[Python-Dev] replacing 'global'
Phillip J. Eby
pje at telecommunity.com
Sun Oct 26 17:11:58 EST 2003
At 05:25 PM 10/26/03 +0100, Just van Rossum wrote:
>Phillip J. Eby wrote:
>
> > If we have a rebinding operator, I'd rather it be something
> > considerably more visible than the presence or absence of a ':' on an
> > assignment statement.
>
>I don't know, but somehow I don't have a problem spotting augmented
>assignments, so I don't think := will be as hard to miss as you suggest.
>
> > So far, all the examples have been downright scary in the
> > invisibility of what's happening. Mostly, I can imagine some poor
> > sap trying to debug a program that uses := and is missing one
> > somewhere or has one where it's not intended -- and hoping that poor
> > sap won't be me. :)
>
>How is that different from a '-=' that should have been a plain '='?
>Also, if := is disallowed to rebind in the _same_ scope, this problem
>would be spotted by the compiler.
But some languages use := to mean simple assignment. So, '=' and ':='
don't appear *semantically* distinct. Whereas, I'm not aware of a language
that uses '-=' differently.
> > I've mostly stayed out of this discussion, but so far something like
> > the scope(function).variable proposals, with perhaps a special case
> > for scope(global) or scope(globals) seems to me like the way to go.
> > It seems very Pythonic, in that it is explicit and calls attention to
> > the fact that something special is going on, in a way that ':=' does
> > not.
>
>The reverse argument can be made, too: := calls attention to the fact
>that something is happening right there, whereas a declaration may be
>many lines away.
I guess I wasn't clear. I meant, using 'scope(function).variable =
whatever' *every* time you assign to the outer scope variable, and not
having any "declarations", ever.
More information about the Python-Dev
mailing list