I switched from tabs to spaces and haven't looked back
Heads up! This post was written in 2014, so it may contain information that is no longer accurate. I keep posts like this around for historical purposes and to prevent link rot, so please keep this in mind as you're reading.
Last week I started using spaces to indent code instead of tabs. It's something I swore I would never do, but I'm glad I finally did.
Why I always preferred tabs #
Tabs are sensible. They were made to indent things, and code needs to be indented, so it was a good relationship. Probably the two most well-known arguments for using tabs are:
- Tabs reduce file size (although this is negligible and I would never argue based on this point)
- Tabs allow each developers to choose their own indentation level without changing the actual file (this was always my biggest reason, and I think most pro-tab people agree)
Of course, there are more arguments (and plenty for spaces too), but here's why I've switched.
Soft tabs make it seamless #
Most editors support soft tabs, which means you can still use the tab key to indent/outdent and never even notice the difference. Sublime Text 3 is my editor of choice, and it does a superb job of this. It also has some built in tools for converting between tabs and spaces, reindenting, etc. That made it a lot easier for me to switch and update existing files.
And when I "seamless", it really has been. I've been a stubborn tab guy for like a decade. My workflow hasn't changed, the keystrokes I use are identical, the code looks the same, and the universe hasn't imploded yet. That's a good sign for my first week.
Indentation is always consistent #
One thing that always drove me crazy about using tabs was the way HTML looks when you view the source. Most browsers render tabs the equivalent of eight or more spaces long. Why they do this, I'll never know. But I do know that I don't have to worry about that anymore. +1 for spaces.
There are other places where indentation varies. In fact, the biggest pro-tab argument ends up being an argument against tabs when you don't have control over how deep indentations go.
Everyone uses them now #
Bootstrap is massively popular, and for a good reason. It cuts out the fat and gives you something tried and tested to develop with. It's a solid framework, and the conventions they use make really good sense.
So when Mark Otto (probably best known as @mdo) released his code guide, it of course suggested we use soft tabs (spaces). Another hard blow to tab lovers.
Here's the thing—I normally wouldn't sway and I'd keep doing my own thing code rogue style, but what's the point? If you've ever been on GitHub, it's clear that most developers are using spaces now. As tab lovers, we're pissing into the wind.
So last week I decided to try out spaces while building Particle. I converted all files from tabs to spaces in less than five minutes and just went with it. And I actually liked it. A lot.
My code fits in now #
It's refreshing to know that my code fits in better with other people's code now. I don't have to worry about what other developers and projects are using, because most of them are using spaces anyway. I also don't have to worry about contributing to a project and accidentally sending commits with a mix of tabs and spaces.
Call it peer pressure. Call it giving up on my beloved tabs. I really don't care anymore. At the end of the day, I looked past an old habit and, for whatever reason, I decided to try something new.
I switched from tabs to spaces and haven't looked back.