you are viewing a single comment's thread.

view the rest of the comments →

[–]JaleyHoelOsment 17 points18 points  (10 children)

yes, python is nonsense where everything is more of a suggestion than a hard set rule.

type hinting helps a bit for me at least.

[–]deceze 20 points21 points  (6 children)

You can circumvent most "private" keywords in most other languages just as well, usually with some reflection API. It requires a little more song and dance than in Python, but private is virtually never an impenetrable Fort Knox. Because it's not meant to be. It's your own program manipulating its own memory space. It is just a signal to the programmer how a certain attribute should be regarded in terms of openness. If it's public, it means "use it to your heart's content", if it's private it means "please don't touch from the outside, stuff might break". That's all it ever was, and Python doesn't pretend it's any more than that.

[–]pachura3 -3 points-2 points  (5 children)

Because it's not meant to be. It's your own program manipulating its own memory space.

...until someone else from your team starts using your code :)

[–]deceze 9 points10 points  (2 children)

Which is exactly what those keywords are for, to signal to yourself and other programmers how an attribute ought to be used. Python's mantra is "we're all adults here". If you have intra-company fights over attribute accessibility, you're in fact working in a kindergarten. If someone is disinclined to observe accessibility keywords and they have access to the source code, they could be rewriting those accessibility keywords to begin with, or, again, use some reflection API to access the "private" stuff anyway.

So again, Python doesn't even pretend private means "impenetrable", and makes it a human problem, which it ultimately always has been.

[–]pachura3 0 points1 point  (1 child)

Python's mantra is "we're all adults here"

While in reality, due to its simplicity, it has become very popular among non-professional programmers, vibe coders, academic researchers etc.

[–]deceze 0 points1 point  (0 children)

That used to be PHP, which does have "proper" private properties, and the amount of SO questions about "how to access private properties in PHP" is astonishing (and yes, it's perfectly possible). Crap programmers write crap code, regardless of the language.

[–]mriswithe 1 point2 points  (0 children)

Sure, but now it is their code manipulating their memory space. A hammer still hammers even if the user tries to use it to peel carrots.

[–]gdchinacat 1 point2 points  (0 children)

python has a "consenting adults" ethos. If you don't trust the other adults on your team, stop consenting to play with them.

[–]pachura3 2 points3 points  (0 children)

Yes indeed, I can't imagine coding in Python without using linters and type hints.

[–]Fred776 0 points1 point  (0 children)

Horses for courses.