For review: PEP 308 - If-then-else expression

David Eppstein eppstein at ics.uci.edu
Mon Feb 10 07:39:54 CET 2003


In article <b27eq5$7ld$1 at slb9.atl.mindspring.net>,
 "Andrew Dalke" <adalke at mindspring.com> wrote:

> Now my other analysis suggests a misuse rate roughly equal to
> a use rate.  Eg, people will use
> 
>   a = x if x < y else y
> instead of
>   a = min(x, y)
> 
> and people will do
> 
>   s = chr(48 + i if i < 10 else 55 + i)
> instead of
>   s = "0123456789ABCDEF"[i]

The question in these cases is not whether these people would find the 
correct construction -- obviously they wouldn't else they would use it 
in place of the ternary.  The question is, without the ternary, what 
even worse construction would they use instead?

BTW, I think your estimate of a correct use per 1000 lines sounds about 
right.  Which is one reason I don't feel very strongly about this 
issue...

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/




More information about the Python-list mailing list