PEP 308: Alternative conditional operator forms

Michele Simionato mis6 at pitt.edu
Thu Feb 13 15:12:50 EST 2003


Evan Simpson <evan at 4-am.com> wrote in message news:<mailman.1045072969.29508.python-list at python.org>...

<snip>

> 
> > (if C: print x
> >  else: print y)
> > 
> > would be a syntax error!
> 
> Placing any statement in any form of conditional expression is a 
> SyntaxError.  If a naive coder were tempted to try it based on the 
> similarity to the if-statement syntax, they would immediately be 
> informed by the compiler that they can't do that.  Checking the docs 
> would (presumably) reveal the explanation to them.
> 
> Cheers,
> 
> Evan @ 4-am

I think that's the point where we disagree: in my view, ideally one
should be able to understand how something works *without* checking
the docs. In the
real life, of course this is impossible, but this does not means that
we
should not pursue that ideal, especially with Python.

I tested the proposed syntax showing it to my girlfriend (see the
thread
on usability studies). She is an happy non-programmer and found the 

z=(if C: x else: y)

construct very hard to read, much harder than

z=x if C else y

The reason of the unreadability were the colons, since she liked

z=(if C then x else y)

(even if I prefer the form without "if" to avoid any possible
confusion
with the statement).

If you think that programming languages should be written for experts
only,
who like to decipher unreadable constructs, then maybe you should give
a try
to Perl ... 

                        Michele




More information about the Python-list mailing list