Tabs versus Spaces in Source Code ('semantic' vs. arbitrary indentation)

Carl J. Van Arsdall cvanarsdall at mvista.com
Wed May 17 21:26:25 CEST 2006


Dave Hansen wrote:
> On Wed, 17 May 2006 12:02:46 -0700 in comp.lang.python, "Carl J. Van
> Arsdall" <cvanarsdall at mvista.com> wrote:
>
>   
>> Andy Sy wrote:
>>     
>>> Carl J. Van Arsdall wrote:
>>>
>>>   
>>>       
>>>>> Next major objection then, how can one practically use 'tabs as
>>>>> semantic indentation' without screwing up formatting of code like
>>>>> the below??
>>>>>
>>>>>
>>>>>   def sqlcall():
>>>>>       cursor.execute('select id, item, amount, field4, field5, field6'+
>>>>>                      'from table1 where amount>100')
>>>>>
>>>>>   
>>>>>       
>>>>>           
>>>> Why couldn't you tab your third line over as close as possible to the 
>>>> start of the quote then use a couple spaces?  Then the tabs would work 
>>>> just fine and you could still have your pretty line.
>>>>     
>>>>         
>>> This will break if someone tries to view my code using different
>>> tab settings from the one I'm using
>>>   
>>>       
>> Uh, no it won't.  It should be read in as "one tab and two spaces" 
>> regardless of the tabstop setting.
>>     
>
> Think about it a little harder.  What does that "one tab" mean?
>
> Assume the code was written by someone using 4-space tabs.  To them,
> the code is:
>
>    def sqlcall():
>    --->cursor.execute('select id, item, amount, field4, <etc>
>    --->--->--->--->...'from table1 where amount>100')
>
> (where -------> represents an 4-space tab and . represents a space)
>
> Which looks fine.  But if I then load the code into my editor with
> 3-space tabs, it looks like:
>
>    def sqlcall():
>    -->cursor.execute('select id, item, amount, field4, <etc>
>    -->-->-->-->...'from table1 where amount>100')
>
> Then my colleage loads it into his editor with 8-space tabs, and it
> looks like (assuming I didn't change it to make it look reasonable):
>
>    def sqlcall():
>    ------->cursor.execute('select id, item, amount, field4, <etc>
>    ------->------->------->------->...'from table1 where amount>100')
>
>   
Ah, good point.  I was referring to it "breaking code".  It may look 
different (which I know invalidates my original point), but it certainly 
doesn't break code. 
I don't really use multiline strings in my code, but I find when working 
with other people I prefer the tab method.  For nothing else other than 
"my indent is 2 whereas my coworker's is 4" and the use of tabs allows 
us to throw things around much more easily without either of us having 
to compromise on personal preference.

.c

-- 

Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list