single-line terinary operators considered harmful
Clark C. Evans
cce at clarkevans.com
Tue Mar 4 21:57:08 EST 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
| minimum).
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
single-line solutions.
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'
else: 'no')
Where the 'else' must be in the same column as the
corresponding if.
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.
Grins,
Clark
More information about the Python-list
mailing list