[Python-ideas] allow line break at operators

Yingjie Lan lanyjie at yahoo.com
Sun Sep 4 05:58:08 EDT 2011


>
Thanks, I think that's the rule described in its full glory. Currently I am not  quite sure of the use case for continuation nested in continuation -- it seems to be still a single continuation, but it allows for some additional freedom in formatting the continued line. Do you have other use cases for that?


For the case of mis-indentation, as demonstrated in your scenario, I think it is better that the rule is not applied to a comment continued onto the next line. The effect of a '#' only carries to the end of a line, if one would like the next line to be a comment, just use another '#'. It remains to consider a mis-indentation that only involves code lines. However, that is not a new problem, so we should not worry (it is like a sunken cost). 

Sorry for top posting. It seems yahoo web email is not designed with such a use case in mind.


>________________________________
>From: MRAB <python at mrabarnett.plus.com>
>To: python-list at python.org
>Sent: Sunday, September 4, 2011 10:04 AM
>Subject: Re: [Python-ideas] allow line break at operators
>
>On 04/09/2011 00:22, Yingjie Lan wrote:
>>>  Every language with blocks needs some mechanism to indicate the
>> beginning and ending of blocks and of statements within blocks. If
>> visible fences ('begin/end' or '{}') and statement terminators (';') are
>> used, then '\n' can be treated as merely a space, as it is in C, for
>> instance.
>>>  and it uses unescaped '\n' (with two escapement options) to terminate
>> statements. This is fundamental to Python's design and goes along with
>> significant indents.
>>
>> Agreed. Currently indentation in Python starts a new block, but if you
>> view it from the perspective of line breaking, it also functions as if
>> the line is continued. The line of code below
>>
>> if condition: do_a(); do_b()
>>
>> can be written as:
>>
>> if condition: #line breaks
>> do_a(); # ';' is optional here
>> do_b() # continue
>>
>> That indentation can be also employed for line breaking is quite evident
>> to me. During the open email correspondence with Stephen, it seems to be
>> a tenable point.
>>
>>  > There would then be three ways to escape newline, with one doing
>> double duty. And for what? Merely to avoid using either of the two
>> methods already available.
>>
>> I believe the other two ways are not as good as this new way. As the
>> proposal is fully backward compatible, people may choose whatever way
>> they prefer.
>>
>I think that the rules would be:
>
>If a line ends with a colon and the next line is indented, then it's
>the start of a block, and the following lines which belong to that
>block have the same indent.
>
>If a line doesn't end with a colon but the next line is indented, then
>it's the start of a continuation, and the following lines which belong
>to that continuation have the same indent.
>
>In both cases there could be blocks nested in blocks and possibly
>continuations nested in continuations, as well as blocks nested in
>continuations and continuations nested in blocks.
>
>I'm not sure what the effect would be if you had mis-indented lines.
>For example, if a line was accidentally indented after a comment, then
>it would be treated as part of the comment. It's in cases like those
>that syntax colouring would be helpful. It would be a good idea to use
>an editor which could indicate in some way when a line is a
>continuation.
>
>>     ------------------------------------------------------------------------
>>     *From:* Terry Reedy <tjreedy at udel.edu>
>>     *To:* python-list at python.org
>>     *Cc:* python-ideas at python.org
>>     *Sent:* Sunday, September 4, 2011 3:01 AM
>>     *Subject:* Re: [Python-ideas] allow line break at operators
>>
>>     On 9/3/2011 3:51 AM, Yingjie Lan wrote:
>>      > I agree that long lines of code are not very common in many projects,
>>      > though it might be the case with some heavily involved in math.
>>     For some
>>      > reason, when the feature of free line breaking came about in computer
>>      > languages, it is welcomed and generally well accepted.
>>
>>     Every language with blocks needs some mechanism to indicate the
>>     beginning and ending of blocks and of statements within blocks. If
>>     visible fences ('begin/end' or '{}') and statement terminators (';')
>>     are used, then '\n' can be treated as merely a space, as it is in C,
>>     for instance.
>>
>>      > Python uses indentation for blocks,
>>
>>     and it uses unescaped '\n' (with two escapement options) to
>>     terminate statements. This is fundamental to Python's design and
>>     goes along with significant indents.
>>
>>      > and by the same mechanism, line breaking can be
>>      > accommodated without requiring parenthesis or ending backslashes.
>>
>>     You need proof for your claim that indentation can be used for both
>>     jobs in the form of a grammar that works with Python's parser. I am
>>     dubious that you can do that with an indents *after* the newline.
>>
>>     Even if you could, it would be confusing for human readers. There
>>     would then be three ways to escape newline, with one doing double
>>     duty. And for what? Merely to avoid using either of the two methods
>>     already available.
>>
>
>-- 
>http://mail.python.org/mailman/listinfo/python-list
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110904/81f3e399/attachment.html>


More information about the Python-list mailing list