[Python-Dev] Re: closure semantics

Alex Martelli aleaxit at yahoo.com
Sat Oct 25 03:43:34 EDT 2003

On Friday 24 October 2003 22:39, Zack Weinberg wrote:
> > 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.
> Understand that I do almost all my programming in typed languages,
> where that keyword isn't noise, it's a critical part of the declaration.

I have a vast experience of typed languages, and, even there, the mandatory
redundancy of declarations is just a cop-out.  A _well-designed_ strictly
typed language, such as Haskell or ML, lets the compiler infer all types, so
you don't _have_ to provide declarations -- you can, much in the spirit as 
you can use assert in Python, but you need not.

> I think there really *is* a language deficiency with regard to
> declaring class versus instance variables.

I don't: there is no declaration at all (save for the accursed 'global'), 
only _statements_.  They DO things, and what they do is simple and

> I find this imperative syntax for declaring instance variables
> profoundly unintuitive.  Further, on my first exposure to Python, I

That's because you keep thinking of "declaring".  Don't.  There is
no such thing.  There is documenting (docstrings, comments) and
actions.  Period.  Entities must not be multiplied beyond need: we
don't NEED enforced redundancy.  We don't WANT it: if we did, we
could chose among a huge host of languages imposing it in a
myriad of ways -- but we've chosen Python exactly BECAUSE it
has no such redundancy.

When I write in some scope
    x = 1
I am saying: x is a name in this scope and it refers to value 1.
I have said all that is needed by either the compiler, or a reader
who knows the language, to understand everything perfectly.

Forcing me to say AGAIN "and oh by the way x is REALLY a name
in this scope, I wasn't kidding, honest" is abhorrent.  If you really
like that why stop at ONE forced useless redundancy?  Why not
force me to provide a THIRD redundant "I really REALLY truly mean
it, please DO believe me!!!", or a fourth one, or...?

*ONCE, AND ONLY ONCE*.  A key principle of agile programming.

> thought A, B, C were instance variables, although it wasn't hard to
> understand why they aren't.

Reducing the productivity of all language users to (perhaps) help
a few who hadn't yet understood one "not hard to understand" detail
would be a disastrous trade-off.

> People like to rag on the popularity of __slots__ (for reasons which
> are never clearly spelled out, but never mind) -- has anyone
> considered that it's popular because it's a way of declaring the set
> of instance variables, and there is no other way in the language?

Yes, or more precisely, at least it looks that way, and it's efficient
(saves some per-instance memory).  Much the same way as
"type(x) is int" looks like a way to "declare a type" and so does
isinstance(x, int) later on in one's study of the language (though
no saving accrues there).  But then, "Extraordinary Popular
Delusions and the Madness of Crowds" IS quite deservedly a
best-seller for the last 160+ years.  Fortunately, Python need not
pander to such madness and delusions, however popular:-).


More information about the Python-Dev mailing list