Tabs vs Spaces
I'm just going to preface this post by saying, i spent far too long reading into this topic and in hindsight, it wasn't something that actually needed to be written. That said, it was a bit of fun reading through countless Stack Overflow, Twitter and Blog posts from a wide variety of developers with different arguments about which is better... Tabs or Spaces.
It’s relatively common knowledge that indentation is used to emphasise, structure and layout code in an attempt to improve readability and some form of logic. That said, indentation is generally only used by the soft, fleshy thing tapping away on a keyboard. There are a couple of rare exceptions to this rule such as CoffeeScript, Yaml and Python, but more often than not, it's for the humans not the machines.
Compilers and browsers rarely care about the amount of whitespace they're provided with and as such pretty much nulls the argument on the spot. This, however, doesn't cease the hot topic that has blighted many developers/programmers since forever.
Ask anybody who writes code what they personally prefer and I can almost guarantee a slew of responses coupled with severe opinion and firm judgement on which is best… all with the aim to defeat their common enemy. For people just entering into the dizzying world of code (and even some time served members), it may be something that confuses you too.
There's even a scene in Silicon Valley where Richard starts dating a Facebook employee, they go back to her apartment and proceed to write some software together, as you do... Richard sides with the tabs camp and one of his biggest niggles in life is someone who uses spaces. This scene culminates in him wildly over-reacting, getting very fired up and falling down her apartment stairs after he notices his new potential flame smashing the spacebar like a crazy person to align her code.
A (very) brief history lesson
Tabs were invented back in the age of the typewriter to make the writing of tabular data easier to format. Instead of having to work out how many spaces you'd require to line everything up in a document, you'd install "tab stops" which would then allow you to hit the Tab key on your typewriter keyboard and jump to the next "tab stop". Thus removing all of the hassle and time involved in tapping away on your spacebar to achieve the same desired result.
This key was then brought over to the keyboard as we know it today and is used in a similar way as it's original intention, however nowadays (within the coding/programming community), it's a pretty heavy sticking point in the age-old argument of Tabs vs Spaces.
The Arguments
The below table is basically compiled using information that I've pooled from some of the conversations, general browsing and actual research I've done over the past few weeks to try and visualise what people argue are the benefits to each argument.
Tabs | Spaces |
---|---|
Easier | Easier |
Consistent | Consistent |
Lightweight | Lightweight |
Less Whitespace | Less Whitespace |
Visual appearance | Visual appearance |
As you can see, advocates of both tabs and spaces provide valid arguments but the last point seems to be the most prevalent. All in all, though, personal tastes do not matter. It's hard for anybody to give two hoots what you use for your personal projects that only you work on.
Hell, I used to use a plugin in Atom that attached emoji's next to functions, variable and other elements but nobody else saw it which (in my book) makes it ok.
The main take-home is, for personal projects, use whatever helps get you through your lines and onto your next project. You can still see the source the way you like, even when you use spaces.
The Truth
Indentation and standards for each language do exist and as such there are some baseline "rules" around whether to use Tabs or Spaces. I've only gone and looked into the languages that I use on a regular basis plus a couple of other popular ones. Apologies, but there are too many languages in the world for me to spend more time on this pointless article to go and read more 😉
Syntax Language | Tabs or Spaces |
---|---|
HTML | Google uses 2 spaces and the popular HTML Tidy defaults to 2 |
Compressing…
Here comes the biggest mitigating factor in all of this argument. It really doesn't matter anyway if you're minifying, compressing and/or gzipping your files as you should be in this day and age. Production code will almost never (or at least it shouldn't be) un-compressed or un-minified.
In this glorious day of modern browsers, fast connections and information available in an instant, the battle for speed and gaining those precious micro-seconds when loading a webpage is something that everyone and their dog is taking very seriously. As a result of this, the argument of using of anything other than compressed/minified files in production is pretty redundant as this is generally the first step in a long line of workflow processes designed to help load your content faster than the next guy.
Formatters
To conclude It doesn't matter. With code formatting inside IDE's being more customisable than ever, it's more than likely that you're going to come across code that doesn't fit your idea of perfection and that's ok. Once you've got your editor setup how YOU (or your team) likes it... Everyone can have their opinions.
If you want to read some more information relating to the Tabs vs Spaces conversation, check this out.
Image courtesy of Florian Klauer.
🡐 Older Note
Installing NVM with HomebrewNewer Note 🡒
Butterfly House