Tabs for indentation & Spaces for alignment in Python 3?

Simon Ward simon+python at bleah.co.uk
Sat Dec 6 12:12:29 EST 2014



On 6 December 2014 03:04:48 GMT+00:00, Michael Torrie <torriem at gmail.com> wrote:
>On 12/05/2014 07:31 PM, Ned Batchelder wrote:
>> This is a perfect example!  The code (with tabs as >--- and leading 
>> spaces as .) is:
>> 
>>   >-------if (!list_empty(pending))
>>   >------->-------ret = list_first_entry(pending, struct async_entry,
>>   >------->------->------->-------.......domain_list)->cookie;
>> 
>> Now, display it in your editor with tabs set to four spaces:
>> 
>>   >---if (!list_empty(pending))
>>   >--->---ret = list_first_entry(pending, struct async_entry,
>>   >--->--->--->---.......domain_list)->cookie;
>
>However, a conscientious programmer knows that tabs could be
>arbitrarily
>sized, so he would never do that.  Instead he would do:
>
>   >-------if (!list_empty(pending))
>   >------->-------ret = list_first_entry(pending, struct async_entry,
>   >------->-------.......................domain_list)->cookie;
>
>Which under the heretical tab size of 4:
>   >---if (!list_empty(pending))
>   >--->---ret = list_first_entry(pending, struct async_entry,
>   >--->---.......................domain_list)->cookie;

Not every programmer is as conscientious in the first of place, and that's far easier to get wrong than just agreeing to stick to one thing. This is why (often more rigid) style guides (or rather policies) exist. 

Maybe we should sack such programmers regardless of their other abilities instead of forcing all, including the conscientious, programmers to adhere to strict style policies? While I like the idea, I think that a slap on the wrist and a bit of re-indentation/re-alignment is all that is necessary (although I have worked with people who consider pure style changes to be a sin too).

Simon



More information about the Python-list mailing list