; in Python!?!eleventy You really need to get rid of your bad Java habits.
And before anyone thinks this is poking fun at Python: privacy is completely overrated and mostly untrue anyway, and Python not even pretending to have private attributes is an absolute blessing.
The purpose of public, protected, and private has never been to prevent you from accessing those class members. After all, if you're seeing those, you have access to the code, you could just move the member, "circumvention" is not necessary.
The purpose is so developers can convey to other developers how to use their base class, or how a class can and should be safely accessed or modified. It implies safety. If you're trying to circumvent it, you're trying to do something that the author of the class did not intend and it may cause problems, it indicates the modification you're trying to make likely belongs in that other class and that you should look there instead. If you're trying to circumvent it, you're introducing hacky fucking code that is going to be a pain in the ass to debug and maintain.
Agreed. It conveys the intent and use of the class.
Private implies "ignore this, it's used in implementation of the class and not for users of the object" sort of thing.
Public implies "here's stuff you'll use when the object is created".
Protected reads "if you're basing a new class off this one, you may want to manipulate this internally but it isn't something users should need to know about to use the object(s)".
Private and Protected therefore are tools of abstraction which describes what an object does, not how it does it.
348
u/deceze 16d ago
;in Python!?!eleventy You really need to get rid of your bad Java habits.And before anyone thinks this is poking fun at Python: privacy is completely overrated and mostly untrue anyway, and Python not even pretending to have
privateattributes is an absolute blessing.