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

Chris Liechti cliechti at gmx.net
Sat Feb 8 14:29:26 EST 2003


mis6 at pitt.edu (Michele Simionato) wrote in
news:2259b0e2.0302080516.1c577eb2 at posting.google.com: 
> "Sean Ross" <frobozz_electric at hotmail.com> wrote in message
> news:<5DV0a.34649$CF1.1127662 at news20.bellglobal.com>... 
>> >
>> >     The proposed syntax is as follows:
>> >
>> >         <expression1> if <condition> else <expression2>
>> >
>> 
>> While I do not think this is necessary, I would like to offer an
>> alternative syntax:
>> 
>>     <expression1> when <condition> else <expression2>
>> 
> 
> +1 to "when". To me "if" is associated to the conditional statement, a
> conditional expression is a conceptually  different thing and needs a
> different expression. Readability is worth adding a new keyword.

+1 for 'when', +0 for 'if'

i'd prefer an other word as the condition and 'then'-part is swapped, 
compared to other ifs, as statement and in listcomps.

i think that the ternary operator completes listcomps and i like those.
also i think it's nice for initialiters:

class X:
    def __init__(self, optarg = None):
        self.someval = optarg when optarg is not None else default_value

i think an expression is much better here than an if statement in this 
case.

as for the new keyword 'when', i don't see a problem. the new syntax isn't 
backwards compatible anyway, so that a new keyword does not make a 
differece for backwards compatibility.

chris

-- 
Chris <cliechti at gmx.net>





More information about the Python-list mailing list