Default parameters

Rainer Deyke rainerd at eldwood.com
Sat Dec 20 02:09:27 EST 2003


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

def draw_pixel(x, y, color, surface=screen):
  screen[y][x] = color

> (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.)

A function that mutates its arguments should not be called with "fresh"
arguments, implicitly or explicitly.  If the purpose of the function is to
modify its arguments, then doing so would throw away the effect of the
function.  If the purpose of the function is not to modify its arguments,
then it shouldn't do so.


-- 
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com






More information about the Python-list mailing list