[Python-Dev] statically nested scopes
Guido van Rossum
guido@python.org
Fri, 03 Nov 2000 08:12:11 -0500
[MAL]
> That's just what I was trying to say all along: statically
> nested scopes don't buy you anything except maybe for lambdas
> and nested functions
That's a tautology -- that's what nested scopes are FOR!
> (which is bad style programming, IMHO too).
Not always. The keyword argument hack is so common that it must serve
a purpose, and that's what we're trying to fix -- for lambda's *and*
nested functions (which are semantically equivalent anyway).
> The only true argument for changing scoping I see is that
> of gained purity in language design... without much practical
> use.
But there is practical use: get rid of the unintuitive, unobvious and
fragile keyword argument hack.
> Other issues that need sorting out:
>
> x = 2
> class C:
> x = 1
> C = 'some string'
> def a(self):
> print x
> def b(self):
> global x
> x = 3
>
> class D(C):
> C = 'some string'
> def a(self):
> C.a(self)
> print C
>
> o = C()
> o.a()
> o.b()
> o.a()
>
> o = D()
> o.a()
>
> What would the output look like under your proposal ?
This is a good point! If we considered the class as a nested scope
here, I think it might break too much code, plus it would allow a new
coding style where you could reference class variables without a self
or <classname> prefix. I don't like that prospect, so I'm in favor
for ruling this out.
--Guido van Rossum (home page: http://www.python.org/~guido/)