On Wed, 06 Dec 2006 04:29:54 -0800
Dick Moores <[EMAIL PROTECTED]> wrote:

(...)
> >
> >def my_function(min, max=None):
> >     if max is None:
> >         max = min
> >         min = 0
> >     # stuff
> 
> Great!
> 
> >I am not sure if this is more intuitive though.
> 
>  >>>
> def my_function(min, max=None):
>      if max is None:
>          max, min = min, 0
>      return max - min
>  >>> my_function(3, 7)
> 4
> 
> I meant that the order "min, max" is more intuitive than "max, min". 
> Don't you agree? And it's the order used in random.randint(), 
> random.randrange(), and random.uniform(), for examples.
> 

Sure I agree, although it may depend on what the function actually does
and how you name it (and the arguments). If you e.g. rewrite your example to

def subtract(from_, what=0):
    return from_ - what

the changed order of arguments seems quite intuitive to me.

What I meant in the first place is that it might be "unintuitive" that
if you pass only one argument this is the one that comes last in case
you pass two arguments.
As I said, I was not sure and was too lazy to think much about it :-)

Michael
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to