PEP 308: I liked the original proposal better

David Glass nospam at nospam.ca
Fri Feb 14 08:16:28 EST 2003


Erik Max Francis wrote:
> David Glass wrote:
> 
> 
>>Although I am not sure any ternary operator is worth changing the
>>language, I too believe the original proposal to be the most Pythonic
>>and elegant.
>>
>>x if C else y
>>
>>doesn't stick out like
>>
>>(if C: x else: y)
>>
>>which, as a special case, requires parentheses.
> 
> 
> It doesn't _require_ parentheses, but parentheses as a requirement are
> part of the PEP.
> 
> Further, I'm not sure why "not sticking out" is a good requirement. 
> Wouldn't you want something that's easy to spot and interpret, rather
> than something which quietly blends in?
> 

I meant that the requirement of the current proprosal for enclosing 
parentheses "sticks out" in that it is an exceptional case when compared 
to other expressions which do not require enclosing parentheses. It 
feels like an unnecessary inconsistency.

However, given the similarity of this form to the "if" statement (colons 
and all), I can see why parentheses are probably desirable here for both 
human and machine readers alike. I can also see some advantage in it 
being similar to and consistent with the "if" statement, but I still 
prefer "x if C else y" over the other pro-ternary alternatives I've seen 
so far.





More information about the Python-list mailing list