Real Problems with Python

Tim Peters tim_one at email.msn.com
Sun Feb 13 16:23:07 EST 2000


[François Pinard]
> ...
> Couldn't we approximate lexical scoping with classes?

Certainly:  the things Scheme does with lexical closures were *intended* to
be done with classes and explicit instance state in Python.  Every now &
again someone comes along and insists the latter aren't sufficient, but they
are -- in Python.  Python's flavor of classes are more powerful than most
realize at first.

> For the few times I needed it, I was fairly satisfied with this
> solution.

Me too, but after s/fairly/very/ after many times needing it.  The class
approach is more flexible in practice, thanks to the explictly manipulable
state (e.g., conceptually small changes don't require juggling six levels of
nested closure -- it's often enough to just add a simple new method to
fiddle an aggregate closure state maintained in a vanilla class instance).

> Surely more verbose than in Scheme, but yet, given I do not use
> it often, I did not care the extra-verbosity.
>
> P.S. - If you see a contradiction with my previous message where
> I praise terseness, please consider that common and frequent idioms
> are  better terse, while some verbosity is acceptable for things
> like lexical scoping, that we do less often, and for which some
> extra documentation is welcome.

I suspect that, like me, you're not doing any GUI programming in Python yet.
The press for fancier lambdas and lexical closures is much stronger from
people who do:  they want to attach small & simple procedures to oodles &
oodles of widgets (your "common and frequent" indeed), and out-of-line class
solutions are legitimately viewed as clumsier and more obscure.

"one-obvious-way"-vs-"one-pleasant-obvious-way-depending"-ly
    y'rs  - tim






More information about the Python-list mailing list