Coding standards / spaces vs tabs

Patrick Goetz pgoetz at mail.utexas.edu
Thu Oct 21 16:54:23 EDT 2010


On 10/21/2010 7:10 AM, Bron Gondwana wrote:
>>   set tabstop=3
>>   set expandtab
>
> 3?  Why three?
>

Einstein said "make everything as simple as possible, but not too 
simple".  I think a similar principle applies to indentation:  indent as 
little as possible, but not too little.

When I first started coding again 10 years ago because both the 
programmers I was working with abruptly quit for personal reasons, 
leaving me (and the client) in the lurch, I inherited a bunch of code 
where tab was used exclusively to indent.  In my opinion, tab = 8 
characters indentation is ridiculously unreadable. With just 3 or 4 
nested blocks your lines start halfway across the page, increasing line 
breaks.  When I discovered tabstop and expandtab in vim, I realized that 
I could make the indentation anything I damn well pleased and it would 
automatically be invoked in any file I edited. And since I was the only 
one working on the code at this point, my opinion was the only one that 
mattered.  After playing around a bit, glancing at a bunch of code to 
make sure nested blocks "jumped out" visually, etc., I determined that 
-- at least for me -- 3 spaces was the optimal number; 2 wasn't enough, 
4 excessive.

Re: using 8 space tabs.  This is the point where someone says "what are 
you talking about? Everyone has 24" 1900x1200 monitors these days; you 
can have a terminal which is 300 characters wide!"  Yes, and I can also 
go blind staring at it 8 hours a day -- I'll pass.

Re: using tabs for indentation at all:  especially given the somewhat 
disturbing growing ubiquity of python, getting in the habit of using 
tabs for indentation is like giving a box of matches and a stick of 
dynamite to your pet monkey.  It seems innocuous enough, but sooner or 
later a tragedy will occur.  Mixing tabs and spaces;especially given 
that the width of tabs is user-definable?  Add to the preceding showing 
the monkey how to light the matches and throw in a couple of liters of 
gasoline.  And yes, I'm aware that Makefiles require tabs; this is just 
one more indication that make is obsolete and needs to be rewritten from 
scratch using modern programming paradigms.

I know talking about indentation is like starting a "vi vs. emacs -- 
which is better?" discussion, but you asked.


-- 
Patrick Goetz


More information about the Cyrus-devel mailing list