Yesterday, I shared some spicy takes. A few were particularly controversial—most notably, that I correct Gif the correct way (with a soft G)—but I also got a lot of emails asking me to elaborate on a few of them.
Today, I wanted to talk about how tabs are objectively better than spaces. This won’t take long.
Tabs let you define how big you want each indent to be, and spaces do not.
Tabs let you define how big you want each indent to be, and spaces do not.
Spaces can too: Simply use more or less of them, to taste.
I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code.
Then use four, or six, or eight, or 20. Hell, most code I’ve seen uses four spaces per indent anyway.
[Re: braille]
Surely there’s an editor out there that will automatically display indent spaces as a tab character. Or failing that it seems like it would be rather trivial create a program to convert n spaces to tabs, and vice versa.
You are missing the point. Lots of code has multiple authors. There is offer no space indention that works for all authors. With tabs each author or reader can use the width that works for them.
automatically display indent spaces as a tab character
You can’t really do this reliably. The problem is that spaces may be used in other places for alignment where the width shouldn’t be dynamic. If you do a simple s/ /\t/g you will have funny results where code was aligned carefully using spaces. (The reverse does work though if you want to go from tabs to spaces, because tabs contain more information.)
You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this for no reason. Sometimes I don’t have a full parser available for every language I want to edit.
Spaces do not allow the viewer of code to choose how wide the indents are, this is dictated by the developer.
Most IDEs allow users to customise how many spaces to display tab indents as. Doing so the other way around may cause issues with languages based on whitespaces such as python.
Spaces can too: Simply use more or less of them, to taste.
Then use four, or six, or eight, or 20. Hell, most code I’ve seen uses four spaces per indent anyway.
Surely there’s an editor out there that will automatically display indent spaces as a tab character. Or failing that it seems like it would be rather trivial create a program to convert n spaces to tabs, and vice versa.
You are missing the point. Lots of code has multiple authors. There is offer no space indention that works for all authors. With tabs each author or reader can use the width that works for them.
You can’t really do this reliably. The problem is that spaces may be used in other places for alignment where the width shouldn’t be dynamic. If you do a simple
s/ /\t/g
you will have funny results where code was aligned carefully using spaces. (The reverse does work though if you want to go from tabs to spaces, because tabs contain more information.)You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this for no reason. Sometimes I don’t have a full parser available for every language I want to edit.
Spaces do not allow the viewer of code to choose how wide the indents are, this is dictated by the developer.
Most IDEs allow users to customise how many spaces to display tab indents as. Doing so the other way around may cause issues with languages based on whitespaces such as python.