[Sugar-devel] Coding style: line continuations

Simon Schampijer simon at schampijer.de
Thu Nov 11 13:09:15 EST 2010


On 11/11/2010 05:39 PM, Sascha Silbe wrote:
> Excerpts from Sugar Labs Bugs's message of Wed Oct 27 11:11:49 UTC 2010:
>
>>   {{{
>>   249                 self._shared_activity.connect('buddy-joined',
>>   250                     self._buddy_joined_cb)
>>   }}}
>>   In emacs I just use tab for that, the next line then gets aligned under
>>   the buddy joined. Same below:
>>   {{{
>>   290             logger.debug('Tube address: %s', \
>>   291
>>   self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].GetDBusTubeAddress(id))
>>   }}}
>
> We should agree on a continuation style, otherwise we'll confuse new
> contributors.
>
> I'm using four spaces for line continuations because it will
>
> 1. decrease the chance of having to split the line several times
> 2. always look the same
> 3. make the code easier to read (though that's obviously subjective)
> 4. work in every editor (none of the editors I've used so far supports
>     Emacs' continuation style)
>
> (I consider 4. to be of minor importance as it's easy enough to adjust
> manually)
>
> In cases where using four spaces would make the code harder to read
> because the block following it uses the same indentation width I add
> four more spaces (i.e. eight total):
>
> if (really_really_long_variable_name>  another_long_variable_name and
>          long_variable_name[another_long_variable_name] == 'bar'):
>      print "whatever"
>
>
> I applied this style for the clean-up patch series.
>
> Sascha

In general I would do what the spec says if there is no good reason not 
to [1]. The example they have does not really handle all the cases, 
though. Neither pep8 nor pylint does favor any formatting. So I guess we 
are a bit free here.

I think your case from above is the most important one in terms of 
readability (using 8 spaces when the next line does 'call' for it). 
About the other cases, not 100% sure yet. You make good points. Maybe we 
can apply it to one major file and see how it looks like then, if I then 
don't run away...:) What do other major python projects do? Worth to 
check there as well.

And maybe "nitpick Marco" has an opinion on it :)

Regards,
    Simon

[1] http://www.python.org/dev/peps/pep-0008/


More information about the Sugar-devel mailing list