Compare source code

Neil Cerutti neilc at norwich.edu
Mon Nov 8 08:50:55 EST 2010


On 2010-11-07, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
> In message <8jftftFelnU1 at mid.individual.net>, Neil Cerutti wrote:
>
>> The handsome ':' terminator of if/elif/if statements allows us to
>> omit a newline, conserving vertical space. This improves the
>> readability of certain constructs.
>> 
>> if x: print(x)
>> elif y: print(y)
>> else: print()
>
> I would never do that. ???Conserving vertical space??? seems a
> stupid reason for doing it. In C, I even go the opposite way:
>
>     if (x)
>       {
>         printf(..., x);
>       }
>     else if (y)
>       {
>         printf(..., y);
>       }
>     else
>       {
>         printf(...);
>       } /*if*/

Interesting. I find conserving vertical space to be a big win. I
understand why you'd enforce braces for virtually all code bodies
in C. In C, I'm giving up the most obvious form of expression for
something obviously more robust. In Python, there's no such
trade-off. Forbidding one-line conditional statements in Python
would sacrifice succinctness for nothing.

-- 
Neil Cerutti



More information about the Python-list mailing list