Religion, politics and coding indentation style: the three great debates

Forget abortion and gun control; if you want to get programmers arguing at your next party, bring up tabs versus spaces when indenting code

A couple of weeks ago I wrote about some of things that I found most frustrating about being a programmer, back when I was a programmer. One of those things was the size of indentation in code. Somewhere along the line, I was trained (or just started on my own; can’t recall) to set the tab key in my editor to four spaces. That’s what I stuck with for years and got used to seeing. When I read someone else’s code that used two or eight character tabs, I found it annoying. It wasn’t a dogmatic thing for me; I didn’t care that much. Four spaces was just my personal preference.

supreme_court-600x450_0.jpgImage credit: REUTERS/Jason Reed
Do we need the Supreme Court to weigh in on this?

In the programmer community, though, discussions of coding style such as the size of code indentation can quickly turn into a holy war. Some people tend to have very strong opinions on it. It flared up a little bit in the comments some people made on the article; but there are plenty of lengthier (and more heated) discussions on it elsewhere on the web.

Spacing and indentation in code are important, of course, to help organize things and to make it readable. Code is often read by different people, and the preferences (or training) can differ from programmer to programmer. Also, depending on what type of indentation is used, the same code opened on different operating systems can look different (and less legible). It’s not as trivial an issue as it may sound to the non-programmer, and it’s also an argument that will likely never end.

Among the choices are things like: hard tabs (that is, the tab key inserting the actual ASCII tab character) versus soft tabs (replacing the tab character with multiple spaces), how many columns wide shoud the indentation be, how to deal with indentation or spacing within a line (some prefer hard tabs at the start of lines, but soft tabs in the middle of lines), etc. There are pros and cons to each choice; hard tabs use less space in the file, but soft tabs will lead to consistent spacing across operating systems. Two spaces were better than four or eight when trying fit things on 80 character lines. On and on (and on) it can go.

1 2 Page
Insider: How the basic tech behind the Internet works
Join the discussion
Be the first to comment on this article. Our Commenting Policies