This thread is old but still shows up on search results, and not only for PHP queries. I believe it lacks modern thoughts about accessibility.
The facts in the accepted answer are clear: for consistently looking code, spaces are best.
However, do you also have consistency among the people you work with?
It might not be the case: some people might have impaired vision.
On an open source project, one might not even know how "consistent" the people working with them are.
Some require such big font sizes, that being able to set the tab width to 1 is a big deal. (I am short-sighted, and although I don't have special needs other than wearing glasses, I can understand how useful it can be for others).
After working years on projects using spaces, and years on projects using tabs, what's apparent to me is that for most developers, tabs or spaces don't change anything. We adapt easily to one choice or the other.
The only persons for whom it matters, are people with special needs. And for them, tabs are better. Shouldn't this be a done deal?
This is even more true these days, as many languages now have great tools to autoformat our code. If an autoformatter is available for a language, then using it should be a priority. It is SO great to not have to ever think about indentation or formatting.
With tabs, the code will not consistently look the same on everyone's screen anymore, but another thing will become consistent: a good experience for everyone.
It is for this exact reason that the web has introduced media queries like prefers-color-scheme
and prefers-contrast
. We want to improve accessibility of websites; source code deserves the same.
So, my recommendation is to set the project settings to fix the differences between operating systems that developers shouldn't have to deal with, and to set some preferences like trimming trailing whitespaces.
That's it. Do not set the tab width, it is a user setting.
Forcing the tab width would be like forcing a bright high contrast theme for everyone in the project.
So for example, here's an .editorconfig
file:
# https://editorconfig.org
[*]
charset = utf-8
end_of_line = lf
indent_style = "tab"
trim_trailing_whitespace = true
insert_final_newline = true
And a .vscode/settings.json
file:
{
"files.encoding": "utf8",
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"editor.insertSpaces": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
}
(Also, point 3 in the accepted answer — "Making more money" — might be misleading. Developers using spaces could simply be making more money because they're older (so have old habits). Young developers (paid less) could have answered that they use tabs because they press the Tab key when indenting. And there's more, see the comments below the original post.)
TL;DR: I recommend to use tabs and to not force their width (and to use an automatic formatter for everything else if possible). Of cours, this doesn't apply if the project/language you work with doesn't allow it for technical reasons.