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

Peter Hansen peter at engcorp.com
Fri Feb 7 18:49:23 EST 2003


Gerrit Holl wrote:
> 
> Guido van Rossum schreef op vrijdag  7 februari om 18:16:27 +0000:
> >         x if C else y if D else z <==> x if C else (y if D else z)
> 
> Doesn't this equal ((z ,y)[bool(D)], x)[bool(C)]? I think it's
> good enough.

If I saw *either* of those in real code produced by someone in my group,
the code would immediately be rewritten.  Neither is readable.

I realize Guido put together the list not as a style guide but to
show how the construct would be interpreted consistently in different 
potentially ambiguous contexts.  I accept that.  Perhaps what the
list also shows, however, is the sort of abuse that might result.
That isn't necessarily a reason to reject the idea (massively nested
if/else statements are almost equally unreadable), but it's a concern.

-Peter




More information about the Python-list mailing list