Default Value

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jun 20 22:26:44 EDT 2013


On Thu, 20 Jun 2013 10:12:01 -0700, rusi wrote:

> Python (and all the other 'cool' languages) dont have gotchas because
> someone malevolently put them there.
> In most cases, the problem is seen too late and the cost of changing
> entrenched code too great.
> Or the problem is clear, the solution is not etc etc.

And sometimes the gotcha is unavoidably in the nature of the problem. 
This is remarkably common in real life, so much so that in English there 
is even a proverb for it: "You can't have your cake and eat it too", or 
to put it another way, you can't save your cake for later and eat it now 
at the same time.

For default arguments, you cannot simultaneously have them evaluated once 
*and* evaluated each time they are needed. Whichever choice you make, 
there will be situations that lead to a gotcha. Even if Python supported 
syntax for both, there would be cases where people used the wrong syntax, 
not knowing any better, and would trip over unexpected behaviour. 



-- 
Steven



More information about the Python-list mailing list