For review: PEP 308 - If-then-else expression
Dan Schmidt
dfan at dfan.org
Sat Feb 8 00:25:27 EST 2003
jerf at compy.attbi.com writes:
| Finally, and perhaps most controversially, ISTM that people asking
| for ?: are, with perhaps a few exceptions, new users of Python who
| expect it to be just like the last (or even "only") language they
| learned.
I've been using Python for five years, which is certainly less than
some, but I think it's long enough to not expect it to be just like
every other language.
I'm familiar with about a dozen other languages.
I really want a ternary operator. Now that boolean types have made it
into 2.3, it's about the last thing I really want. I can't tell you
how excited I was when I saw that Guido was considering finally adding
it at long last, or how depressed I was when I saw people throwing in
their -1s because they were afraid that some people would abuse it.
| If they want it that bad, in my experience it's probably because
| they're abusing it anyhow; most programmers go a very, very long
| time without using it even in languages that have it. One of
| Python's strengths is its stubborn refusal to let people hang
| themselves with it, unless they *really insist*.
I really don't think I would be abusing it. I simply want a way to
write an expression that depends on a condition without needing four
lines (and an extra variable, if my expression wasn't going to be
assigned to a variable) to do it.
It probably is true that my exposure to expression-oriented languages
like ML and Lisp makes me more aware of the benefits of a ternary
operator. I don't see that as a bad thing.
I just 'ported' (to clearer Python) a Python program using the 'and-or'
trick in a bunch of places. It was really annoying. I would much
prefer that people who were going to fake a ternary operator anyway
were given a real one to work with.
Dan
--
http://www.dfan.org
More information about the Python-list
mailing list