static variables?

Erik Max Francis max at alcyone.com
Thu Nov 21 16:51:39 EST 2002


Terry Reedy wrote:

> Ok, you are 'proposing' that extra magic is *possible*, that it
> *could* be added,  or rather, have been added from the beginning.

Yes.

> Given that we all know that anything programmable could be done, the
> above does not say anything.

I was simply pointing that it was not beyond the realm of possibility to
have it behave as most newbies expect.  The reason it's done the way it
is is because it's the simplest implementation; there really aren't any
higher, more laudable goals involved.

When someone asks, "Why does it work this way?" the answer is, "It could
have been done other ways, but it was done this way because it was the
simplest to implement, and it's too late to change now."  That's all I
said; I simply gave another outline for another behavior that it _could_
have been, but _isn't_ and _won't_.

> I thought you were saying something more
> (ie, that there is a plausibly good and not just possible
> alternative).

Nitpicking aside, it is easy to turn the simply suggestion I gave into a
well-defined and easily implementable approach.  You can even do it with
relatively little change:  As now, stow off a unique instance of each
default argument as Python already does.  When it comes time to use one
(i.e., the function is called and one of those arguments is not
supplied), make a copy (via copy.copy, or copy.deepcopy if you prefer)
of the default argument and use _that_ instead of the original unique
object.  Voila, problem solved.

Am I suggesting this be done?  No.  Would it help newbies get over that
hump that everyone new to Python seems to bump into at least once? 
Maybe; I don't know.  Is it worth doing now?  No, because the current
behavior is so well-entrenched, good or bad.

Can you nitpick this further?  I'll wager you can.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ One rainy day / Chivalry walked up to me
\__/ Des'ree
    Maths reference / http://www.alcyone.com/max/reference/maths/
 A mathematics reference.



More information about the Python-list mailing list