As someone who was a die-hard tabs guy for ~30 years, but has been using spaces for the last ~10: This post is correct, but irrelevant.
I hung onto tabs for the reasons mentioned in the article: It doesn't require agreement on the number of spaces for an indent. I always liked 3 (a bit bigger indent than 2, not so much space as 4), but tabs meant people could pick whatever they liked. A single character that means "another indentation level" makes a lot of sense to me.
But, at least in the Python world, spaces have won. So I switched, and whatever.
I have bigger fish to fry, I'll use whatever. If I was on a team that chose tabs, I'd be fine with it. But I'd also be fine with spaces. Life is too short to care, tooling largely just takes care of it.
Yeah, I'm surprised this is even still discussed. Most editors have a setting so I just adapt to what the code I work on is using and most often I don't even notice if it's spaces or tabs. I haven't seen anyone manually typing four spaces anyway. (At least not in the last decade or so.)
I've seen this -- I'd be interested to know how many blind coders are using braille displays. I only know two blind coders, but both use standard accessible editors, using text-to-speech. They don't care about tabs vs spaces. I'm not sure which editors work well with braille displays (if any).
They do care greatly about sticking 100% to an auto-code formatter, not for their benefit of reading other's codes, but so they didn't need to worry about accurate formatting themselves, which is another excellent reason to just pick a code formatter and use it on every commit religiously.
Yes! Not just braille, but eyesight problems in general. Someone using a 100pt+ font so they can see code really don’t want masses of screen estate used by spaces.
"I don't care, as long as it is consistent per codebase."
I work on a codebase that my team owns, and we use spaces. I work on another codebase another team owns, and it uses tabs. I use whatever the codebase wants.
Your answer isn't equally-good, it's worse. The argument for tabs is that each user can set them to display however they'd like. That's obviously not possible with spaces. So tabs make more sense.
It is possible and there's IDE extensions for this at minimum for VSCode, it's just impossible to be consistent with tab indents, because you'll inevitably have to align with a space.
> it's just impossible to be consistent with tab indents, because you'll inevitably have to align with a space.
That's definitely application specific. I've seen other applications (not IDEs) use variable width tabs so that tabular data (Tables) would line up very well with only a single tab.
Then your editor renders the 8 space code as 4 spaces without missing a beat. Why wouldn't it? Detecting the indentation level used is trivial. (Provided, of course, that the author had the foresight to use spaces, not tabs.)
Whenever I open a C file in Emacs, the indentation level is autodetected. I'll admit that may not have been trivial to implement, but it certainly has been done.
More importantly, some people can only see maybe a dozen characters at a time due to vision impairment.
To me, "can someone without good vision work with this code" was all the argument needed. Preferences, sure, accessibility though? Why not just make it simple?
Rust also disappointed me on this, I just have never heard an argument for spaces that comes close to functional rather than just aesthetic. I don't honestly know why this is such a controversial topic.
I was initially angry at the decision to use tabs instead of spaces in gofmt, but the advantages of having 95% of go projects use the exact same formatting has won me over. I'll happily give up my habits and preferences for more universal consistency.
I think the arguments in favour of tabs are pretty strong. But there are a couple of small issue:
- You can't have aligned tables of data / blocks of comments / etc. if group of lines containing the aligned text have different amounts of indentation.
- You can't place a fixed limit on line width (which many code formatting standards do, presumably to reduce horizontal scrolling and facilitate side-by-side diffs).
A lot of tools exist to autoformat code to a standard, or the language has one. Use the tools. In C++ we have clang-format, set it up and leave the decision to that. It just saves so much hasle and takes emphasis off of something that doesn’t matter by making it not matter.
Tabstops are still 9, 17, and every 8 thereafter... the standard on the VT-52 and VT-100 is still used when you 'cat' a file, and if you write files with tabs otherwise, you will have trouble with the console and the printer. Which is to say, I'm still fine with a tabs substituted for spaces wherever you like.
Didn't Stephen McConnell settle this in the 90s in Code Complete? Spaces, no fewer than 2 and no more than 4, and follow the main convention of the language.
Granted, you're hosed if you wrote C for the Linux kernel; you were stuck with 8.
I hung onto tabs for the reasons mentioned in the article: It doesn't require agreement on the number of spaces for an indent. I always liked 3 (a bit bigger indent than 2, not so much space as 4), but tabs meant people could pick whatever they liked. A single character that means "another indentation level" makes a lot of sense to me.
But, at least in the Python world, spaces have won. So I switched, and whatever.
I have bigger fish to fry, I'll use whatever. If I was on a team that chose tabs, I'd be fine with it. But I'd also be fine with spaces. Life is too short to care, tooling largely just takes care of it.