The Tabs vs. Spaces war is over, and spaces have emerged victorious

(xn--gckvb8fzb.com)

Comments

mjburgess 18 hours ago
The point of the "tab" option is that there is no consensus on the number of spaces to use -- so by using tab, one uses a single character, and allows the developer to determine screen spacing to their comfort.

"Tab" being a live option is a symptom of the war-never-over in absolute spacing degree -- since different people have different eye-sight, eye-strain, etc. constraints, different linguistic familiarities, code-density preferences, and so on.

jihadjihad 18 hours ago
Rob Pike on why Go is indented with tabs [0]:

> How wide should the indentation be? 2 spaces? 4? 8? Something else?

> By making the indent be a tab, you get to decide the answer to that question and everyone will see code indented as wide (or not) as they prefer.

> In short, this is what the tab character is for.

0: https://groups.google.com/g/golang-nuts/c/iHGLTFalb54/m/zqMo...

the_mitsuhiko 17 hours ago
The war is mostly over because regardless of it you use tabs or spaces, the many modern languages use a code formatter and reformat to whatever is common. Languages that go with tabs are also now routinely mixing it with spaces for visual alignment and assume a certain tab width for total visual width enforcement.

On the other hand editors often now handle spaces as if they are tabs, even for cursor movement. So well. Both won?

I remember a time when people religiously claimed that both tabs need to be the way to indent but also that they have to be 8 spaces visually. I guess at least that war was lost since now even CSS allows you to change the number of visual spaces a hard tab has.

donatj 5 hours ago
Hear me out - tabs are better because there is no possibility of invalid indentation state. "Make invalid states unrepresentable" and all that,

If your style rule is 4 spaces, you have 3 invalid indentation levels for every valid one. Even if you only use two spaces half your possible indentation levels are invalid.

The number of times in my life I've been editing a space-indented file in vim on some sshed server and had to count spaces is way too high.

bbkane 17 hours ago
The most important thing is consistency. I've become a huge fan of deferring tabs vs. spaces debates to an autoformatter. Set it; forget it; argue about something else.

This is most useful when applied ecosystem wide - no one in the Go ecosystem argues about tabs vs spaces, they just run `go fmt` (or more likely their editor is set to do that automatically) and move the #$@% on with life :)

Fortunately for me, newer languages tend to include a formatter in the core install/editor tooling - Go, Rust, Gleam, Dart, probably more I'm forgetting... I think Go pioneered this approach and I'm glad others have taken it as well.

chrisweekly 17 hours ago
The choice isn't (tabs) vs (spaces).

It's (tabs && spaces) vs (spaces).

In the real world, there will always be spaces, whether used for indentation or not. Using tabs for indentation inevitably leads to a mix of both - which is, objectively, worse for maintenance and consistency.

GeorgeTirebiter 17 hours ago
Completely agree: tabs FTW. I wish I could find the reference, but when dealing with mono-spaced fonts, readability is apparently enhanced with THREE spaces per indent. Now, good computer people hate non powers-of-two, so it's either 1, 2, 4, or 8 spaces!!!! I guess I'm not a good computer person, because my eyes find tab stops at '3 spaces per tab' just right.
ta8645 17 hours ago
Just define Tab as 1 space, and they can be used interchangeably. Peace in our time.
hackthemack 17 hours ago
In the 90s, when I used various text editors like Ultraedit, Nedit, Pico, Nano, Vi, and my co-workers used Dreamweaver, Visual C++, Visual Basic, NetBeans

I was in the "TABs are superior" camp but only for the initial indention of code blocks.

But somewhere along the way, editors added features that let you see invisibles, and let you set up smart tabs so that you could hit tab, but it would interpolate 4 spaces (or whatever you set) into the document, and let you shift+tab back the indention or TAB the indention, but put in spaces.

More importantly, the mass of people who all coalesced on using the same editor in the web development sphere, Sublime then Atom then MS Visual Studio Code, has made it easier to just say "set your editor to do this".

I have changed my mind to using SPACES now because the editor lets me fake using TABS.

purpleidea 17 hours ago
Tabs are the preferred, more efficient and more accessible format, and most people know this. Every golang dev loves just having one tap to indent code, and nobody loves the constant repeat rattle of space indented code.

