[Python-Dev] replacing 'global'
Skip Montanaro
skip at pobox.com
Sun Oct 26 06:21:41 EST 2003
>> * Would you be required to use := at each assignment or just the
>> first?
Just> Just the first; "a = 2" still means "a is local to this scope".
That seems like a very subtle error waiting to happen...
>> All the toy examples we pass around are very simple, but it seems
>> that the name would get assigned to more than once, so the programmer
>> might need to remember the same discipline all the time. It seems
>> that use of x := 2 and x = 4 should be disallowed in the same
>> function so that the compiler can flag such mistakes.
Just> I don't see it as a mistake. := would mean: "bind to whichever
Just> scope the name is defined in", and that includes the current
Just> scope. I disagree with Alex when he says := should mean "I'm
Just> binding this name in NON-local scope".
Yeah, but if you come back to the code in six months and the nested function
is 48 lines long and assigns to x using a variety of ":=" and "="
assignments, it seems to me like it will be hard to tell if there's a
problem.
>> * This seems like a statement which mixes declaration and execution.
Just> How is that different from "regular" assignment? It mixes
Just> declaration and execution in the same way.
Not in the way of saying, "this is global and here's its value".
Skip
More information about the Python-Dev
mailing list