Not sure about other implementations, but GCC employs an (apparently?) random use of spaces and tabs.
See for example this file: you'll see that it uses tab characters for indentation, but not everywhere, the reason being that the files use a two spaces indentation per level, but the tab character is inserted in place of a chunk of 8 spaces.
This means that the indentation an editor shows is dependent upon how many spaces an editor shows for each tab, which obviously forces the user to set up their editor in a such a way that tabs are consistent with spaces. By inspecting the linked file you'll see that for a good formatting, tab has to be 8 characters long.
Is there any reason why nobody ever runs a s/\t/ /g
on the whole codebase?
Since I didn't really expect that the use __
was required, which it is, I'm asking this question just in case I'm missing something crucial so that the answer is not "because not everybody agrees that spaces are better than tabs".
Let me clarify one point: given a file generated like this
echo -en 'first line\n second line\n\tthird line\n'
which has this content
first line
second line
third line # there's a tab and no spaces at the beginning of this ine
no editor in the world, ever, knows what the correct way of showing this file is, because that depends on the convention. Stackoverflow seems to assume a tab is 4 spaces, but GCC codebase assumes a tab is 8 spaces.
It is a convention and, as such, it can be inconsistent between different codebases, and no editor is able to deduce our convention in a deterministic way. Given the file above, no editor knows if it has to show the third line indented with respect to the second line (thus guessing a tab is more than 2 spaces) or not (thus guessing a tab is exactly 2 spaces), unless the editor user communicates that information via options.
Clearly, each editor can apply some heuristic; for instance, if a file is a C++ source file and it contains these two lines
if (true) // <space><space>
std::cout << "bye"; // <tab>
the editor can be fairly confident that each tab is at least 3 spaces, to guarantee a minimum indentation to the second line with respect to the first; it could also deduce that the tab is at least 4 characters, applying the euristic that "nobody uses 1-space indenting"; but can it do more? Can it conclude that the tab is 4, 6, or 8 spaces? No, it can't. Full stop.