Friday, June 13, 2008

Why is Tabs vs Spaces a "Holy War"?

Ok so this has always bugged me: Why is Tabs vs Spaces a "Holy War"? I don't understand it.

My personality is such that I can normally see both sides of an argument. So, when I look at this issue and I don't see the other side I wonder if maybe there is just a miscommunication rather than major differences.

So lets set out some base assumptions:

1. Regardless of whether you use tabs or spaces to indent, use spaces to align so that alignment doesn't change with tab width. If you believe that you should use tabs to align, then you are a fool or lazy.

2. If you are not using a fixed-width font, then you are a complete moron or a newbie. (some people argue tabs for alignment because it works better for variable width font)

So, the vast majority of us can agree to use spaces to align and for godsake use a fixed width font.

Ok now that that is taken care of, on to the important part: Indentation. Everyone has different preferences as to what is more readable as far as indent width. If spaces are used the only way to adjust the indentation to a comfortable width for you personally is to modify the document. This is not acceptable for anyone sharing code: white space diffs, change battles, etc.

If you use tabs, you can set your editor to any indent size...

Where is the argument?

EDIT (2009.9.15):
So I have finally uncovered a somewhat valid argument against tabs:

Comments that are aligned across multiple indentation levels.

When using tabs they can become mis-aligned if spaces are used to align them, and then the document is opened with a different tab width.

So does the whole argument boil down to that? This never comes up in tabs/spaces holy-war debates (that I've seen). But now it seems to me that the crux of the whole thing is the valuation between the {benefit of parameterized indentation level} vs the {cost of lost formatting in cross indentation level comments.}

Now if only we could do this for Palestine and Israel...

EDIT (2009.10.22):
I found another (minor)advantage of tabs recently now that I've been using spaces (for compliance) at work: Keeping commented-out code aligned.

    int x;
//  int y;   // after commenting out with tabs
//    int z; // after commenting out with spaces