PEP 308: Alternative conditional operator forms

Christos TZOTZIOY Georgiou DLNXPEGFQVEB at spammotel.com
Tue Feb 11 08:01:50 EST 2003


On 10 Feb 2003 23:41:08 -0500, rumours say that Nick Vargish
<nav at adams.patriot.net> might have written:

>Darnit. I knew I should have read the whole thread before piping up.

Nick,

this is not my idea either; it was mentioned in the initial PEP by Guido
as 
 if C then x else y
only to be rejected for ambiguity; my remark (and others') is that the
'if' can be dropped, while 'then' needs not be a keyword (ie it pops up
in the middle of an expression, and look-ahead of depth 1 in Python's
parser allows special use of 'then' only in expressions).

However, I don't mind.  I'm +0 anyway.  If a ternary conditional
operator is there, I'll use it (heck, I don't mind even the 'x if C else
y') instead of "C and x or y" with its one glitch.

Why so much fuss, anyway?  I've been a C programmer for years, and I
used its ternary operator often (when I thought it appropriate); my
coding style was always dense (see patch 681780, as an example of Python
code that is not so obvious but is fast; I guess it will probably be
dropped though), being kind of a 'lone wolf' for years, and I based the
readability of my code on comments (ie, "this block does this; now move
on to the next block").  I am aware of the problems dense code creates
when co-operating with people, and the readability of Python was one of
the things that enchanted me with the language.  So I'm still learning
to code in a more readable way (I never did any XP so far).

The only reason to be on the plus side to add a "clear" ternary
conditional operator in python, is because the and-or trick already
exists.  For someone who owned a ZX Spectrum (like me), it is familiar;
it is not for a newbie.

Guido must be getting mellow.
Or old.
Or wise.
Or all of the above. :)
-- 
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')




More information about the Python-list mailing list