Python-list digest, Vol 1 #10572 - 14 msgs

Jeff Shannon jeff at ccvcorp.com
Mon Apr 22 14:49:04 EDT 2002


In article <mailman.1019488539.12450.python-list at python.org>, 
mgilfix at eecs.tufts.edu says...
>   While I'm not commenting on whether this is really useful in python
> (because I get along fine without it), the python equiv would be:
> 
>   def both_ways (arg, dir):
> 
>     if dir:
>       arg1 = blah
>       arg2 = some_blah
>     else:
>       arg1 = something_else
>       arg2 = some_other_thing
> 
>     another_func (arg1, arg2)

Hm, well, I'd be likely to write this as:

    def both_ways(arg, dir):
        if dir:
            another_func(blah, some_blah)
        else:
            another_func(something_else, some_other_thing)

Yes, it could be argued that this isn't as good because I'm 
duplicating the reference to another_func.  But then, you're 
duplicating the references to arg1 and arg2.  And besides, 
practicality beats purity.  :)

I would also argue that my example is a *lot* clearer than the 
ternary operator version, despite being less concise:

    def both_ways(arg, dir):
        another_func( (dir ? blah : something_else), 
                      (dir ? some_blah : some_other_thing) )

Apparently, though, this is a matter of taste.  I'm just happy 
that Guido's taste seems to be in favor of if/else.  <wink>

-- 

Jeff Shannon
Technician/Programmer
Credit International



More information about the Python-list mailing list