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

Dale Strickland-Clark dale at riverhall.NOTHANKS.co.uk
Sat Feb 8 10:04:38 EST 2003


I am quite surprised at the number of people who have missed important
points in this proposal and at the amount of prejudice against
suggestions that have already appeared in other languages.

The important points are:

1. This is a proposal to extend expressions with a test to return one
of two values (as apposed to an alternative to program flow logic).

2. It is desirable to evaluate only the result expression and not the
discarded expression.

There is also an implicit requirement to by "Pythonic" -- something
which I'm happy to ignore as it obviously means whatever the user of
the term wants it to mean. It is a smokescreen for appearing
pro-Python while really just being anti-change. I don't think anyone
would describe list comprehension as Pythonic, yet this is perhaps the
most useful recent addition to the language.

The other consideration often raised and used as an excuse for an
objection or a standpoint are thoughts for the poor beginners. 

The widespread use of C++, Perl and TCL (to pick a few at random) is
proof that beginners will persevere with anything that is of interest
or benefit to them. It is arbitrary and self-defeating to unnaturally
constrict the enhancement of the language -- especially a feature you
can take or leave -- because someone may not understand it. The people
that like or want these syntactic frills will figure them out.

That said, I am as pro-ellegance as the next guy. I hate kludges.

As far as I can see, there are still only two serious contenders:

a) special characters: cond ? exp1 : exp2

b) textual:            cond if exp1 else exp2

The others suggestions offered in response are ethier pointless (they
offer nothing not already in the proposal) or have missed the point.

a) has been criticised for being C-like and b) for being Perl like.

Good. So we know they both work. The fact that they have been used
elsewhere is surely a point in their favour. To invent a construct to
meet a well understood need that hasn't appeared anywhere else is
surely an argument against it's use. I don't see anyone objecting to
using '*' as the multiply operator in spite of it being nothing like
'x' which most beginners seem to prefer.

I think we can ignore those who simply flatly vote against this
proposal. They obviously don't use the language as much as the rest of
us or have a problem with change. 

I also think we should disregard the form

cond ? exp1 ! exp2 

simply because it hasn't been used before. It is difference for its
own sake.

My vote goes for ?: because it is concise, unambiguous and would look
better in an expression.

However, I would vote for if/else if that was the only option left.

--
Dale Strickland-Clark
Riverhall Systems Ltd




More information about the Python-list mailing list