Seriously though, tabs let you pick what's visually easier for you to read and I've worked with coworkers that struggle when indentation isn't clear.

jl6 17 hours ago
Tabs are the modern choice, because you can then configure your editor so that for every tab character, it calls an LLM with the buffer contents up to that point, with instructions to generate an appropriate number of spaces that can then be substituted in. You might be thinking 2, 4, or 8, but the LLM will give you the contextually-correct answer.
tfandango 15 hours ago
My favorite things about the Tabs vs. Space war is that you can't even reference it without igniting it.
phplovesong 18 hours ago
Tabs are better, simply because you can view them as you like. Go obviously does this, and Haxe too (with default formatting options, even tho its configurable)
burnt-resistor 2 hours ago
Despite the triumphal declaration, bikeshedding flamewars over superficial minutia will continue because that's human nature.
Brajeshwar 9 hours ago
I’ve also been tinkering around with AI-Coding assistants, having fun and learning many of the missing steps from my career. As someone who loved to write codes that are well formatted, well named, and well organized, the one thing I hate about AI-Coding is the fomattinig mess. So, the first thing I do now is to set `.editorconfig`[1] and add an instruction as part of the process to respect it.

btw, it still ignores it at times.

Of course, long back, these are also the first things I did so the team can reduce fights and let them choose their own tab-to-space preferences. The other thing was to set up `.gitattributes`[2] early on, specially for those on Windows, to commit the correct attribution when pushing to git.

1. https://editorconfig.org

2. https://git-scm.com/docs/gitattributes

hotsauceror 18 hours ago
Not that one more opinion in this endless war of opinion will matter, nor will it convince anyone, but I genuinely don't see the issue with "tabs for indentation, spaces for alignment."
dimava 16 hours ago
Edit: it got fixed, thanks to the author

I think with majority of TypeScript projects using Prettier, 2 is more likely to be the default[0]

The linked page literally says to ignore it [1]

> STOP READING IMMEDIATELY THIS PAGE PROBABLY DOES NOT PERTAIN TO YOU > These are Coding Guidelines for Contributors to TypeScript. This is NOT a prescriptive guideline for the TypeScript community.

4 is a historical thing used as a default for all languages in VSCode [2]

[0] https://prettier.io/docs/options#tab-width

[1] https://github.com/microsoft/TypeScript/wiki/Coding-guidelin...

[2] https://github.com/Microsoft/vscode/issues/41200

Edit: found the TS style guide at https://github.com/basarat/typescript-book/blob/master/docs/... , it should be the correct link

P.S. did send a mail to author hopefully they fix it

wodenokoto 6 hours ago
When I started programming in Python I was all like “why do they even allow tabs?” But now I’m like “why did they ever allow spaces?” Space indentation is only nice if your editor has all sorts of weird logic to handle spaces at the beginning of a line as though they where half or a quarter as many tabs.

Just use tabs!

dusted 14 hours ago
It's slightly insane that computer programs are still mostly derived from plaintext files.. but what's absolutely insane is that we, the people creating those programs, do so by modifying individual characters in those very same plaintext files..

Yes, text is a good interface medium for exchanging program descriptions between humans and machines.. but it's not a very good medium for storing and exchanging program descriptions from machine to machine, or even human to human.. Humans have opinions, sense of aesthetics, habits, and so on.. some more than others, but still, most people care about at least some part of the.. non-important-to-the-actual-program-compiling stuff, such as casing, indentation, placement of brackes, variable naming and so on.. all stuff that's there for the humans, the compiler don't care what you name your variables.. It's insane that there's no abstraction here..

Just think about how much code we've written to wrangle characters in text files.. formatters, beautifiers, linters, preprocessors, templating systems, lexers, compilers.. It's natural, the amount of development invested in this, and the, honestly, pretty good tooling we have to manipulate those individual characters in files, makes it seem like the only way..

But it shouldn't be.. We should be able to describe programs by typing text, but the text shouldn't be there both for us and for the machine, it should be there only for us, the machine should present text to us, that describes the program, but we should be in control of how that is presented to us, far, far beyond choosing a color scheme in our glorified typewriter emulators. I should be able to tell my programming editor how _I_ want things presented, and that presentation should be a setting in _MY_ editor, not something that has any effect on the program descriptions I'm working with.. Like, the browsers default stylesheet in an alternative world where HTML only described what, and didn't allow the webmaster to overwrite the style. Power to the user.

