On Fri, Nov 27, 2020 at 12:28 AM Steven D'Aprano <st...@pearwood.info> wrote:
> Block scoping adds semantic and implementation complexity and annoyance,
> while giving very little benefit. No thank you.
>
>
> > def foo():
> >     let x = 1
> >     if bar:
> >         let x = 2
> >         ...
> >     # x is 1 again here
>
> Is there a shortage of variable names that you have to reuse the same
> name "x" for two distinct variables?
>
> I know that "naming things" is classically one of the hard problems of
> computer science, but this is taking things to an extreme.
>

I spy the Blub Paradox here. Since you don't use lexical scoping, you
don't like it, don't want it, and see no value in it. I use lexical
scoping all the time, and it doesn't lead to the stupidities you're
implying that it does; in fact, it can be used to make code much
clearer and easier to reason about, because - quite the contrary to
what you're saying here - you can use distinct variable names, and
have a guarantee that the variable can't be misused outside of its
intended scope.

This wouldn't really apply as cleanly to Python, since the rest of the
function could potentially use a global with the same name, but
please, stop assuming and asserting that block scoping must inherently
be both useless and confusing.

(And there are a number of very VERY good - albeit unusual - uses for
name reuse. It's not that we can't think of different names. It's that
we specifically WANT the same name, since it is serving the same
purpose. In the absence of sub-function scoping, we're forced to
invent arbitrarily different names, and that doesn't actually improve
clarity at all.)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/OP3TJGHYGMNQXCIC3SCV7I6DQSZJTMIE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to