Continuing indentation

Rob Gaddi rgaddi at highlandtechnology.invalid
Thu Mar 3 13:06:56 EST 2016


Marko Rauhamaa wrote:

> John Gordon <gordon at panix.com>:
>
>> In <871t7sbkex.fsf at elektro.pacujo.net> Marko Rauhamaa
>> <marko at pacujo.net> writes:
>>
>>> Ethan Furman <ethan at stoneleaf.us>:
>>
>>> > No, it isn't.  Using '\' for line continuation is strongly discouraged.
>>
>>> Why would you discourage valid syntax?
>>
>> Some things that are permissible may not be desirable.
>
> Line continuations are such a central part of the syntax that it would
> seem silly to deprecate them.
>
> While it is true that
>
>    if a and \
>       b:
>        pass
>
> is ugly,
>
>    if (a and
>        b):
>        pass
>
> is even uglier.
>
>
> Marko

Not ugly, error-prone.  The first is purely aestehetic, the second
actually matters.  Let something as simple as a trailing space sneak in
after your backslash and your meaning changes.  Blank line between; same
thing.

Granted in Python that will tend to lead to a SyntaxError, rather than
silently shoot you in the foot the way this used to in C:

if (condition)
   first_action();
   section_action();
else {
   alternate action();
}

But the principle remains.  Syntactic whitespace has its ups and downs
on the leading edge of the line, but at least it's visible there.  On
the trailing end of the line it's actively inviting trouble in for
coffee and eggs.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list