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

Paul Paterson hamonlypaulpaterson at houston.rr.com
Sat Feb 8 19:11:40 EST 2003


"Paul Moore" <gustav at morpheus.demon.co.uk> wrote in message
news:y94qpfuv.fsf at morpheus.demon.co.uk...
> "Andrew Dalke" <adalke at mindspring.com> writes:
>
> > I would rather see some better examples of when people would like to
> > use the if/else expression.  People have pointed out that it can do
> > short circuiting, but in the real-life uses I saw in the kernel it
> > didn't make a different if there was short circuiting or not.
>
> Yes, I thing the short-circuit argument is spurious. No-one has given
> a telling example which needs it.
>

print sqrt(x) if x >=0 else "Imaginary roots"

This benefits from short-circuiting. It could easily be written with if
statements so it doesn't fit the "telling ... needs" category.

However, for me this is the crux of the matter. Short circuiting pretty much
has to be the justification for implementing this PEP because if you don't
need short-circuiting you can write a trivial three line iff function. But
then if short-circuiting is the main reason then I think I'd rather open up
the general idea of how to implement lazy evaulation in a Pythonic way.









More information about the Python-list mailing list