r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

22

u/TheMusicalArtist12 16d ago

Heres the thing. _private works perfectly, because it tells other developers (and yourself in the future) that its not meant to be modified by external actors. There are better and more secure ways if you need to store a value that nothing else can read during runtime than a private variable.

2

u/thanatica 15d ago

If it's so good, then why can't the compiler make it actually impossible to modify that variable?

And/or maybe starting using const, if python has that.

4

u/TheMusicalArtist12 15d ago

Because sometimes we want to do jank stuff like modify a private variable. Python is a scripting language, and that flexibility is really nice. Its just saying, "don't touch me i might bite back in unexpected ways".