For review: PEP 308 - If-then-else expression

Erik Max Francis max at alcyone.com
Mon Feb 10 00:34:07 EST 2003


Alan Daniels wrote:

> On Sun, 09 Feb 2003 16:26:06 -0800, Erik Max Francis <max at alcyone.com>
> wrote:
> 
> > The combination of the punctuation and a keyword still gives me an
> > eek.
> 
> Actually, we have combinations of punctuation and keyword already,
> because every "if" and "else" has to be followed by a colon character.

I was really referring to punctuation other than colons, which are
ubiquitous in Python code.  I thought that was kind of implied.

> I agree that a ternary operator would be useful, and most people here
> seem to want one, as long as it's "Pythonic", that is, easy to
> understand at first glance, easy to read later on, and not prone to
> abuse over time.
> 
> I'm proposing the...
> 
>   cond ? x else y
> 
> ...syntax because I haven't really seen any more legible alternative.

My moderate objection to it is that the ? helps people familiar with
conditional operators in other langages but isn't really a panacea for
someone coming across it for the first time (the ? doesn't really tell
me what's going on).  I personally just have an objection to a ternary
operator (conditional or not) where one element is punctuation and the
other is a keyword, it seems ugly to me.  (In this case, it's merely an
attempt to keep as close to the ?: notation used in other languages,
which in and of itself doesn't really impress me.)

> (P.S. I still don't see what's wrong with good ol' "cond ? x : y")

Because Guido said so in the PEP.  It's his language.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ She glanced at her watch ... It was 9:23.
\__/ James Clavell
    Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
 A personal guide to Quake III Arena.




More information about the Python-list mailing list