[Python-ideas] Line continuations with comments

Stefan Drees stefan at drees.name
Mon Jun 10 07:33:01 CEST 2013


On 2013-06-09 21:52, Christian Tismer wrote:
> On 23.05.13 01:15, Ron Adam wrote:
>>
>> I'm not sure why some people dislike the back slash so much as a
>> continuation tool.  Python is the language that avoids using {braces
>> around blocks}, so you'd think it would be the other way around.
>>
>> I really don't think the '\' will be over used.  New programmers do
>> try a lot of strange things at first for making their own programs
>> easier to read, (I did), but usually they come around to what the
>> community practices and recommends.
>>
>
> I think the reason that people don't like the '\' is that it opens up so
> many
> bad memories:
>
> - having to use them inside C macros
> - having to deal with it on windows
> - felt unpythonic because it is a low-level trick to produce longer lines
>
> Especially the unpythonic feeling comes from the fact that '\' either has
> special meaning in strings (which is accepted) or has very restricted use
> outside of strings:
>
>      there must not be anything but the line end after it.
>
> So by lifting the usability of '\' to allow comments after it makes it from
> an ugly left-over C feature into something useful that people _want_ to use
> for splitting the continuation of something from the comments.
>
> I think after introducing it, the bad prejudice will vanish.
>
> The mental change is from "a hack because the line doesn't fit"
> into "a well-formed structuring tool to split code and comment"...

there are two other reasons that jump into sight:

- as continuation signal in shell: who has not been bitten by an
   innocent space following the backslash? ... and it's not the space
   we dislike ;-)

- on my console I use three fingers to produce this one symbol "\"
   eg. <ALT-SHIFT-7> so I even might visit trigraph-land again ??/

All the best,
Stefan.

> cheers - chris
>
>>
>>>     <snip>
>>>
>>>     The reason \# works, but not \ #, is when the comment comes directly
>>>     after the back slash, it's removed and leaves a (backslash +
>>> new-line)
>>>     pair.
>>>
>>>
>>> Whether we require there be no space between \ and # or, conversely,
>>> require there be at least one whitespace character should not be
>>> based on
>>> the relative ease of patching the current code. Personally, I would
>>> prefer
>>> the latter as I believe requiring a space after \ will increase
>>> readability.
>>
>> My preference is to allow any number of spaces before and after the
>> '\'. and that any comments after the slash not change what it means.
>>
>> A built in single space rule would probably frustrate people who don't
>> want to do it that way.  Like how you get a character after a
>> continuation error, even if it's only a single space.  Yeah, it's how
>> it works, but it's still annoying to get that error in that situation.
>>
>> A comment of course, would still uses up the rest of the line. So a
>> '\' after '#' is just part of the comment.
>>
>>
>> Cheers,
>>    Ron
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
>
>



More information about the Python-ideas mailing list