Tabs or spaces?

A story of friendship and betrayal.

I was a happy guy. Using spaces for indentation and enjoying life. It was Python that made me set tab expansion option for the first time. Before that I didn't know or even care, but the interpreter had problems parsing my tab-indented files. Four looked perfect and seemed standard. It worked for almost every language or specification I've coded in. No questions were asked.

It seemed to me as if the people who use tabs hadn't known about the tab expansion option available virtually anywhere. Why would you use tabs if you can insert any amount of spaces with the same keystroke? And it's better for Python, too! That's a no brainer, right?

Many years have passed. I started working as a Drupal backend developer. It's coding guide enforces 2 spaces per indentation. For the first time 4 wasn't good enough! But all my personal projects were built with 4 which looks completely different. You can't afford changing space indentation size as you'd like just to make it consistent across your projects, it basically messes git history with unnecessary change in almost every line. So all that's left is to live with it.

But what if we had a magical character that could stretch or shrink to any size the reader wants? A character that could be inserted with a simple keystroke just like space indentation? Just like a real tab?

That's pretty much why I'm in team tab now whenever I can. If my indentation width preferences ever change there will be no change to my gitted projects. If I ever start working on a system that enforces 8 spaces on you I can just change my tab width at home to avoid confusion.

Downsides? None severe. Yaml forces spaces, Makefile forces tabs so you'll have to switch between them from time to time. If you want spaces to publish code somewhere for reading, replacing tabs with spaces is much easier than the other way around (unless you know the number of spaces) - simple substitution is enough, like s/\t/ /. Alignment must be done with spaces anyway so it's not an argument against tabs.

Smaller files are a bonus, although you'll likely not notice - 1000 lines of code indented once with 4 spaces will produce 3 kilobytes larger filesize than with tabs, assuming 1 byte encoding. Most code files nowadays contain classes which make you indent all the lines at least once, then every method is at least one extra level. All in all, you might save around 5kB every 1000 SLOC which is nothing, unless we're talking HTML.

Spaces are like two people in a horse costume - they work together trying to trick people into thinking they're something they really aren't.

Comments? Suggestions? Send to
Published on 2019-08-02