Yes, that age old debate. This post in no way attempts to elicit a flamewar of programming fundamentalism.
I recently started a project to create a docking library for Oracle's new RIA platform, JavaFX. After years of banging my head against the wall with the default Eclipse formatter, I realized there had to be a better way. A colleague of mine, Josh Ventura, introduced me to the Google style guide and its elegant formatting of what is an otherwise Salvador Dali of semantics (Java).
After some research of this age old debate I really started to settle on spaces; having configured Notepad++ and Eclipse to use an 80 character width line limit and 2 spaces. After more research and just stewing on the idea, I believe my friend DaSpirit's earlier influence has begun to drive me in the opposite direction, and allow me to explain why.
Most of you who would read this are probably aware of the existing advantages and disadvantages of each. For example:
* Spaces are better with large projects and source revision control and are consistent with every editor (including the web)
* Spaces make it easier to detect formatting errors
* Spaces are semantically correct for alignment
* Tabs have smaller file sizes and thus lead to the computer even consuming less energy
* Tabs are quicker to type (not true if you properly configure your editor, but still almost always true for backspacing)
* Tabs are semantically correct for block indentation
* Tabs are dynamic and represent the separation of view as in MVC (you can set your editor to how you want to perceive or "view" the tabs/indentation)
However, I am starting to see things a little differently. We are all most likely aware that tabs can solve a lot of the complaints against it by proper configuration of the code editor. A lot of editors like Qt or Notepad++ also allow you to display a symbol for the tab character making it both easier to visualize (imo) and easier to detect SCM (like git or mercurial) formatting inconsistencies from other contributors.
I also feel that using tabs makes it easier to port my code. For example, let's say I prefer 3 spaces, my employer prefers 2 spaces, and I have a second job or hobby that requires 4 spaces. Through the use of tabs I am able to write my code once and run a regular expression to give it to any employer or publish it in a variety of different ways. Because I feel that this addresses all outstanding concerns related to tabs, I am still conflicted on the subject because of what I feel is the only remaining disadvantage to tab indentation. To clarify, I believe a mixture of tabs and spaces is where I am heading for my own personal projects as in the following screenshot:
If you've ever tried to publish code through the internet using http://pastie.org/
or to a forum/blog site like 64Digits you will understand what I mean. Websites where formatting code is virtually integral to the function of the site, such as pastie.org or Stack Overflow, have always been a headache for me with tabs. From the complete absence of tab input to the ugly line wrapping, using tab indentation on webpages has been a huge nightmare. However, many sites do work around this and provide tab input support, it still does not address the issue of configuring the tab width to a reader's liking (as far as I am aware). I feel this is extremely necessary for people to read the code the way that they want, specifically other people reading my code in a way that makes them comfortable. I would say that it is almost integral to the web.
In a perfect world we probably wouldn't use either and all of our code might be written on a single line with no whitespace with the editor configured to generate different views based on some parsing or lexical context. I would be very happy in that world as everyone would get a different view of the code just like with model view controller, which we sort of get with tabs. I am really looking to see what others have to say about this and if you feel my opinions are justified. Perhaps there is some browser configuration that could solve my tab problems on the web, or there is some other advantage to spaces that I have not considered. Either way I would like to know what others think and if anybody may have a solution to my dilemma. Comments welcome.