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

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Sat Feb 8 22:49:48 CET 2003


"Samuele Pedroni" <pedronis at bluewin.ch> writes:
> I sympathize but the question is really what you prefer your target group to
> encounter:
> 
> 1) sys.exit(errs and 1 or 0)
>     style = bold and "bold" or "italic"
> 
> or
> 
> 2) sys.exit(1 if errs else 0)
>     style = "bold" if  bold else "italic"
> 
> because (1) idioms are used in practice.
> 
> Personally I have no problem with (1) idioms and I don't like (2) forms, or
> more in general I have yet to see a ternary cond op form that I like.
> So I'm happy with the status quo, workarounds included and their
> limititations.

Your post is very interesting since it's the first one where I've
heard someone actually claim to prefer (1) to (2), rather than offering
(1) as a kludgy workaround but really preferring a multi-line if statement.

FWIW I find the (1) forms awful and greatly prefer (2).  Think of
Andrew Koenig's example,

    maximum = x > y and x or y

which follows the form of (1) but is simply incorrect some of the
time, which you might not immediately notice.  Who needs to expose
themselves to that kind of error?




More information about the Python-list mailing list