[Python-ideas] Parenthesized Compound With Statement

Ron Adam ron3200 at gmail.com
Thu Jul 4 01:57:46 CEST 2013



On 07/03/2013 04:39 PM, Guido van Rossum wrote:
>
> Maybe you're talking about this case:
>
> instructions = [
>      'foo',
>      'bar',
>      'very long line'            # comma intentionally missing
>      ' which is continued here',
>      'not so long line'            # comma accidentally missing
>      'accidentally continued',
>      'etc.',
> ]
>
> I brought this up a few weeks or months ago, hoping to convince people that
> implicit string concatenation is evil enough to ban. I didn't get very far.

I'm +1 for that change BTW.

It falls under the management category of how difficult it can be to get 
people to want to change how they think.


> But allowing backslashes here won't accomplish anything, because they are
> redundant. (In fact I get really mad when people use backslashes for
> continuation inside parens/brackets/braces. :-)

But you did apparently feel the need to put verbose comments there to 
clarify the example. ;)

Yes, the backslashes are redundant as far as the compiler goes, but they 
serve as hints to the human reader, (in the same way your comments did.), 
so I don't think they are completely redundant.

New users would probably find the following easier to read because they 
don't yet think in terms of what the CPU is actually doing or not doing. 
That probably takes a few years of programming to reach that point.

  instructions = [
       'foo',
       'bar',
       'very long line' \
       ' which is continued here',
       'not so long line' \
       ' accidentally continued',
       'etc.',
  ]

This doesn't bother me, each line has a meaningful ending to the reader, 
and there is no need for comments to make it clearer.  And the number of 
backslashes is not excessive.

I'm neutral on this, not need to recommend, or discourage it.  It helps 
some people while, others find it unnecessary.  It's a human thing, the 
compiler doesn't care.


But this ...

  instructions = (
       'very, ' \
       'long, ' \
       'line with commas in, ' \
       'it to, ' \
       'seperate individual, ' \
       'items, ' \
       'etc, ' \
  )

Now, this gets under my skin!  This is definitely redundant.


The missing comma case I saw was in a list several screen pages long with 
only a few lines continued, and one missing comma.  I just can't recall 
which file it is.  Meant to put it in the tracker, and still do once I find 
it again.  I think I saw it in one of the encoding files.

Cheers,
    Ron








More information about the Python-ideas mailing list