I used to prefer spaces over tabs.
As long as the font was monospaced (each characters take the same width and height),
spaces would make anything and everything aligned perfectly, anywhere.
True, tabs should also do that, but pasting code with tabs on some website would occasionally ruin the indentation.
I was like this for a few years; any languages that I used would be indented using spaces.
As far as I know, all reputable IDEs and text editors have a feature that would automatically
remove the whole indentation block with one backspace (as opposed to clicking 4 times on the
backspace button to remove each spaces in the indentation). As far as usability, spaces are
better suited to most tasks since not every website support the TAB
character in their inputs.
As any developer do every now and then, I was having a debate with a few friends and fellow programmers about said subject on Xat, a chatting platform which was rather popular back in 2010 (but later on died due to the arrival of Discord as well as its persistence on not wanting to migrate to HTML5 instead of Flash). Though it was just a late Friday night debate with very little serious points being made and an atmosphere that clearly indicated nobody really wanted to convert one another to their own indentation style, it was still a night which I remember to this day, almost 10 years later.
A few minutes in the debate, somebody joined our chat. This wasn’t anything too special as the chat was known for being a hub for programmers. After being quiet for a few minutes, he suddenly pointed out the following obvious, but often overlooked fact:
If
person A
wants 2 spaces,person B
wants 4 spaces, andperson C
wants tabs, then everybody should use tabs because you can set the length of theTAB
character in the settings of almost any IDE.
So silly, yet so true. Even if many IDEs nowadays have the make-4-spaces-seem-like-2-spaces feature (which seems like a bad practice anyways), this doesn’t change the following benefits about using tabs over spaces:
Want to use 2 spaces? no problem. Want to use 4 spaces? no problem. Even 8 and 16 if you’re feeling wild.
With spaces, some files created by person A
could be indented with 2 spaces whereas
others created by person B
could be indented with 4, though this isn’t too bad per se,
it’s still an inconsistency, and inconsistencies are bad.
Even though having a code format style for each projects does help, some people might be dissatisfied with the spacing chosen (e.g. 2 is very popular these days with HTML instead of 4). Using tabs as indentation allows any developer to chose what they like without having to fear being yelled at by an angry colleague who prefers using a spacing of 5 for some mysterious reasons.
Though I do use tabs for indentation now, it doesn’t make the use of spaces suddenly forbidden for every single case. Spaces are still useful for alignment. Because I like when code is neat and tidy, tabs are not the best for alignment – spaces are. For an example, I suggest you read my coding convention article.