PEP 308: Erik's alternatives list

phil hunt philh at cabalamat.uklinux.net
Wed Feb 19 09:18:18 EST 2003


On Tue, 18 Feb 2003 18:59:31 -0800, Erik Max Francis <max at alcyone.com> wrote:
>Here is the list:

...and here are my comments...

>I.  Proposals mentioned in the PEP at some point
>
>1.  x if C else y

I don't like this. The existing conditional construct in Python has 
the order C - x - y. Similar constructs in other languages use this 
same order. This is, by far, the most common order of doing things 
in mainstream programming languages. Therefore, it is the easiest 
orderr to learn for people coming to Python from other langs (and 
people coming to other langs from Python).

>2.  if C then x else y
>3.  if C: x else: y

These are consistent with how Python presently does things, so i 
support them.

The only problem I see with thme is that people might mistake them 
for the existing conditional statement. One way round this might be 
to enclose them in (...) or possibly [...], for example:

   days = (if year%4==0 then 29 else 28)
or
   days = [if year%4==0: 29 else: 28]


>4.  C ? x : y

I like this. It has the advantage of being familiar to anyone using 
C, C++, C#, Objective C, Perl, PHP, Java, Javascript, Awk, and 
probably a lot of other languages too.

I would note that, according to the statistics on Sourceforge and 
Freshmeat, this list include all the langauges commonly used for 
open source development. Therefore, people moving to Python from 
other langs will find this familiar.

>5.  C ? x ! y
>6.  cond(C, x, y)                                                    (*)
>7.  C ?? x || y

These are all OK, IMO. Though I have no particular enthusiasm for 
them.

>8.  C then x else y

This would be better enclosed in (...).

As it stands, i don't think it looks obvious enough that it is a 
conditional.

>II.  Proposals which were "seconded"
>
>1.  x when C else y

yuk

>2.  C ? x else y

OK I suppose.

>3.  C -> x else y
>4.  C -> (x, y)
>5.  [x if C else y]
>6.  ifelse C: x else y                                              (**)

Not keen on any of these.

>7.  <if C then x else y>

OK

>8.  C and x else y

Yuk.

>III.  Proposals but were not "seconded"
>[...]
>8.  C then: x else: y
>10. (? C: x, y ?)

Of this category, these two are the only ones I like.


-- 
|*|  Philip Hunt <philh at cabalamat.uklinux.net>   |*|
|*|  "Memes are a hoax; pass it on"              |*|





More information about the Python-list mailing list