PEP-308 a "simplicity-first" alternative
Tim Hochberg
tim.hochberg at ieee.org
Wed Feb 12 12:41:53 EST 2003
Dave Brueck wrote:
> On Wed, 12 Feb 2003, Tim Hochberg wrote:
>
>
>>>>so whether he likes it more or less than a
>>>>broken idiom some people use anyway is really beside the point.
>>>
>>>On the contrary, as Paul also said in his response, the question is
>>>whether to replace the current idiom or let it stand. So preference
>>>between the status quo and a proposed new situation is exactly to the
>>>point. A choice between the two is exactly what people will be voting
>>>on.
>>
>>
>>On the contrary, the question is whether to replace the current idiom
>>_with_new_syntax_. Not adopting new syntax does not stand in the way of
>>declaring the and/or idiom to be bad form and standardizing on a new
>>idiom or idioms.
>
>
> Such as _______________? This topic has come up over and over for years
> and nobody has come up with a better idiom than the one listed in the FAQ.
> Unless a better one is discovered then the choice really is between
> sticking with the old one or replacing it with new syntax. If you can
> think up a better idiom, now would be an excellent time to suggest it.
If what you want is a terse, short-circuiting idiom for the ternary
operator I can't help you. But it's been asserted, and as far as I can
tell accepted by both sides, that short-circuiting is not needed often
in ternary operations. So if nothing comes of the current discussion,
the warning against "a and b or c" in the FAQ can be strengthened and
people can be pointed to either:
# Clear, extensible, but verbose
result = {True: true_value, False : false_value}[cond]
# More concise
result = [true_value, false_value][not cond]
In my own experience the common "[false_value, true_value][cond]" is
error prone because the ordering of the values is opposite what I'd
expect, so I wouldn't recomend that.
When short circuiting is required, I have no problem telling people to
suck it up and use a a real if/else statement since this case is
relatively rare. To quote M. Hudson quoting Tim Peters "learn to love
the return key".
Sigh.
I started out +0.5 on the ternary operator, but all of the proposed
syntaxes are worse than the status quo in my eyes. (except perhaps some
of the "then" based syntaxes which I'm still looking at). So, I'm slowly
drifting towards -1 on the whole thing. The tone of the discussion is
starting to push me that way as well.
Doctor-it-hurts-when-I-do-this-Then-don't-do-it'ly yours,
-tim
> -Dave
>
More information about the Python-list
mailing list