single-line terinary operators considered harmful
Clark C. Evans
cce at clarkevans.com
Wed Mar 5 03:57:08 CET 2003
On Wed, Mar 05, 2003 at 02:14:06AM +0000, Dennis Reinhardt wrote:
| The weakness is that Python has a "dangling else" ambiguity which requires
| indentation to disambiguate (i.e. the if-else must occupy two lines
Why is this a weakness? I like indentation. I use Python exactly
beacuse it uses indentation to show me structure. The biggest problem
I have with all of the 'terinary' options is that they are
The only solution that the terinary operator needs to solve
is a way to provide for conditional logic within an expression
intead of forcing the programmer to use statements.
After the select/case option presented previously, my second
best option would be something like...
var = (if 1 == x: 'yes'
Where the 'else' must be in the same column as the
Getting it to fit on a single line is just an unnecessary
distraction, and, IMHO, one that is bogging down the whole
discussion down... and preventing a good mechanism to
express conditional logic within an expression.
More information about the Python-list