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

Christian Tismer tismer at tismer.com
Sat Feb 8 15:51:35 EST 2003


Aahz wrote:
> In article <mailman.1044670460.17376.python-list at python.org>,
> =?iso-8859-1?q?Fran=E7ois_Pinard?= <pinard at iro.umontreal.ca> wrote:
> 
>>We have an important precedent in Python, in the form of list
>>comprehension, where `if' and `for' are appended to the expression.
> 
> 
> Had I been clearer-minded, I would have argued against listcomps on that
> ground.  As it is, I'm not sure I want to continue the precedent.

Seconded!
listcomps are leading to "uncomprehensions". I would
like to see them dropped as a step in the wrong direction.

The proposed syntax is counterintuitive for me by two reasons:

a) control flow in Python always involves special characters.
    It should at least have some markup at the start and end.

b) reading and execution order should match as much as possible.

-42 on PEP 308

cheers -- chris


p.s.:
Reasoning about a):

I consider the if and the colon in "if ... :" as valuable
markup, which is missing very much by the use of lame
words inside of the expression. Admittedly, this can be
made much more readable by higlighting editors, but this
should not be made mandatory.

Remark: Algol 68 did this by stropping of keywords,
which made if-expressions quite readable. But what
I really liked (many others not, so it is as exotic
as indentation) is the bracketing IF FI.
IF ... THEN ... ELSE ... FI
This tries to resemble brackets by using FI as a picture
of a closing bracket. I personally could live with a thing
like this, since it is symmetric and has good markup
(even without stropping).
It is as strong as indentation: For indentation, you
don't need to think of any priorities.
Nor do you have to with brackets.

Reasoning about b):
Anybody know about how Forth does it? The
proposal reminded me a litle bit of that:

<cond> if <true-case> else <false-case> then

This is reverse polish notation, which is strange
by nature. But it has one advantage over the PEP's
and the listcomps infix/postfix mix:
You read it from left to right, and you know the
machine does it exactly the same way. No priorities,
no nothing. (But you need to install a stack in your
brain :-)
The similarity to the PEP is funny: Just <cond>
and <true-case> appear to be swapped.

I don't propose Forth, but I find the proposal
in the PEP as unattractive as that.

p.p.s: Maybe I'm going to make a proposal.

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/








More information about the Python-list mailing list