Default parameters

Carl Banks imbosol at aerojockey.invalid
Sat Dec 20 01:56:07 EST 2003


Rainer Deyke wrote:
> Carl Banks wrote:
>> Well, personally, I don't see much use for non-constant default
>> arguments, as we have them now, wheras they would be useful if you
>> could get a fresh copy.
> 
> I disagree completely.  If a function modifies one of its arguments, this is
> a fundamental property of that function.  If using a default value for that
> argument causes the function to swallow the changes it performs, the
> function no longer has consistent behavior.
> 
> On the other hand, the following function has consistent, if silly,
> behavior:
> 
> 
> default_list = []
> 
> def append_5_to_a_list(which_list = default_list):
>  which_list.append(5)


I said a non-constant default argument wasn't useful.  As evidence
against, you suggest that the function is "consistent."

Now, do have any evidence that non-constant, default arguments (as
they are now) are USEFUL?

(I don't agree with your "consistent" theory, anyways.  The function
would be treating all arguments consistently: it's just that it'd get
a fresh copy of the default arguments each call.)


-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon




More information about the Python-list mailing list