[Python-Dev] replacing 'global'
Just van Rossum
just at letterror.com
Sun Oct 26 11:25:23 EST 2003
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.
> 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
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.
> And 'scope' can be looked up in a manual more easily than ':='
> can. Last, but not least, ':=' looks enough like normal assignment
> in other languages, that somebody just plain might not notice that
> they *need* to look it up.
That's a good point.
More information about the Python-Dev