Tabs are objectively better than spaces
gomakethings.com
gomakethings.com
Monospace spaces are consistent across every machine
While the fight over "how many spaces" can be tricky, at least the code looks consistent once a standard is found
It matters in that the code you write looks great for you, but misaligned for everyone else.
If we are coding as a team, the code needs to be easily readable by everyone, not just by your IDE -- and without having to change my IDE to suit each developer's personal preference of tab size
Because that's exactly it -- you set your IDE to make tabs the width that is easy to read for you. I do the same. We both get readable-to-us code without imposing our visual preference on each other.
I don't understand the downside of this approach. Am I just missing something obvious? Honestly asking.
I love that I can set tabs to a certain size and it all just works. Nowadays I have to use an editor that already has spaces in mind just to edit. I used to be able to edit code in Notepad, but with some codebases using 2 spaces, or 4 spaces... I've even seen some with 8 (!!).. I have to use an editor that understands spaces = tabs (VS Code, for example).
There are days when I want to switch sizes, just because of my little neurodivergent brain.
I'd love to hear why spaces became the dominant form of indenting code. Does anyone know the history?
A lot of code will use space to align code over multiple lines. If you only use tabs, the alignment will be broken in other developers editors if they don’t have the same tab indentation.
The author complains about visual noise with 2 level indentation. But misaligned code can become a complete unreadable mess. You end up being forced to set your tab indentation to the same value as the original author anyway.
So the logical conclusion then may be to use tabs for indentation and spaces for alignment. That would work in theory, but handling that correctly in an editor is nearly impossible.
So then you end up with the conclusion that spaces is the only way that doesn’t have any serious downsides. It’s far from ideal, but i don’t think the purported benefits that tabs have of letting you change indentation later works in practice anyway.
I’ve experienced this personally in a huge code base with multiple authors where some earlier code used tabs. It was always a 50% chance that code with tabs looked like hot garbage as the author had a different tab level than yours. After enforcing using only spaces, at least the code looks fairly organised most of the time.
My take is it's because when people use tabs, they don't only use it for "regular" code indentation, which remains consistent when different people configure their editor for a different visual tab width. They also use it for things intended to line up, like this:
void actions() {
int bat = (get_bat_thing()
+ the_other_thing());
int turn = (get_turn_thing()
+ the_other_thing());
return bat + turn;
}
Obviously that'a a made up example to illustrate. Line 2, 4 and 6 are "regular" indentation, and if it's done with a tab, you can change displayed tab width to taste, and the code will still look consistent.But the lines 3 and 5 are intended to match up with the expression, and that breaks when someone has used tabs (followed by a few spaces).
Changing displayed tab width makes lines like that misaligned and ugly. Even worse, it does so in an inconsistent way in different places in the code. If the example was written with 4-wide tabs (matching the regular indent on line 2), then you display it with 2-wide tabs, it will change the line 3 and 5 indentation inconsistently:
void actions() {
int bat = (get_bat_thing()
+ the_other_thing());
int turn = (get_turn_thing()
+ the_other_thing());
return bat + turn;
}
After the person using an editor configured with 2-wide tabs edits the file and lines up their code, it is then indented inconsistently for the person using 4-wide tabs. They might not even realise. If a team does this for long, different parts of the code end up inconsistent in different ways from each other; a messy repo.This messy repo problem is avoided by mandating spaces.
On the face of it, this seems to take away your personal flexibility to change visual indentation locally. But this isn't really true. In principle, your editor could change how it displays the code, as if those spaces were really the equivalent tabs, and then use a different displayed tab width, distinguishing between regular and expression indentation in the editor to keep various alignments.
object1.field1 = value1;
longObject2.field3 = value2;
longObject23.longField1 = value3;
or if ((firstArg == 1 && x == 3)
|| (firstArg == sthElse && x == 4)
|| (thirdArg == 3 && fourthArg == 2)
) { ... }It's just more work and to do it reliably requires making tabs visible in the editor though, which is another mark against tabs for many, I'd imagine.
I suppose there may be Vim/Emacs realignment macros that take care of it but then we're heading toward the other classic argument.
Here's what it should look like (if you really want to go full-alignment):
class Demo {
\tfunction thing() {
\t\tlet height = 123;
\t\tlet width = 456;
\t\tlet title = "Foo";
\t\tlet description = "Foo bar baz";
\t}
}Personally, I really hate code formatted like this. I don't really think it's any easier to read, and I find it obnoxious to write/maintain unless the editor does it for you. Just my opinion.
There is added value to collectively agreeing on one format. I think that added value can easily outperform the technical merits of a specific format.
No, Betamax was worse for most uses than VHS. The picture quality of Betamax was better at roughly the same tape speed, but the cassettes held about half the amount of tape. Slowing down the tape to improve capacity made the quality advantage go away.
colon newline, space space space space space space space space if x equal equal 5 colon newline, ...