Default parameters
Rainer Deyke
rainerd at eldwood.com
Sat Dec 20 21:13:47 EST 2003
Carl Banks wrote:
> Well, ok. I don't agree that it's dangerous, and there are certainly
> useful functions that modify their arguments that could benefit from a
> fresh copy.
>
> def top_secret_code(a,b,c,stub=[]):
> stub.extend([f(a,b),g(b,c),g(c,a)])
> return stub
This is exactly the kind of function I would call inconsistent. Called with
three arguments, it creates and returns a new list. Called with four, it
modifies an existing list and returns a reference to it. I find this highly
counterintuitive. If I was a user of this function and I learned about the
three argument form first, I would expect the four argument form to leave
its fourth argument unmodified and return a new list.
--
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com
More information about the Python-list
mailing list