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

Paddy paddy3118 at tiscali.co.uk
Sat Feb 8 00:35:26 CET 2003


Eru wrote:
> Guido van Rossum <guido at python.org> escribio:
> 
>>Proposal
>>
>>   The proposed syntax is as follows:
>>
>>       <expression1> if <condition> else <expression2>

Don't like the above. It doesn't 'scan right for me'.



> 
> Mmm, introducing a new keyword can be a problem, and I don't think it's a good
> idea in this case. Moreover, it isconfusingly similar to the 'normal' syntax;
> it could led to problems like doubting when 'then' is needed and when it must
> not be used.
> 
> How about 
> 
> if condition : expression1 else expression2
> 
> If that's not suitable for any reason (I haven't actually thought carefully 
> about the side effects), I prefer the a?b:c option
> 

Damn!
Eru seems to have got the same idea as I had.

I like this as it it is very similar to the if statement and so has very little extra 
baggage for newbiew to learn.

I also think that the order of condition then true expr followed by false expression 
'scans right'.

I would go further and suggest that the else clause be allowed to be left out. If the 
condition is false then the expression should then return None.

So an if to the right of an equals sign is the ternary operator.


Rgds, Paddy.





More information about the Python-list mailing list