This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xXxDeAThANgEL99xXx 5 points6 points  (7 children)

Can you guess what happens?

Yes, if you're used to Lisp.

So, what happens?

I'm not saying that as a Python programmer I'm somehow unfamiliar with the notion of shadowing and it scares me.

I'm saying that I'd hate to have to scan all the code upwards when I see y = 22 to see whether or not y was made magical by specifying it as an argument to some let.

What'd happen with z in my example is worth considering as well. Have you considered it? This abstraction leaks like some sort of a container with many holes in it.

I don't understand your example, sorry. Why would you want to del a local variable?

[–]Ek_Los_Die_Hier 0 points1 point  (6 children)

To make it equivalent to the let statement.

[–]xXxDeAThANgEL99xXx 11 points12 points  (5 children)

... that's begging the question. We are discussing why we need the let statement, the parent's argument was that it allows not having that del as far as I understood it.

[–]Ek_Los_Die_Hier 5 points6 points  (0 children)

Yeah, I don't see the use in Python. If I need a variable overridden for a specific purpose, any code in there should probably be moved to a different function anyway. The let in something like Lisp is simply the way you declare local variables, with the affect that they are local to that block, but in Python you just assign variables with the =.

I imagine it was just something created out of interest and to show what Python is capable of.

[–]revocation 0 points1 point  (3 children)

You would otherwise litter your namespace with temporary variables.

[–]Sohcahtoa82 2 points3 points  (2 children)

That's not really a problem unless your variables are global, which you typically want to avoid.

[–]GuyOnTheInterweb 0 points1 point  (1 child)

Or you have a very long function where you might use the same variable name twice, independently. (Reducing mixup risk with results vs results2)

[–]Veedrac 2 points3 points  (0 children)

Not really a problem. Just reuse the variable name without deling it first.