Over the years, there has been a jihad over whether to use spaces or tabs when writing code. It's a holy war we fought ourselves at the ZURB offices, until we came up with a truce in 2009, saying spaces were for back-end development while tabs were for front-end development. But recently the war was reignited and we found ourselves fighting it out again over whether to use spaces or tabs.
The problem is that a lot of hackers are insanely passionate about the amount of screen columns that the code indents, as pointed out in this excellent blog post. Some prefer it to be two column while others like it to be four columns. Then there are the folks who prefer more complicated and context-dependent rules.
At ZURB, we had hackers on both sides of this battlefield — some for spaces and others for tabs. Spaces, however, slowly took over. Code kept getting written with spaces, and the backend folks mostly ignored the truce. However, the war heated up again when Tanya used tabs for some front-end code, which piqued the ire of our contractor, who fired back and reformated the code manually with spaces.
So we decided to put an end to the war once and for all, and make everything consistent all around with spaces, but not before delving deeper into the problem.
The Problem with Tabs
Because most arguments on the subject were esoteric, we asked our contractor why the tabs were problematic and why spaces are better.
Tabs wreak havoc, he told us, because they're so wildly different on different editors. On some editors, tabs show up as two spaces, on others it shows up as four spaces and on a few editors tabs will actually show up as an entirely different character, he said. With a multitude of editors and hackers, these differences can cause some pretty whack alignments.
It gets even worse if you mix spaces and tabs while coding. Your code will only look good on your editor, but could look like crap on another editor. Here's the example our contractor gave us:
Say we hacked this using two spaces for the div open and end tags, then used two tabs for the span tags, it could end up looking like this in an editor that interprets tabs as four spaces:
So, yeah, mixing tabs and spaces is bad, way bad. Don't do it.
Spaces for the Win
As you can see, there's no real benefit to using tabs over spaces because of the inconsistency of tabs. Around ZURB, spaces won because they're more consistent with the communities we work with and admire, such as Rails and SASS. However, whether you use spaces or tabs, the key is to be consistent so you don't end up with some funky code that you'll have to go back and reformat.