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

Erik Max Francis max at alcyone.com
Mon Feb 10 00:20:22 EST 2003


Paul Rubin wrote:

> "Samuele Pedroni" <pedronis at bluewin.ch> writes:
>
> > I still prefer
> >
> > log.info(ok and "success!" or "failure.")
> >
> > over
> >
> > log.info(if ok: "success!" else: "failure")
> 
> OK, at that point it just get down to a matter of subjective
> preference.  I personally find the second version far more explicit
> and understandable.

I think this is a lot more than just preference.  To those not familiar
with the idiom, `C and x or y' is downright obtuse.  He may prefer it
because it is a few characters shorter (and only a _few_ at that), but
it is only clear if you already know the idiom.  Furthermore, as has
been said over and over again, it's _broken (if x is false).

The latter is more explicit and is immediately understandable by
extension to anyone who has seen the if...else statement in the language
(which is, well, everyone).

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ She glanced at her watch ... It was 9:23.
\__/ James Clavell
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.




More information about the Python-list mailing list