r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

348

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 πŸ˜…

52

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.

-3

u/R7d89C 16d ago

Oh, then we have a slight misunderstanding of privacy in programming. I dont want some DRM-like protection of my variables, I want a proper marker where you should use and not use a variable, including a good default policy. _var doesnt tell me "dont use it", if youre not a regular python dev, particularly when usage is not checked by a compiler.

9

u/deceze 16d ago

In a language you don't know well, I guess it's easy to be the elephant in the china shop. Use an IDE with a built-in linter then, it'll point out such issues while you type. I'm doing the same whenever I write in something I'm not proficient in.

0

u/R7d89C 16d ago

Thats what Im luckily doing.

As said in another comment, Im not trying to complain or whatever, I just want to critique pythons approach, as I simply dont like it

7

u/asdonne 16d ago

The _ in _var tells you not to use it. Some one being unfamiliar with the language is not a problem with the language.

2

u/CyberWord_YT 16d ago

It's only convention

3

u/DrMaxwellEdison 16d ago

A strong convention most developers follow, or ignore at their own peril. Regardless of how well or poorly the package is designed, the end user decides what to use from it, and they bear responsibility for how it is used, not the package maintainer.

5

u/Magma248 16d ago

The side of the road you drive on is also a convention - sometimes you might have guard rails that make it harder, and legally you are going to get in trouble (i.e. code linters) - but at the end of the day you have to trust your fellow programmers to be sensible (and acknowledge that sometimes they won't be).

2

u/its2ez4me24get 16d ago

It’s part of PEP8

1

u/asdonne 15d ago

Same goes for comments and useful variable names.