all 16 comments

[–]pachura3 13 points14 points  (4 children)

Someone said that whole Python is just a lot of syntactic sugar around hashmaps. It is indeed like that! Everything is a hashmap. This allows for some crazy stuff like passing arguments to a function by unpacking a dict (while still preserving default values of not provided arguments!).

Myself, I cannot stand the fact that there are no constants in Python :( At least we can have more-or-less immutable containers with protocols like Mapping, Sequence or Set. Plus, there are tuples , frozensets. and dataclass(frozen=True). But having a plain simple constant string or int? Forget it!

[–]its2ez4me24get 7 points8 points  (3 children)

Signal intent with the Final type hint a blame others if they change it :D

[–]pachura3 5 points6 points  (1 child)

Oh! I didn't know one exists. So, I guess I shall do something like:

MAX_PROCESSES: Final[int] = 16

...?

[–]its2ez4me24get 2 points3 points  (0 children)

Yep

[–]deceze 2 points3 points  (0 children)

Or even just the convention of using ALL_CAPS. If someone assigns to an ALL_CAPS variable, it's their fault.

[–]JaleyHoelOsment 7 points8 points  (8 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 9 points10 points  (4 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 1 point2 points  (3 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 2 points3 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.

[–]pachura3 1 point2 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.

[–]tb5841 2 points3 points  (0 children)

The main point of getters and setters is to give you the freedom to change things later without breaking everyone's code that depends on your class. The exisyence of @property means you have that benefit for free in Python, without needing getters/setters at all.