For review: PEP 308 - If-then-else expression
hamonlypaulpaterson at houston.rr.com
Sat Feb 8 17:31:52 CET 2003
"Paul Rubin" <phr-n2003b at NOSPAMnightsong.com> wrote in message
news:7xptq3f83c.fsf at ruckus.brouhaha.com...
> "Andrew Dalke" <adalke at mindspring.com> writes:
> > Though with some cases, as in
> > is_html = True
> > ext = ["txt", "html"][is_html]
> > the result is easy to understand.
> For me at least, it's absurd to say that the above is clearer than a
> conditional expression.
It depends on the reason you are reading the code,
1. reading the code to see the normal flow of events (conditional seems a
2. reading the code to see all possible flows of events (options then
condition is clearer)
3. looking for a bug in a certain flow path (either might be clearer)
- other possibilities I can't think of
1 is probably the norm and should probably be the determining use case.
However, you could argue that debugging is as important, giving weight to 3.
Also, in the specific case above there is no normal flow and therefore 2 is
actually the most likely use case.
I'm not particularly fond on the above representation, but I think its
important to realize that clarity depends on what you are trying to achieve
when you look at code.
More information about the Python-list