For review: PEP 308 - If-then-else expression
lac at strakt.com
Sat Feb 8 18:17:20 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
> lot clearer)
> 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
4. You are reading somebody else's code. You know what this code is
supposed to do. You know how you would write it. You have
absolutely no expectation that you will be surprised here, and get
anything other than that. You want to zip through it quite
quickly, checking that it does what you expect. You'll stop if you
find something odd.
> 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