PEP 308: A PEP Writer's Experience
David Gausebeck
gausebec-spam at paypal.com
Sat Feb 8 21:43:58 EST 2003
More information about the Python-list mailing list
Sat Feb 8 21:43:58 EST 2003
- Previous message (by thread): ActivePython Install problem
- Next message (by thread): PEP 308: A PEP Writer's Experience - CON
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>In doing the PEP last time, I collected numerous proposed >spellings. None were perfect -- here is each with it's >weaknesses: > > [3a] condition ? val1 : val2 > > + same as C, C++, and Java > - not readable (except to c/java programmers) > - uses punctuation in odd ways > - : is already overused > > [3b] condition ? val1 ! val2 > - still uses punctuation in odd ways > - still not readable > > [3c] if condition then val1 else val2 > + readable > - probably requires new keyword (perhaps "soft" keyword) > - ambiguity with if statement could make it hard to read > - ambiguity with if statement makes it impossible for > Python's parser > > [3d] if condition: val1 else: val2 > - overuse of : > - ambiguity with if statement could make it hard to read > - ambiguity with if statement makes it impossible for > Python's parser > > [3e] if(condition) val1: val2 > - overuse of : > - () already mean grouping and tuples, that's enough! > - already meaningful in python's current syntax > > [3f] val1 when condition else val2 > + reads like english > - new keyword > - condition evaluated first but is textually in middle > > [3g] val1 if condition else val2 > + reads like english > - condition evaluated first but is textually in middle > >If you throw out the unparsable, avoid innovative uses for >punctuation that are difficult to read, and don't want to >introduce a new keyword, you're left with [3g]. It's only >real flaw is that condition appears in the middle, but >nothing's perfect. That's why Guido's PEP 308 proposes [3g]. There are a couple more ideas that have come up in the PEP thread, and there are two in particular that I like better than any in the above list. From Alan Daniels: condition ? val1 else val2 This is just another variant of [3a] and [3b], but it uses less punctuation and is (IMO) more readable as a result. >From Paul Rubin: <new keyword> condition: val1 else val2 this is like [3d] but without the ambiguity with if. Of course, its big disadvantage is the requirement of a new keyword. The original suggestion was for the keyword 'ifelse' or possibly 'select'. I was thinking 'when' could work, and my latest idea for it is 'case'. A simple example of each looks like: x = y>0 ? y else 0 x = case y>0: y else 0 -Dave
- Previous message (by thread): ActivePython Install problem
- Next message (by thread): PEP 308: A PEP Writer's Experience - CON
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list