[Python-Dev] Re: closure semantics

Alex Martelli aleaxit at yahoo.com
Fri Oct 24 16:17:42 EDT 2003


On Friday 24 October 2003 12:27 am, Zack Weinberg wrote:
   ...
> Frankly, I wish Python required one to write explicit declarations for
> all variables in the program:
>
> var x, y, z # module scope
>
> class bar:
>    classvar I, J, K # class variables

Seems like a great way to get uninitialized variables to me.

Might as well mandate initialization, getting a hard-to-read
      classvar I=2.3, J=(2,3), K=23

or to force more readability one might say only one name per
classvar statement
      classvar I=2.3
      classvar J=(2,3)
      classvar K=23

But then what added value is that 'classvar' boilerplate dirtying
things up?  Might as well take it off and get
    I = 2.3
    J = (2, 3)
    K = 23

which is just what we have now.


> It's extra bondage and discipline, yeah, but it's that much more help
> comprehending the program six months later, and it also gets rid of

There is absolutely no help (not one minute later, not six months later)
"comprehending" the program just because some silly language mandates
redundancy, such as a noiseword 'classvar' in front of the assignments.

> the "how was this variable name supposed to be spelled again?"
> question.

I disagree that the 'classvar' boilerplate would provide any help with
that question.  Just put the initializing assignment there and it's only
clearer for NOT being obscured by that 'classvar' thingy.  Document
with docstrings or comments, not by changing the language.


A language which, I suspect, MIGHT let you do exactly what you want,
is Ruby.  I don't know for sure that you can tweak Ruby into giving
(at least) warnings for assignment to symbols outside of a certain set,
but I suspect you might; you _can_ change the language's semantics
pretty deeply.  Yet in most other ways it's close enough to Python that
the two are almost equivalent.  I do believe (and hope!) you stand very
little chance of ever getting into Python something as alien to its
tradition and principles as variable declarations, so, if they're important
to you, considering ruby might be a more productive option for you.


Alex




More information about the Python-Dev mailing list