python syntax for conditional is unfortunate

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Sep 23 20:58:21 EDT 2008


Cameron Simpson <cs at zip.com.au> writes:

> A good coder will present things clearly. For trivial stuff the one
> line form may be fine, and for longer stuff then this:
> 
>   y = some thing or other \
>       if x \
>       else something_else

Parentheses are usually more robust for multi-line, where possible:

    foo = (bar
        if some_condition()
        else baz)

The lines can more easily be edited and rearranged without fiddling
with backslashes at the end of every line. (For even more robustness
at the cost of space, separate the parentheses so they're on separate
lines from what they enclose.)

It also addresses the original poster's complaint that there's no
early signal of the compound nature of the expression: the opening
parenthesis signals this.

-- 
 \     “It is far better to grasp the universe as it really is than to |
  `\    persist in delusion, however satisfying and reassuring.” —Carl |
_o__)                                                            Sagan |
Ben Finney



More information about the Python-list mailing list