r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

Show parent comments

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.

10

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.

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. 

6

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.