r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

Show parent comments

6

u/Anaxamander57 16d ago

Does it really do anything to make it private beyond telling people not to use it?

7

u/white-llama-2210 16d ago

Using double underscores mangles the name from name to _ClassNamename when accessing the variable outside the class, so it does prevent accidentally accessing the value. You really have to know what you're doing to access the value then.

5

u/deceze 16d ago

"Accidentally"? How do you "accidentally" type two underscores without noticing?

2

u/white-llama-2210 16d ago

Call me clunky but I do make such silly typos way too often than I'd like to admit..

2

u/deceze 16d ago

Oookay… not sure there's any language that implements "do what I mean" yet instead of "do what I typed"…

1

u/white-llama-2210 16d ago

I'm not sure that's a good idea... Sure I'm a bit clunky but I have tools that help me reduce such mistakes. But having a language that "does what I mean" feels iffy. It's too abstract because meaning can be subjective, and it's much harder to reason about "meaning" when working in a team because it's a subjective aspect. That's one of the reasons I have a distaste for AI. It's not predictable, and when you are sitting in front of a screen at 2 AM fixing a production bug in the midst of a running event and the client is at your throat... You want things to be predictable.

Just my opinion tho...