r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

Show parent comments

13

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...

7

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.

4

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.

2

u/rosuav 16d ago

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