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

Paul Moore gustav at morpheus.demon.co.uk
Mon Feb 10 20:58:26 CET 2003


Erik Max Francis <max at alcyone.com> writes:

> 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).

In this instance, x is *not* false. It is "success!", which evaluates
as true. As has been pointed out (in various contexts) over and over
again.

Paul.
-- 
This signature intentionally left blank




More information about the Python-list mailing list