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

Andy Sy andy at neotitans.com
Wed May 17 14:29:56 EDT 2006


Ed Singleton wrote:

> On 5/15/06, Brian Quinlan <brian at sweetapp.com> wrote:
>> The problem with tabs is that people use tabs for alignment e.g.
>>
>> def foo():
>>    ->query = """SELECT *
>>    ->  ->  ->   FROM sometable
>>    ->  ->  ->   WHERE condition"""
>>
>> Now I change my editor to use 8-space tabs and the code is all messed
>> up. Of course, a very disciplined group of people could be trained to
>> never use tabs except to align with the current block level but, in
>> practice, that doesn't work. Therefore tabs are bad.
> 
> def foo():
>    ->query = """SELECT *
>    -> .......FROM sometable
>    -> .......WHERE condition"""
> 
> That would solve it.  Tabs for indentation, spaces for spacing.
> 
> Ed

Ok, this is a somewhat workable solution.

Cons:

1) You have to be more conscientious regarding how many tabs
   you use at the beginning of a line.  If your text editor
   does not display tabs explicitly (SciTE can), it can be
   a *REAL* hassle.

2) Because you have to use all pure spaces after the proper
   # of tabs, you will often end up having to type a lot
   of them compared to if your tab key generated pure spaces.


Pro:

1) Happily, you do get your 'semantic indentation' so people can
   dynamically change the indentation-size they want to view your
   code with.



You do need everyone to understand 1 thing: NEVER use tab characters
(and consequently the tab key) for anything EXCEPT semantic indentation.


Big question though: is the above guaranteed to work nicely in all
situations in python?


Also, in free-format languages like C, Java, C#, the temptation to mix
semantic and arbitrary indentation might be just too great for sloppy
programmers.



If anyone wants to use tabs, I think the above is the ONLY right way
to use them and it also happily eliminates any arguments over how
many spaces you should use for your tab setting.


If ALL tab users followed this convention, I will happily consider
myself agnostic... ;-)



Now, on to the next holy war... date formats....


ANY OTHER FORMAT BESIDES ISO YYYYMMDD (but it's ok to put dashes
in between or use word MMM instead of numerical MM) IS *EVIL* AND
*MISGUIDED*!


-- 
It's called DOM+XHR and it's *NOT* a detergent!




More information about the Python-list mailing list