Tabs vs Spaces
Recently StackOverflow released an article about how developers that use spaces make more money than developers who use tabs. They found this to be true even when taking into account factors such as years of experience, language, and country. Another article took an even deeper look at the data, and while it also pointed out some additional correlated factors (open source projects and version control), it also couldn’t fully explain the difference.
Obviously, nobody is saying that switching to tabs tomorrow will guarantee you a raise at your next performance review. There are a million other more important things that affect the quality of a code project. I believe we can safely declare that this is correlation, not causation. However, it’s such a large difference that it’s hard to ignore. There must be some underlying reason for this delta.
Anytime the topic of coding style appears, developers will rush to support their preferred method, often with religious-like zeal. Just peruse the hackernews post about the aforementioned StackOverflow article and you’ll find a great deal of animated discussion covering the advantages and disadvantages of both methods. What I find more interesting is not the actual pros and cons, but the motivation behind them.
Let’s google “tabs vs spaces” and select the first result, conveniently another StackExchange question. It generally boils down to two major arguments.
- Tabs are better because they are variable, allowing developers to personalize their tab width
- Spaces are better because they appear consistent across all editors, increasing readability
Both have advantages and it’s entirely personal preference which advantage you place greater value on. So let’s ignore that and instead focus on the reasoning behind the argument. Tab users want to be able to customize how their code looks. They prefer some specific width and want their editor to use that. Space users are concerned about the code looking inconsistent. Tabs can create readability problems due to code looking misaligned across different editors with different tab widths.
There is a fundamental difference in the motivation behind these two statements. One is arguing about personal preference, while the other is arguing about code readability. One generally only benefits yourself, while the other is concerned about the entire team. Simply put, tabs vs spaces is a debate over whether developers should have to surrender their personal preference for the benefit of the team.
As a software developer, you will often be forced to do things you disagree with. You have to adhere to coding styles that are different than what you are used to, work in languages you hate, and move forward with an idea you think is worse than your own. The ability to accept something you disagree with is a valuable skill when working with a team. Flexibility and open mindedness make you easier to work with and also benefits the team overall. This translates to better engineers who get paid more.
So the next time you have to make a decision that impacts your entire team, don’t just go with what you like the most. Take a moment to consider what is best for everyone involved, even if the decision is something as trivial as tabs vs spaces.
There is typically another argument for tabs that states that they take less bytes to represent, resulting in a smaller file size and potentially faster performance. I think technology is past the point where we need to be concerned about saving a few bytes here and there in our source code, especially with tools that do code obfuscation/minification.