Q: Python 2.0 preliminary features?
Guido van Rossum
guido at cnri.reston.va.us
Tue Oct 12 22:31:54 EDT 1999
Regarding the use of 'global' in combination with nested scopes:
I have always been in favor or *not* providing a way to assign to
variables at the intermediate levels. That is, you can *use*
variables from intermediate levels, but you can't *set* them. The
'global' statement will set the variable at the module-global level.
Motivation: I agree that it is useful to reference variables in the
surrounding scope. But if you start modifying them, you're abusing
the nested scope mechanism to hold mutable state; it's much clearer
to define a class for this purpose.
In particular, I think that allowing
def f():
sum = 0
def accumulate(x):
global sum
sum = sum+x
...code using accumulate()...
return sum
tends to create obfuscated code.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list