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

Alan Daniels from_deja at alandaniels.com
Mon Feb 10 10:28:59 EST 2003


Erik Max Francis <max at alcyone.com> wrote in message news:<3E4739CF.A36F48F4 at alcyone.com>...

[snippage...]
> Alan Daniels wrote:

> 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.)

This is a valid complaint. Even though I've proposed it, I'm not
entirely happy with the combination of a character and keyword myself,
but I figured it was an idea worth mentioning, even if just to see what
anyone might counterpropose. For what it's worth, here's what I want to
see in a ternary operator:

1) Is readable and obvious, for people both with and without
   backgrounds in C.
2) Gets the "cond" part of it first, just like in Python's
   current use of the "if" keyword.
3) Doesn't break the meaning of any existing constructs.

I haven't seen any proposal so far that meets these criteria of mine.
I'd also be tempted to add "does not add any new keywords or operators",
even though my own proposal fails this. But, I see this as mildly desirable,
but not strictly necessary.

I don't like the "result = if cond: x else: y" because ultimately, it
implies that any and all "if" code blocks in Python code will have to
be expressions, for the sake of consistency. This is *big* language
change, and not one's that's justified for the sake of adding a new
operator.

> > (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.

I'm perfectly aware of that. I even sat down and read the PEP. Like
everyone else in this thread, I'm stating my opinion on the proposed
solution. I thought that would go without saying.




More information about the Python-list mailing list