If you follow me on twitter you’ll probably know I’m very opinionated and more than happy to discuss (some would say argue or troll) my opinions. I indent with spaces, Lea Verou indents with tabs. Lea has blogged about her reasons why she thinks that tabs are superior. I’m going to provide my opposing opinion and then tell you why neither of our opinions should really matter anyway.
Whitespace shouldn’t matter
There’s really no excuse not to be using at least basic build tools. There are so many great tools like SASS, LESS, Yui-Compressor, Google Closure Compiler, etc. Your first intention should be to write code that is easy to maintain, by both yourself and others. Then you can convert to a format that is better for machines. If you can’t use build tools the gzipped difference between spaces and tabs will be insignificant anyway.
Tabs can be personalised
The width of a tab character can be adjusted per editor. This may sound like a major advantage but the reality is that it means that you can’t use tabs for alignment. You have to mix tabs for indentation and spaces for alignment. If tabs are used for an alignment, personalisation throws alignment out. Needing to use a different strategy for indentation and alignment is a hack.
Tabs are easy to select
It’s true, tabs are easy to select. But you have to ask yourself, why would you need to? Assume for some reason you want to select all indents and double them or convert them to spaces. That would mean you’re probably just trying to force somebody else’s code to fit your preference. Maybe it’s time to give up on that personal preference.
There’s a better way
As I said, I’m very opinionated and not only do I have an opinion about why I prefer spaces over tabs, I have also historically had an opinion about how many spaces to use as well as a bunch of other formatting preferences. But I invalidated my own opinions and (grudgingly) gave up my personal preferences for the greater good. The greater good. (Film reference bonus points)
Everybody has different preferences but we all have to work together as part of teams and as part of larger communities. We all have egos that must be put aside for the common good. Whitespace is but one of many aspects of code formatting that we each have a preference for but in order to effectively collaborate, we need to ignore these preferences and follow a common standard.
I am but one cog in the Vend development machine. Battles over preferred formatting could seize this machine but instead we lubricate it with common standards. Nobody wastes their time trying to understand each others formatting or worse yet, reformatting code to their own preference.
You could try to create a “team standard” but there are several down sides to this approach. Firstly, there’s that ugly argument when you first try to create your standard. Then those who didn’t get their own way feel resentment towards those who did. When switching between work projects and external/personal projects you potentially have to switch between two different standards. Your standard probably won’t match that over any open source project that you want to contribute to. And if you hire somebody new, you need to teach them (or force upon them) your team’s unique way of doing things.
Instead, go and find industry standards that others are most likely to follow. We expect our browsers to follow standards and render the result of our code in a consistent and expectable way. We should hold ourselves to the same level and do our best to write code in a consistent and expectable format.
End proprietary formatting
If your programming language has a common format and you’re writing code in your own preferred format, then you are using proprietary formatting. You are the Internet Explorer of the formatting wars and your indentation preference is ActiveX. Give up your ego and embrace your community.