Tabs versus spaces, thoroughly

Tabs for indentation, spaces for alignment

People keep spamming this as if it means anything. Tabs for alignment
is not a thing. We're not going back to that. Throughout this file,
monosyllabic ''tabs'' is shorthand for tabs for indentation and
spaces for alignment.

Oh, and about this:


Yes, mixing tabs and spaces like this is cursed, but this kind of
alignment is cursed regardless of how it's achieved.
Exception: lisps, see #safe

Editing abstract syntax trees directly would free us to transend the cursed textual plane

Nah, like plain text.

Always bet on text

Just automate it

This solves the problem, but it doesn't answer the question. Also,
code style should be simple enough that a developer can just type
correctly formatted code.

Consistency versus customizability

Iñaki Baz Castillo wrote
To be clear: all those using spaces instead of tabs for indentation
are irredeemably wrong.
Let me see your code in the way I like.

Drew DeVault wrote
@neauoire the other reason which should immediately shut down the
discussion is that tabs are more accessible. If you have a vision
impairment then tabs allow you to customize the display of the
code to read more comfortably.

This argument is best made in this reddit post

A Hacker News user with a throwaway account wrote this about it
Not going to get into the details of the argument (there is a
reason tabs vs spaces is considered the prototypical "religious
war"), but I do strongly disagree with the way it was argued, and
I felt the need to comment because I so frequently see this type
of discourse and find it very disheartening. It's what I usually
call the "If you disagree with me you want to kill puppies" (or,
in this case, "if you disagree with me you hate blind people") form
of argument. The author really isn't inviting people to challenge
his thinking with his final sentence - I feel like he's instead
trying to flat out invalidate other opinions by emphasizing how
callous you must be to have them.

Elastic tabstops

Great idea, sadly seems kind of unworkable.

EDIT: I've changed my mind on this.
TODO: update.

Tabs make for smaller files

The many more meaningful arguments from both sides make this
irrelevant to me.

At worst, people merely type it to grow their pros&cons lists. At
best, people use it as evidence of the superiority of tabs, not
so much as a reason to choose them.

Invisible characters are special
"here is how to correctly mix these invisible characters, a thing
space people literally never have to try to do, it's in the name"
look it's not hard. tabs for indentation, spaces for alignment,
form feeds between function arguments, soft hyphens between array
elements, paragraph separators between methods. i love to encode
metadata with invisible characters instead of doing programming
It's not about which one is better. It's about which one can we
get rid of. And we can't get rid of spaces.

Matters of typography

TODO: set virtualedit=all
On font fallbacks and failures
TODO: rewrite.

#portable Tabs aren't portable

I've heard places that tabs aren't supported everywhere.
TODO: fact check.


Lots of pieces of notation consist of inserting characters at the start
of a line like #s for comments, >s for quotes, +s for diffs and so on.

When done to text indented with spaces, the text is reproduced
verbatim a couple of columns to the left.  In the case of tabs,
there are lots of edge cases that can make the text look wrong,
and doubly so when you use custom tabstop values such as 4:


Yeah, not good.

This would not be the case if the convention were prefix-tab instead
of prefix-space, but that would shift things too much to the left
for default values of 8 column tabstops.  Also, good luck getting
THAT to catch on.

Freedom versus safety

Spaces allow for wrong indentation, where bad indentation means
mistakenly putting N±1 space indents in an N space codebase,
or something of the sort. You get the idea. Wrong indentation is
still possible with tabs --if a space slips through-- but likely
way less common.

Counterpoint: freedom over safety. TODO.

People who indent with [TODO: which one?] make more money

Abuse of statistics and tired, forced meme.

Tabs mean indentation

TODO wrote
Tabs are meant to indent, that's exactly what they do, that's
only what they do. They're not meant to format text, to align it
in columns, to put your comments into a regular block.

Xah Lee wrote
the semantics of tab is what indenting is about, while, using
spaces to align code is a hack.
Tabs were invented for tabular data. Source code is not tabular,
so check and mate, go indent with spaces.
Honestly if you find the accessibility argument weak, and many do,
consider that the tab character is literally for indentation.

Gary Bernhardt @garybernhardt wrote
> "The accidental lingering aftereffects of typewriters' mechanical
> limitations are integral to the experience of programming."
> — Tabs.

Who is correct here?
Was the tab key invented before the invention of indenting code?

Every editor supports tabs

Indenting with spaces is not supported in every environment,
to my knowledge there's no way to get an interactive shell to interpret the tab key as a number of spaces.
Ditto some old but important text editors like the original vi.

If you use tabs you need to set up your text editor to know how many spaces an indent level is and insert,
delete and move that many spaces when you're at the start of a line.
(And possibly more things.)
If you use tabs you need none of that,
it solves all of it for you.
You should set it up to let you know if you mix spaces and tabs but space people should do that too,
they just don't need it as bad.


Always do this regardless of preference

Get your setup to spot mixed up invisible characters for you.

Relevant git config settings:

		whitespace = fix
		whitespace = space-before-tab,trailing-space

Break glass in case of spaces

How many? To me, 2 spaces is indisputably nowhere near enough
indent to easily scan the structure of code. 4 is workable, but
still not ideal. 8 happens to be the sweet spot.

Regardless, make it easy for developers to comply with your projects
tab length. Editorconfig is overkill but worth it.


Break glass in case of tabs



Adam Spiers
Bart Groeneveld
Jamie Zawinsky
Lea Verou
Stackexchange thread