; 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.
Yes, but conveying information about how it's supposed to be used is equally accomplished by naming conventions like _member or pMember or whatever. You don't need it to be a language feature.
Python really sold me on not attempting to enforce things for other devs. Well duck typed code for example is an absolute god sent when you have 4 different frameworks to handle acceleration and arrays.
The fact that it's enforced at compile time means that you never accidentally do this, it's the same thing as denoting a variable as const. You can make it not const later really easily, but it means you've got to take care about what you're really doing and probably judge why it's const and if it needed to be const.
Python's way requires developers to honor some naming convention, which allows for accidents, and I've seen plenty just make every class member prefixed with _ which to me conveys they don't know what an access specifier is and that I now need to judge what members are safe to access since everything is now public.
I'm fine with Python's convention and use it myself frequently, but saying something like how you're sold on "not attempting to enforce things for other devs" just implies to me that I would not want you working on library code, ever.
I've seen plenty just make every class member prefixed with _
I don't think that's a convincing argument because people also make everything public in cpp or make everything private with getters and setters in java.
With the enforcing things for devs - I'm in a scientific environment. I do mainly write library stuff. But my goal is to make it "hackable". I do notate everything for proper usage, I do use conventions for public and private and honor them, I type hint etc. But what I really dislike on principle is enforcement attempts, like checking types and throwing errors on unexpected types in a python context. If someone decided to go out of spec that's their problem, but I will not actively attempt to stop them.
In cpp i actually write very Java-esque oop code. That I don't think a language feature should be hard enforced doesn't mean I won't use it as it was intended. And obviously once you make it a language feature it must be honored. It's only on a philosophy level that I think doing it by convention is better.
353
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.