Fleeting thoughts

The tyranny of spaces

by Johannes Martinsson

My thoughts about how to indent code. Use tabs for indentation and spaces for alignment. This is commonly referred to as smart tabs.

There are a couple of code bases at work that are aligned using spaces. TWO SPACES. I cannot even remember how many times I’ve had to hold up a sheet of paper to my screen in order to visualize the indentation level. It is horrible.

Why use tabs for indentation?

I think the biggest advantage of using tabs for indentation is that each individual is free to define their own indentation width. It allows each developer to use whatever indentation with they are most comfortable with. Some like two columns, I like a saner, more readable, eight columns.

If you need to align something, then indent to the same level as the thing you want to align with and align using spaces.

This approach is commonly referred to as smart tabs.

I like the idea that one tab character equates to one level of indentation. When I see three tabs I instantly know that the code is indented three levels. (But then again, I also liked the idea of XHTML.)

Why use spaces for indentation?

It looks the same in all editors, for everyone.

This baffles my mind. How is this an argument in favor of the proposition?

What is the reason the code must look the same for everyone? Should we all be using the same font size also? Color themes?

It is too difficult for programmers to indent code using tabs.

I find this akin to saying that formula 1 cars should have an automatic gear box because it is too difficult to shift gears manually.

If you write code for a living you owe it to yourself to at least learn your editor and be able to tell the difference between spaces and tabs.

Why not just mix spaces and tabs?

No. This is the path to insanity.

How important is indentation?

It is obviously not the biggest issue in the world. But if you are in a position of choosing indentation method, go with tabs that will enable your peers to select the indentation width they are most comfortable with. Thanks.

TABS ARE MORE INCLUSIVE! YOU PC BRO!?