Q: Python 2.0 preliminary features?
Greg Ewing
greg.ewing at compaq.com
Thu Oct 14 04:04:45 EDT 1999
Guido van Rossum wrote:
> def f():
> sum = 0
> def accumulate(x):
> global sum
> sum = sum+x
> ...code using accumulate()...
> return sum
>
> tends to create obfuscated code.
I can't see anything very obfuscated about that -- the
two uses of sum are only two lines apart, after all.
It could become obfuscated if the code were much more
complicated. But it's the very simple cases like that --
where the overhead of defining and instantiating a
class would totally swamp the code being wrapped --
that one feels the lack of lexical scoping most keenly.
In any case, is that really any worse than
def f():
sum = [0]
def accumulate(x):
global sum
sum[0] = sum[0] + x
...code using accumulate()...
return sum[0]
which is the sort of thing people are going to do if
you restrict lexical scoping to being read-only. To my
way of thinking, the original version is clearer.
I suspect that, if you introduce read-only lexical scoping,
you're just going to substitute the stream of "Why is there
no #@%$#$% lexical scoping in Python" complaints with "Why
the #@%$#$% can't I assign to a non-local variable in Python"...
Greg
More information about the Python-list
mailing list