ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

Tabs vs. Spaces is Not a Religious Issue

Updated on June 20, 2016

Everyone seems to claim that the tabs vs. spaces debate is a holy war among programmers. But there’s nothing religious about it: tabs are logically better.

I seem to be one of the few that consider this to be more than a matter of opinion, so I’m going to provide a number of benefits of using tabs, followed by the best rebuttal I’ve been able to find by the space users. And then, I’m going to explain why that rebuttal is flawed.

If you think I’ve made a mistake or neglected to point something out, let me know. I’ve yet to find a good reason for indenting with spaces, but no one is perfect. Let’s get started.

Tabs Let YOU Decide How Wide Your Indents Are

Any decent code editor will have settings that allow you to configure how much space a tab character will use. Maybe you like it to take up 2 spaces, or 4, or maybe even 8. It doesn’t matter, the choice is yours.

If you indent with space characters, you are dictating how everyone else will have to work with your code. If I like indenting with 4 spaces, but you used 2, then too bad. I can either refactor all the whitespace to use 4 spaces and risk angering the original author when I commit my changes, or I can simply deal with it, quietly complaining to myself.

Best space user rebuttal: When I use spaces, everyone sees my code the same way. No matter where my code is used, it will look the same.

Reality: Nazi. That’s the only word I can think to describe this position. Why not require everyone to use the same syntax-highlighting color scheme and the same font settings, too.

Standardization is good, but only when it affects the quality of the code. If my HTML tags are displayed in blue text and yours in pink, that doesn’t affect code quality. Neither does the width of my indentation — let me decide what is appropriate.

Collaboration with spaces is difficult. Many (bad) programmers will continue to indent with their preferred number of spaces regardless of the document they’re editing. This type of thing is never an issue when using tabs.

Tabs Take Up Less Space

A tab character and a space character both use the same amount of disk space. However, unless you only indent with one space character, your file sizes will be larger when indenting with spaces.

Best space user rebuttal: This is not an issue because production files can be minified/compressed.

Reality: News flash: not everyone compresses files like they should. This also does not address the original source files, which will always be larger than tab-indented files.

Imagine a project with hundreds of thousands of third-party file dependencies that use spaces for indentation — each file, on average, about 10-20% larger than the tab-indented equivalent. Now, imagine dozens of projects on your computer with this problem. Yikes. Don’t you want that disk space back?

Tabs Require One Keystroke

This is self-explanatory. One indent level means pressing the tab key one time.

Best space user rebuttal: All major code editors can be configured to automatically replace the tab key with a set number of spaces.

Reality: What happens when you need to insert an actual tab character? Admittedly, it’s probably a rare occurrence that you need to insert a tab, but what do you do if the situation comes up?

But that’s not the big problem. What happens when you have to use a computer that doesn’t have your favorite code editor installed? What if you’re forced into using Notepad on your client’s machine? Now, your rebuttal is moot — you must hit that space bar multiple times every time you need to indent.

It also seems a little silly to me that advocates of spaces press the tab key and expect it to render space characters instead. Why must you fight the tab character?

Moving Your Cursor Through Tabs Is Easier

You can easily move through tab indents with your keyboard arrow keys. You can even highlight and select indentations.

Best space user rebuttal: There are other ways of moving through code than just the arrow keys. For example, ctrl+left arrow, home/end keys, etc.

Reality: That’s a pathetic excuse. It’s like saying that a bicycle with a missing pedal is fine, because you can kick the ground with your foot on that side instead. It’s an inefficient solution.

I don’t care what special accommodations your code editor has for navigating through whitespace. Almost every editor uses arrow keys for moving the cursor, and even if you’ve memorized every possible keyboard shortcut in your editor, you will probably still use the arrows from time to time, and you’ll likely be forced into working in a different editor now and then, too.

This excuse also doesn’t address how you can highlight/select a specific number of indentations. If I want to select from the second indentation of a line until the end of a block of code, I can easily do it when tabs are used (mouse or keyboard). With spaces, you have to eyeball it, and you often end up picking up or leaving off a space character. Which leads us to…

You Can't Leave Off Part of a Tab Character

When you indent with spaces, it’s easy to accidentally add or delete a space and not notice it. It’s difficult not to notice an extra or missing tab character.

Best space user rebuttal: An extra space or two never killed anybody.

Reality: No, seriously, I haven’t heard any good rebuttals to this problem. Extra spaces can and do cause problems. If I’m looking at a line of code, and a couple extra spaces lead me to believe that I’m still inside of a loop or conditional statement, then that’s a problem. Don’t try to downplay it.

It’s a rare occurrence when I see a file with more than a few hundred lines of code where there aren’t some stray spaces in the indentation. If you don’t think that you could ever make this mistake, prove it to yourself — look through some of your space-indented files, and convert the spaces to tab characters (most code editors can do this easily). Make sure you have visible whitespace markers turned on, and check out all those extra dots that surround your tab characters. Space people are messy.

What space-indented code with visible whitespace markers looks like to me.
What space-indented code with visible whitespace markers looks like to me.

Spaces Are Better for Aligning Code

Wait a minute. That’s an advantage for spaces, right? Wrong. Whether you indent with spaces or tabs, alignment should always use spaces. This is a red herring that space apologists use to introduce confusion into the argument.

Here is how code is indented and aligned using spaces:

function myFunc () {
••••var foo = [
••••••••••••••item 2,

Here is how code is indented with tabs and aligned with spaces:

function myFunc () {
--->var foo = [

In fact, using tabs in this case makes it easier to differentiate between the indentation and the alignment. Advantage tabs!

If you indent with spaces, you probably never even thought about indentation vs. alignment. If so, congratulations, now you know such a thing exists.

Note: There’s no rebuttal to this because the original argument is wrong to begin with.

Do Spaces Have ANY Advantages?

OK, so you’ve heard a lot about the advantages of tabs; surely, spaces have some advantages too? Well, let’s talk about them.

…[crickets chirping]. I honestly could not find a single advantage to spaces. Everything I found — after considerable digging, mind you — was simply an excuse trying to downplay an advantage that tabs bring, or a flat-out misrepresentation or misunderstanding, like in the indentation vs. alignment example earlier.

If there is an advantage to spaces, I’d love to hear it. I honestly don’t think that it could outweigh all the advantages of tabs that I’ve outlined above, but it might lend some clarity regarding why they are so popular. Maybe it is a religious issue for the space people, but it’s not for tab users.

Use tabs for indentation, and stop listening to all those space nazis that can’t even decide on how many spaces should be the standard.


    0 of 8192 characters used
    Post Comment

    • Chatty Chat profile image

      Cindy 14 months ago from Planet Earth

      Tabs are always better especially when I'm making outlines for class.

    • profile image

      TwinEnigma 14 months ago

      I agree. When working on existing projects, it's best to conform to the standards that were chosen. I just wish that tabs were the common standard.

    • RonElFran profile image

      Ronald E. Franklin 14 months ago from Mechanicsburg, PA

      Interesting. I never realized there was a tabs vs. spaces debate. I'm a 2-space guy. But when I encounter code using a different indentation factor, I simply adjust. As you say, it's not a religious issue.