Use Tabs, Not Spaces!
I am now working out of an office and with other developers on a regular basis. With this comes the debate amongst developers over syntax highlighting and tabs vs. spaces. I usually do not get involved in these “geek wars”, but lately I have learned just how much tabs make sense. I have always been a tab fan, but here are the reasons I see tabs being the better of the two.
- Each developer can set tab width to their own preference in their IDE. So once user can have tabs shown as long, while the other has them shown as short.
- Using the arrow keys is much easier with tabs. It’s one key stroke as appose to 4 or 8.
- Whitespace leads for less mess during an update.If any amount of whitespace is changed, it throws off source code control systems.
- Tabs are less on disk that spaces, which is important for load time in web applications.
There are a lot of plug-ins and IDE’s that put some solutions into play for some of these issues. I would love to here others experience and view points on this, and what you development does to solve the never ending battle.
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
Comments
While I absolutely agree for editing C-like languages, I don’t miss tabs when I’m editing Lisp in slime/emacs. When I press tab anywhere on the line, slime indents my code to the ‘right’ level, using spaces. It indents stuff inside macro calls differently to stuff inside function calls, so I can tell which is which when I scan through.
I find that with ’superior’ editing tools, I don’t need to press the arrow key so much. Or maybe it’s because this laptop doesn’t have proper home/end keys..
You are right in theory, wrong in practice. Spaces have proved to be superior in real world settings. No tabs any more.
Are real-world settings where you look out from your office window instead of somewhere more ‘realistic’?
Try some technical arguments instead of real-world tripe.
I guess you don’t listen to the Java Posse podcast, one of the members will go into great lengths on why tabs are evil. Personally I think they might be right. Perhaps the only valid advantage for tabs are markup languages like html/xml but I’m not sure its that necessary.
> Each developer can set tab width to their own preference in their IDE. So once user can have tabs shown as long, while the other has them shown as short.
This is good in theory, but in practice, I have found that everyone has to set their tab widths to the same (or very close) number of spaces in order for the code to look right. The other issue here is that most engineers seem to prefer 2 or 4 spaces per tab (I like 4, but I’m ok with 2); the upshot being that it is usually fairly easy to compromise on a tab width thus eliminating the need to use tab characters in order for everyone to be “happy”.
> Using the arrow keys is much easier with tabs. It’s one key stroke as appose to 4 or 8.
This one is kind of silly. Who moves along one character at a time over large chunks of whitespace? If you don’t know your editor well enough to use meta-arrow to skip over arbitrary whitespace, you have bigger issues than tabs vs. spaces. Of course you could use the same logic to make the argument that all the code should be one one line. No need wasting keystrokes on those vertical arrows. ![]()
>Whitespace leads for less mess during an update. If any amount of whitespace is changed, it throws off source code control systems.
Any decent source control system handles this issue with ease. However, if yours doesn’t then switching to tabs won’t really solve the problem (stray tabs will confuse SCM just as easily as stray spaces).
>Tabs are less on disk that spaces, which is important for load time in web applications.
This is absolutely no problem in any context except for (as you mention) markup that goes over a slow network. However, if your modules are so large (and heavily indented) that changing spaces to tabs has any measurable affect on load time, then it’s time to refactor not screw around with whitespace. The same argument has be made, BTW, for using single character variable and tag names instead of byte-wasting descriptive names. I’d argue that if your code is properly modular, you won’t see a massive speed gain there either.
I’ve been debating this tab vs. spaces thing since the days when BRIEF was my editor of choice and no matter how you spin it, spaces come out on top.
Hey, I’ve argued extensively about this on my blog. And almost every space for indentation proponent agrees with my argument. But guess what, they still use spaces for indentation. As a text editor developer, I can only cringe.
http://mystilleef.blogspot.com/2006/11/indentation-with-spaces-considered.html
I’ve never, in my 12 years in the business, worked at a place that had time for this nonsense. Who cares what you guys use? Seriously. You guys should argue over things that will make the company money, not things that can be cleaned up with a code beautifier.
Hugh, you seem to be under the impression that code is only for making money. Some of us actually enjoy writing and thinking about code, and tabs versus spaces, indentation versus braces, etc., are unfortunately rather limited arguments, but they are at least signs of an active mind.
I’d rather work with someone who has a strong, rational opinion about tabs versus spaces, even if they disagree with me, than someone who calls the discussion nonsense. The former is more likely to be interesting.
Ricky Clarkson:
Writing code does pay the bills for me, yes. However, I do code on the side for fun and just to figure things out and try new things.
I do not call the discussion non-sense, that’s why I asked for feedback on the matter from others and what their development does to handle this ongoing battle. The main reason I wrote about it is because at my work it has been a fairly large issue of late.
Hugh Jass:
I do not blog for a company, this post is in no way related to the company I work for… other than the fact that the idea of reaching out to my readers about the issue - soley for a solution, came from my every day work.
Yes you can use a code beautifier, but I have found it commits a lot of changes when checking it back in to source code control, even the intelligent ones.
Ricky Clarkson:
This is not a real world trip, I was stating my opinion on the matter, but was reaching out to others for ideas and “real world” solutions. Because in the “real world” I code for a living. There is no reason to be nasty about it.
Wow, you picked a religious topic. You asked so here goes,
>Each developer can set tab width to their own preference in their IDE.
That’s true for leading tabs for indention but falls down if developers use tabs for alignment later in the line. Spaces will hold their alignment across IDE settings.
>Using the arrow keys is much easier with tabs.
I guess I’m not a big arrow user. Most decent editor will process the tab key and insert the correct number of spaces.
>Whitespace leads for less mess during an update.
Most diff tools have options to ignore space changes. I use free Winmerge from sourceforge, great product.
>Tabs are less on disk that spaces, which is important for load time in web applications.
This one is pretty weak. There are so many better ways to deal with that issue (reformaters, compression, etc. as part of your deployment process). You could also recommend one character javascript variables and no comments too. Better to strip them at deployment time or serve compressed files if size is an issue for you.
In case you can tell, I’m a space guy
I used to be a four character tab guy until I started doing a lot of Python and found spaces easier to deal with, with proper tool configurations. Now I use spaces across languages.
-Rich
The arguments fit either way. Mostly I think it comes down to whether you like bashing your board with your thumbs or your pinky. At any rate, this thread is getting nasty and I think it’s time to set a few things straight.
1. The ability to argue about something silly like this is what shows you have a thorough mind. It’s a unique quirk of folks who write code. Try dating a programmer: you’ll learn to love ‘em for it.
2. If you don’t like one variant, change the code. Copy the slop into txt file and invest the ten minutes it takes to write a simple parser. It’s fun, and easy too! (n00b tip: look after \n characters.)
3. The space-on-disc argument has backing. Just because your code has other space issues doesn’t mean you should add one more, right? If you’re scoffing at an argument, you’ve forgotten how silly the conversation was to begin with. Have some fun already, ya stiff!
4. Some people stick to their guns, and their arrow-keys. Your favourite time-saving keystroke is not a measurement of anyone’s personal worth.
5. The real-world is irrelevant.
Ricky:
“Some of us actually enjoy writing and thinking about code, and tabs versus spaces, indentation versus braces, etc., are unfortunately rather limited arguments, but they are at least signs of an active mind.”
Fine. You keep your mind active by arguing over what amounts to the settings of a code beautifier. I’ll keep mine active by discussing things that matter, you know, actual code - not the presentation thereof.
Spaces == Invariance
Any editor, tool, debugger or processing utility you use will see the exact same code no matter where it comes out, web, scm, diff, editor etc. You write the code once and you don’t have to tweak every single tool you use to make it handle tabs the same. You’re not even guaranteed that all of your tools will give you the control over tabs that you need to make the code look right.
Tabs are the worst kind of varience.. Hidden varience! As a coder you must surely see the folly that leads down this path?
Invariance is a wonderful property in all kinds of software systems for a variety of reasons and any time you have an opportunity to ensure it you should ![]()
Any code editor I’ve ever seen allows you to expand tabs and work quickly and effortlessly. Meta movement is such a common idiom even simple text input like this form I’m entering on support it.
As to the web compression argument, I think you shouldn’t ruin your _source_ code to shave a few bytes per line you should feed your static javascript and html through an automated text folder and finally use something like mod_gzip for an even better effect. Save the code folding for the production publish however ![]()
Cheers, hope you see the light!
The comment about tabs causing variance is misled.
The original author said to only use tabs for indentation, not for lining up of code other than that. E.g.:
[tab]int x=5;
[tab]int y=6;
is fine, but obviously:
[tab]char x=5,
[tab][tab]y=6;
..will cause x and y not to line up with each other if the tab size is anything but 5. Therefore, most promoters of tabs will say to use them only to signify indentation, so that tabs only line up with other tabs. That will always give consistent code.
So you espousers of spaces, realise that we tab users don’t actually end up with code that is misaligned. It is only those who mix tabs with other characters who misalign code.
If you feel like you’re not good enough at stopping yourself from doing that, then maybe spaces are for you.
Whichever side you take, you should spend some effort debugging your indents.
Tab guys should look through your code at different tab sizes and make sure your formatting doesn’t fall apart with either tiny or huge tab sizes.
Space guys probably need a tab alert program added to their build script. So if a tab sneaks into their source code they get a error message telling them to fix it.
Sorry, the comment form is closed at this time.

























I definitely agree with you, I use tabs with 2 spaces in every editor.
If I see anything messy I just used the eclipse formatter to format the code.
Rest said its up to the developer to choose their own indenting format.