PEP 308 - keeping it simple
Ian Parker
parker at gol.com
Sun Feb 16 19:22:11 EST 2003
In article <RwO3a.135333$HN5.529257 at rwcrnsc51.ops.asp.att.net>, djw
<dwelch91 at no.spam.attbi.com> writes
>Ian Parker wrote:
>> Several posters have mentioned the FAQ entry:
>> 4.16. Is there an equivalent of C's "?:" ternary operator?
>> Different implementations of a ternary operator will lead to
>> embarrassing FAQ entries:
>> 4.16. Is there an equivalent of C's "?:" ternary operator?
>> Yes, as you know Python is an elegantly simple language and of course
>> provides a ternary operator equivalent to "c?a:b", although more
>> long-winded, and requiring parentheses
>> (if c then a else b)
>> or
>> 4.16. Is there an equivalent of C's "?:" ternary operator?
>> Yes, just use a similar construction to an if statement, but swap the
>> order of the terms around a little to get
>> a if c else b
>> which everyone agrees would be a natural way to express a conditional,
>> if one wasn't already familiar with the order used in if statements.
>> Let's just go for the C way of doing this so that we can drop the
>>FAQ
>> entry entirely.
>>
>Or, we could just adopt C syntax for the entire language and drop
>Python specific documentation altogether. <Wink> Seriously though, for
>me, having syntax that looks like C (or Perl, Pascal, etc, etc) is not
>something to strive for. On the contrary, I find constructs like x ? y
>: z to be rather hard to read. Python is not C. Let's keep it that way!
>
>/d/
>
Adopting all of C might be going a bit far, but I don't mind having a
few operators in common!
I'd agree that the "x ? y : z" is harder to read than a binary operator,
but it is surely simpler than a list comprehension and look how quickly
one gets used to those. I was initially peeved at fashionable
complications being introduced into Python and it was only when I
actually bothered to write a list comprehension that I realised how easy
and convenient it was.
--
Ian Parker
More information about the Python-list
mailing list