For review: PEP 308 - If-then-else expression
Andrew Koenig
ark at research.att.com
Sat Feb 8 11:55:59 EST 2003
Sean> (I especially enjoyed "contrariwise" (Andrew Koenig))
Lewis Carroll, actually. I think it's from Tweedledum and Tweedledee.
Sean> Mostly, I just wanted to avoid a specific edge case someone mention much
Sean> earlier in the thread:
Sean> if x if C else y:
Sean> ...do stuff...
Sean> which just seemed ugly.
Agreed. That's part of the reason I'm only +0.8 instead of +1.
But I think it's an unusual case.
Sean> But, then:
Sean> if x when C else y:
Sean> ...do stuff...
Sean> is only marginally less ugly.
Yes.
Sean> And, of course
Sean> if if C then x else y:
Sean> ...do stuff...
Sean> is worse than both.
I'm not sure, actually. At least it alerts the reader that something
is going on :-)
Sean> Oh, and then there's
Sean> if C ? x : y:
Sean> ...do stuff...
Sean> or, as was proposed earlier:
Sean> if C ? x else y:
Sean> ...do stuff...
Sean> None of the above constructs is particularly wonderful, none is
Sean> particularly clear, and, hopefully, none of them would ever be
Sean> used. But, of those listed, I find the 'when' variant to be the
Sean> least confusing.
Tastes vary.
<<snip>>
Sean> Personally, I don't mind
Sean> if (y, x)[C]:
Sean> ...do stuff...
Sean> although I don't consider it to be either obvious or clear.
I *do* mind it, for two reasons:
1) It puts the false condition ahead of the true condition.
2) It evaluates both alternatives even though only one is needed.
--
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list
mailing list