The issue of tabs-vs-spaces is a long and revered Flame War, so I don't think I'll be changing any minds with what I can write on the topic.
However, it's what I use in all the code that I personally write, and any projects I make public use it.
When you want to indent.
When you want to align.
On the same line, first tabs, then spaces.
(Spaces are shown as ·
and tabs as ↦
in these examples.)
When indenting a function, tab
:
function doThings() {
↦var someNumber = 123
}
When aligning text, space
:
/**
·*·==== the =====
·*····aligned
·*······text
*/
function someBigFunction() {
}
When aligning indented text, tab
then space
:
function getTheZipCode(input) {
↦//··········city,····80924···(-?1234)?
↦var regex = '\w+,\s+(\d{5}(?:-?\d{4})?)'
}
Once you have a space
on a line, no tabs are allowed after it.
This is wrong:
/**
·*·Column1↦Column2
·*·val1a↦val1b
·*·val2a↦val2b
*/
And this is right:
/**
·*·Column1······Column2
·*·val1a········val1b
·*·val2a········val2b
*/
And this is just the worst:
function getTheZipCode(input) {
····//↦↦↦↦city,····80924···(-?1234)?
····var regex = '\w+,\s+(\d{5}(?:-?\d{4})?)'
}