Timothy Wittig

Home

Tabs vs. Spaces

Published Jan 07, 2022

My goal in writing this is to have something I can point people to whenever they ask me my thoughts on tabs vs. spaces. Which, sure, has never happened… but maybe someday!

It’s hard to argue the conventional wisdom around tabs vs. spaces—accept whatever is established, set your IDE to insert that, and focus on coding—so I won’t. There’s a reason it’s conventional wisdom! The actual difference in developer experience between the two options is negligible when compared to the effort expended in converting a code base from one to another. And that’s to say nothing of political capital you’ll burn doing it.

But that’s a boring answer. What if I’m starting a project from scratch and I’m forced to make a decision?

Tabs.

Hear me out, space cadets. My reasoning is ✨personal readability✨. Whenever I work in a set of files for more than day or two, my brain starts navigating based on the shape of the code. My mind subconsciously captures the shape of the code blocks I’m working with, leveraging the Gestalt principle of proximity to quickly locate them again. I first realized I was doing this after I joined a team with a programmer that would convert everything to use two space indents. My brain began to struggle, unconsciously reaching for something that wasn’t there every time I switched files. It took this happening a few times to identify that my mind was trying and failing to identify shapes in the code.

For example, my mind will take the following snippet of code and internalize the distinct shapes. I can quickly scroll around and, without really thinking about it, find that deeply nested set of three lines.

But if someone came in and flattened the file down with indents of only two spaces, the shapes disappear. My subconscious is no longer able to identify distinct shapes and instead sees one continuous and amorphous shape.

Now, I don’t begrudge someone else finding two space indents more readable. In fact, that’s what my co-worker claimed when I asked them why they insisted on two spaces—they liked everything to fit on their tiny monitor (which I do begrudge). But that’s exactly why I prefer tabs over spaces—you’re free to customize indents to your personal readability preference. Just like your IDE theme or your font size isn’t encoded in the source files, I don’t believe indent size should be either. So tabs. Unless of course the code base is already using spaces, then I choose peace.