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

Paul Paterson hamonlypaulpaterson at houston.rr.com
Sat Feb 8 00:52:30 EST 2003


"David Eppstein" <eppstein at ics.uci.edu> wrote in message
news:eppstein-0565A9.17575107022003 at news.service.uci.edu...
> In article <8eY0a.2044$yn1.144744 at twister.austin.rr.com>,
>  "Paul Paterson" <hamonlypaulpaterson at houston.rr.com> wrote:
>
> > >     if obj() if callable(obj) else default:
> > >        ...
> >
> > One of the most compelling, one-line counter arguments I've ever seen!
>
> What, just because a notation can be abused makes it always bad?
>

The thing that struck me when I read this one liner was that it was an very
logical thing to write but reading it was horrible. When coding I could
imagine my self thinking "ok if obj() is true then I do this... oops, what
if obj isn't callable... ok, I'll add a default".

Because the "x if c else y" is more writable (closer to the way people think
when writing code) than readable I think it will lead to less readable code.
I'm not against the idea of a ternary operator or the lazy evaluation. I'd
just rather find one that balanced readability with writability.






More information about the Python-list mailing list