If I wanted variables to be blue and blinking, and I want the function keyword to be a fire emoji, that's on me, that's just presentation..

We shouldn't have directories with plaintext files as our program storage, we should have dedicated program description files, and we should have dedicated tooling to work with them..

We will never have that.

DrSiemer 15 hours ago
Meanwhile, the war on tab width marches on. Back when I got tired of inconsistent tab widths, I simply based my preference on the silly fact that some research showed how developers using two spaced tabs make slightly more money.

Among our team we do not enforce a specific width, but respecting the choice of the original author of a project is required.

Kind of annoying how LLMs will sometimes randomly decide to change tab width.

Avshalom 16 hours ago
The real war is between people constantly aligning and formatting things in their code and people who just want to know which bits are inside the loop.
notarobot123 17 hours ago
The original "tabulator" key was intended to save time and effort aligning text with spaces. With the ubiquity of decent IDEs that objective is unnecessary.

I think there is a reasonable argument about the distinct semantic value of tabs but they introduce a concept that the general public think is superfluous when two spaces do the trick.

Words can become obsolete if there are other more commonly understood ways of expressing the same thing. This seems similar.

binary132 15 hours ago
I would humbly suggest that something like “lines of application code ever written”, or better yet, “source code files evaluated since Unix epoch [or “per second” if you prefer]” is probably a better metric. I think in that analysis, you would find that tabs are more than holding their own.
jfengel 16 hours ago
How about "neither tabs nor spaces, and set your editor to indent according to the syntax rules of your language"?

It doesn't work for indent-sensitive languages like Python, but it works for most of the other major languages.

taeric 17 hours ago
Without tab stops, tabs always fall a bit short.

I'm now vaguely interested in hate making a programming language that relies on tabs and field/record separators. Just to really embrace the crazy.

exiguus 16 hours ago
This makes me smile. All the hard work to look up the defaults. Personally I prefer that the CI Workflow enforce whatever is chosen.
jahewson 16 hours ago
Tabs are for tables. Change my mind.
Quitschquat 15 hours ago
How about flexi spaces? Best of both worlds. Set you space size.
tabs_or_spaces 13 hours ago
Finally, I've been battling with this for ages!!
konart 17 hours ago
Thankfully all the go code I'm working with has tabs.
indycliff 16 hours ago
What would an LLM choose... guarantee it's a tab
personjerry 18 hours ago
Wait until you guys hear about fibonacci tab spacing: https://marketplace.visualstudio.com/items?itemName=ewic.fib...
TheAceOfHearts 17 hours ago
This tabs vs spaces nonsense debate has gone on way too long, mostly because people cling on to terrible legacy text editors. Any modern text editor should allow you to write a simple plugin to display tabs or any combination of leading spaces as whatever indentation amount you prefer.

Projects should just pick whatever standard is most popular for their given language, and then people can tweak their editors for personal preferences.

If you encounter a lot of code on the web then you might consider writing a browser plugin.

jeffrallen 16 hours ago
The fact that Go = tabs is just one more good reason to use it, in my book.
wormius 8 hours ago
commas.
deafpolygon 17 hours ago
I've always been team Tab. I prefer tabs, even in my CSV (actually, TSV) files. But everyone else has decided this for me and I have begrudgingly adopted spaces. Even though Tabs can be set to whatever anyone wants at no switching cost to anyone else. Imagine if Python used actual Tabs.
sergiotapia 18 hours ago
Just gimme a `go fmt` or `mix format`. These discussions are so 2007! :)
throwawayqqq11 17 hours ago
Now let the battle of how much spaces to use begin!

Are you a superior 4-spacer or is that too much for your weak IDE on that 4:3 screen?

_hao 16 hours ago
Bullshit. Tabs are the only sane choice and I don't care what anyone else says.
owlstuffing 16 hours ago
This is yet another reason why source code sb stored in parsed AST form.
ChrisArchitect 15 hours ago
Obligatory Silicon Valley HBO clip on Tabs vs Spaces: https://www.youtube.com/watch?v=oRva7UxGQDw