[sugar] Python coding conventions

Marco Pesenti Gritti mpg
Mon Oct 2 10:20:59 EDT 2006


Dan Williams wrote:
> On Mon, 2006-10-02 at 14:10 +0200, Marco Pesenti Gritti wrote:
>   
>>>> When we decided for tabs I remember Dan had a discussion with David 
>>>> about this and he was feeling strongly for tabs. Dan?
>>>>     
>>>>         
>>> (obviously activities can do what they want)
>>>
>>> Yeah, I'm a tabs guy.  But a lot of the python bindings code for GNOME
>>> that we were using also used tabs, and we felt consistency there too was
>>> worth something.  Maybe not.
>>>
>>> People who prefer spaces either (a) like hitting arrow keys a lot, or
>>> (b) have an editor that skips spaces automatically.  Not every editor
>>> does that, or does it consistently.  Presumably Python started using
>>> 4-space-width tabs because they couldn't agree on how big a tab was
>>> supposed to be and decided to make the question irrelevant. 
>>>   
>>>       
>> To me the pro of spaces are:
>>
>> - You can read the code on every editor and it will always look the same.
>>     
>
> There's always modelines, and as long as everyone agrees that a tab is
> the same width (enforced with modelines and whatnot), the code is always
> readable anyway.  It's completely the same problem.  If you choose
> spaces, everyone has to agree on (a) using spaces in the first place,
> and (b) agree on an indent width, either 4 or 8 spaces.  If you choose
> tabs, everyone has to agree on (a) using tabs in the first place, and
> (b) agree on a tab width, either 4 or 8 "spaces".  It's exactly the same
> choice either way, and making somebody else use spaces is exactly the
> same thing as making somebody use tabs.  Obviously the world would be a
> better place if everyone had exactly the same opinions... :)
>   

I was talking about reading here. If you use spaces the code will be 
displayed in the same way, no matter how many spaces a tab is set to. Or 
am I missing something?

>> - Even if you don't setup your editor and there are no editor hints you 
>> can still submit small patches with the right style by just using spaces.
>> - Maybe it's slightly less likely to get patches with the wrong style, 
>> since using spaces is the natural fallback if using tabs things doesn't 
>> look right.
>>
>> Is (b) really an issue? Both vim and emacs should handle this fine. And 
>> gedit has an option for it (not sure how well it works, we should make 
>> sure of that since it's the editor both we are using).
>>     
>
> The issue is not auto-indent; pretty much everyone supports that.  The
> issue is whether or not the editor skips whitespace when you hit arrow
> keys.  Otherwise, you're stuck hitting arrow keys _a lot_ to get around
> most places, since Ctrl+Home and Ctrl+End only work on _lines_, not
> internally to them.
>
>   

If any of emacs/vim/gedit doesn't handle this smartly than that's a 
problem. I wouldn't trade the spaces advantages I outlined above for this.

Marco


More information about the Sugar-devel mailing list