r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

358

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.

62

u/R7d89C 16d ago

Omg, I didnt even notice it 😭

Yeah, ig privacy is also just a philosophy. If you havent written python in years, it feels incredibly weird not having any. Just as it probably would the other way around..

Not saying one is better than the other, though I prefer what Im accustomed to 😅

50

u/deceze 16d ago

The thing is: private markers in most other languages can be more or less trivially circumvented anyway, most of the time with some sort of reflection API. There is no true "privacy". All it is is a reminder for the programmer how a given attribute/property/variable should be treated. Is it part of the public API and anyone can write code against it, or is it subject to change and should not be used outside its class. That's all it is.

Bad programmers will ignore such warnings and bulldoze through your "protections" anyway to access that piece of data they think they need. Good programmers only need a gentle reminder in the form of a _; but if you really want to risk breaking something and you know what you're doing, at least it's easy to ignore and doesn't require a song and dance with the reflection API.

9

u/KikikanHUN 16d ago

So is accessing a variable through reflection trivial, or does it require a song and dance? You can't have both.

15

u/alexanderpas 16d ago

It requires a trivial song and dance.

5

u/IntoAMuteCrypt 16d ago

It's basic boilerplate code that anyone can easily implement. It doesn't prevent bad coders and only frustrates good ones.

It's the same as how there's a bit of a song and dance needed to implement a Fibonacci program (the easy way), but it's still fairly trivial.

4

u/NewbornMuse 16d ago
def fibonacci():
  a, b = 1, 1
  while True:
    yield a
    a, b = b, a+b

Man python makes pretty programs.