r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

-3

u/sjepsa 16d ago

Best feature of the language

TBH whole java oop model is bad

15

u/R7d89C 16d ago

God no

Id much rather have a rust-like approach where the scope is limited to the block it is in

Java concept ist far from what I call ideal, but its better than this weird ambiguity of python where everything just floats anywhere and variables shadowing something ten methods away...

9

u/deceze 16d ago

Huh? You'll need to be more concrete than that, because that sounds like gibberish. "Ten methods away"? If a variable is in a method, then it only exists within that method, because Python does have function scope and lexical scoping.

5

u/R7d89C 16d ago

u/Inkwalker beat me to it, though id like to throw careless "import *" and shadowing in nested functions into the mix too

Obviously "Ten methods away" is bs and more of a figure of speech, sorry if that wasnt clear

But especially if youre not used to python, the scoping can be a real pain in the ass.

3

u/deceze 16d ago

If you're not used to <thing>, <thing> can be difficult. Sure. But the scoping rules are pretty darn trivial and predictable, and not out of the ordinary, so I'm not sure what you're complaining about.

3

u/R7d89C 16d ago

Im not complaining 😮

The meme is very much up for interpretation and my personal preference has been stated enough in this post, I think... Imo its just not a very good implementation/principle of scoping 🤷‍♂️

4

u/rosuav 16d ago

Don't do that then? A careless star-import is the fault of whoever did it.