ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

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 = [
••••••••••••••item1,
••••••••••••••item 2,
••••];
}

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

function myFunc () {
--->var foo = [
--->••••••••••item1,
--->••••••••••item2
--->];
}

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.

working

This website uses cookies

As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://corp.maven.io/privacy-policy

Show Details
Necessary
HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
LoginThis is necessary to sign in to the HubPages Service.
Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
AkismetThis is used to detect comment spam. (Privacy Policy)
HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
Features
Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
MavenThis supports the Maven widget and search functionality. (Privacy Policy)
Marketing
Google AdSenseThis is an ad network. (Privacy Policy)
Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
Index ExchangeThis is an ad network. (Privacy Policy)
SovrnThis is an ad network. (Privacy Policy)
Facebook AdsThis is an ad network. (Privacy Policy)
Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
AppNexusThis is an ad network. (Privacy Policy)
OpenxThis is an ad network. (Privacy Policy)
Rubicon ProjectThis is an ad network. (Privacy Policy)
TripleLiftThis is an ad network. (Privacy Policy)
Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
Statistics
Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
ClickscoThis is a data management platform studying reader behavior (Privacy Policy)