Defending the ternary operator
Jeremy Fincher
tweedgeezer at hotmail.com
Mon Feb 10 10:56:00 EST 2003
Carlos Ribeiro <cribeiro at mail.inet.com.br> wrote in message news:<mailman.1044730161.12704.python-list at python.org>...
> While I agree that programmers love to save keystrokes, in some cases is more
> important to save line count. Long blocks of code tend to be hard to read,
But they're significantly easier to read than the same code on a
single line.
> If used **with care**, conditional operators may allow to eliminate a few
> 'auxiliary' if statements out of the way, thereby making the structure
> clearer. Things such as selecting values for printing, etc., don't need to
> stay on the way, and may be distracting when looking at the code.
But *all* the code still needs to be read by anyone wanting to
understand it well. It might as well be on separate lines for ease of
readability.
I may be alone in this, but I find
if condition:
do_something()
To be significantly more readable than:
if condition: do_something()
The indentation shows me the control stucture much better. An
if-expression would make the latter far more common than it already
is.
Jeremy
More information about the Python-list
mailing list