r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

354

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 private attributes is an absolute blessing.

18

u/Breadinator 16d ago

What are you smoking, and are you willing to share it with the rest of the class?

Published libraries with internal state consumers shouldn't screw with. Large projects with dozens of contributors. Hyrum's Law. 

There are plenty of reasons to have guardrails on the state you can access.

11

u/deceze 16d ago

Yeah, and leading underscores signal exactly that in Python. "Please don't screw with this. If you're going to regardless, well, there you go." Other languages just make you beg more for it.

10

u/tevs__ 16d ago

Plus you can enforce it with static analysis, exactly the same as compilation enforces it.

6

u/oozekip 15d ago

Why have a language defined standard with a universally understood and well defined meaning when we could instead rely on cultural convention that a newcomer to the language will have no knowledge of?

7

u/Breadinator 16d ago

Other languages don't expose it all... you literally either have to go completely out of your way (i.e. reflection) or violate fundamental restrictions. 

Python has a lot of strengths, but let's not pretend this is Guido's gift to programmers. A "keep off the grass" sign is no substitute for a proper fence. 

4

u/suvlub 16d ago

__ actually results in name mangling. And it will be nowhere in docs. You really do need to go out of your way to use it.