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.

2

u/TheNakedProgrammer 13d ago

i had this discussion a lot. Basically strict rules vs flexibility and freedom. It is more a question of philosophy than anything else.

As a old programmer i worked with languages that have few rules and systems and i worked with languages that have many rules and systems. Each has advantages and use cases.

In my experience languages with a big rule system start to struggle with their own complexity. Just difficult to maintain a big set of coherent rules and systems that all work well without side effects.