Tabs versus spaces
Had to admit to wife that tabs vs. spaces is really a thing. So embarrassing


Spaces are great for aligning things, unless you switch to a proportional font in which case they are completely hopeless.

Tabs don't (necessarily) break when used with proportional fonts. However custom tab values do break alignment
(system defaults of 4 count as custom).

You can't align things longer than 7 characters, which is doubly bad when you take into account that aligning text into columns becomes more desirable the more variable the sizes of their would-be ''cells'' are. So tabs dissallow for alignment when it's most useful.

The tab key is also useless for alignment of non-zero-padded numbers, since they are a special case in that they must be aligned in a ''flush right'' manner.

Tabs for indent and spaces for alignment

Yeah, no. You can't mix and match like that. You WILL get them mixed up.

Gary Bernhardt @garybernhardt wrote
"If you just use tabs for indent and spaces for alignment it'll be fine!"
"If you just free your mallocs it'll be fine!"
Literally the same!
Someone replied
It's fine if you use gofmt ✨

Ah, yes, the Gofmt Argument. Automating whitespace does, in fact, nullify the wrongness of the both approach, but it also nullifies the entire point of a debate about whitespace, so it's kind of invalid.

Consistency versus customizability
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.
Hard tabs cause source files to depend on metadata to be displayed correctly.
Not if you use tabs for indentation and spaces for format.
if you use a tab for indentation and then some spaces to format, how many spaces should the tab be? that's the metadata.
It doesn't matter, it might look different but it will still look correct. And everybody gets their preferred tab size.
that assumes 1) no intended alignment between differently indented lines and 2) no column limit

Some people think 8 columns tabs are too long and customize tab character size in their {editors,terminals,whatevers}. This is wrong because it makes alinment that uses tabs break. You can get around this by making the ''tabs for indent and spaces for alignment'' argument, but it is wrong, which makes this also wrong.

However, there's an argument that tabs are better, because just like they can be customized to be shorter, they can be customized to be longer, which may be desirable if you have bad eyesight.
@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.

Is this really a thing though? I have _shit_ eyesight and I just took a look at some Go code with my glasses off: I can't read a thing but, indent-wise, the structure of the code is pretty clear to me. Like, I can't imagine a context in which 8 columns isn't enough indent but you can still read characters.

Maybe I'm wrong though. Do you (or does someone you know) set your tabs to be longer than 8 columns? Please, let me know!

Elastic tabstops

Elastic Tabstops are an attempt to make the tab character actually good at alignment.
Rather than saying that a tab character places the text that follows it at the next Nth column, we should say that a tab character is a delimiter between table cells in a manner more reminiscent of how they're used in tab separated value (TSV) files. When used for text or code I call this format "Tab Separated Columns". Seen in this light, we can see that space aligned files are analogous to the old fixed width data files, and we all know the advantages that delimited files have over those. For one thing, you can use sed or other tools to substitute strings in files and everything will still line up when you load them in the editor. Another advantage is that proportional fonts can now be used (in itself not a new idea - see Smalltalk, Oberon and Plan 9's Acme).

If we'd made computers work this way from the start we'd live in a tabs-for-everything utopia. It would also be really useful outside of a programming context: hassle-free, spreadsheet-quality alignment at every text input.
If I had a time machine I'd make sure the definition of the "tab" character in ASCII required the use of elastic tabstops

Sadly it is hopelessly unworkable for backwards compatibility reasons. Unless everyone adopts it at the same time code will look broken for whoever doesn't adopt it.

File size

Tabs lead to smaller file sizes than spaces. It escapes me why anyone thinks this is even vaguely relevant among so many way more meaningful arguments from both sides. Maybe no one really does, maybe it's an illusion created by people typing it to grow their pros&cons lists.

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.

TODO: Tabs don't allow for arbitrary indentation, like in lisps.

Okay, so let's make tabs the global default and have lisps still use spaces. Yeah, no. This doesn't necesarily rule out tabs altogether, but at least for holy war purposes, There Can Be Only One.

Invisible characters are special

/media/tabsversusspaceshotlinebling.jpeg credit
"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

Andrew Kelley @andy_kelley wrote
talking about this video
tabs v spaces: "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." A+
TODO: replace with quote from video.


Tabs ''mean indentation'' in a way that spaces don't.
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. "Hard tabs" is such a bad term, it should just be "tabs". "Soft tabs" should be called "spaces pretending to be a tab".

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?


Break glass in case of spaces

How many? The hill I will die on is that 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.

Break glass in case of tabs

Don't use them for alignment, and configure your editor to help you spot mixed up invisible characters. On vim my current setting is
        set list listchars=tab:▒░,trail:▕
which makes code look like this:
        for {
        ▒░░░░░░░if done {
but with much dimmer tabs, because of my colorscheme.