PEP-308 a "simplicity-first" alternative
Peter Hansen
peter at engcorp.com
Wed Feb 12 12:17:58 EST 2003
holger krekel wrote:
>
> Peter Hansen wrote:
> > Any time someone writes "it's nice" or "it's a neat trick" in
> > a discussion of this nature, I'd like to run screaming from
> > the room... we _eschew_ neat tricks, not embrace them!
>
> Sorry, peter, but this sounds rather formal. Do you really think
> it's that great a "feature" that you have to switch to another idiom
> if your ternary becomes binary?
I would argue that a ternary operator should not be able to be
a binary operator with the else case left out. I'm in the camp
that not only believes the "explicit is better than implicit"
and which thinks a ternary operator with an element missing is
just too implicit to be comfortable.
Comparisons with the conventional if:/else: don't work. In
the conventional case, where you are saying "if A then DO X,
otherwise DO Z", if Z is "pass" you clearly don't need to
specify it. In the expression case, the else case would be
"None" which is not just the absence of a result but actually
a specific, special result which has special meaning in Python.
It should be explicit if this is what gets returned when you
"don't care" about the else case... I believe.
We can agree to disagree, but I'm pretty firm on this point and
don't believe you can dissuade me. On the other hand, if your
preference makes it in, I probably won't be overly concerned
either, although I doubt I'd ever use it and I would probably
find it surprising each time I read it.
-Peter
More information about the Python-list
mailing list