Default Value

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jun 20 21:28:06 EDT 2013


On Thu, 20 Jun 2013 07:49:37 -0700, Rick Johnson wrote:

> When the subroutine is completed, all inputs and local variables are
> expected to be destroyed. If the programmer wants a return value, he
> need simply ask. Data persistence is not a function of subroutines!
> Finally, a subroutine should never have side effects UNLESS the
> programmer explicitly ask for a side effect.

Correct. And by using a default value, you are explicitly asking for a 
side-effect, namely, "use this object as the default" (not, "use this 
expression, and re-evaluate it at call-time"). 

That some people do not comprehend the *consequences* of doing so is not 
Python's fault, any more that it is Python's fault when people write:

a = b = []
a.append(1)

and then are surprised that b is no longer empty. That doesn't happen 
with 

x = y = 0
x += 1

therefore Python is buggy, yes? No.

In short, your invalid understanding of Python's execution model is your 
lack of knowledge, not a bug in Python to be fixed.


-- 
Steven



More information about the Python-list mailing list