Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by mjburgess on Friday July 25, 2025 @02:55PM
(#44686874)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by SAI_Peregrinus on Friday July 25, 2025 @04:15PM
(#44687897)
But an editor can just as well let the user choose what width to display spaces at the start of a line. Nothing forces them to be the same width as spaces in the middle of a line.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by em-bee on Friday July 25, 2025 @05:37PM
(#44688783)
which editor does that? space width is defined by the font, and normally you use monospace fonts. i am unfamiliar with any editor that allows you to choose a different font for spaces. besides, it would only work for indents, it would mess up any alignment of code into columns.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by SAI_Peregrinus on Friday July 25, 2025 @08:17PM
(#44690081)
None, but it's clearly possible to add since such handling is already present for tabs in almost any editor. I merely mean that there's no technical restriction.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by efilife on Saturday July 26, 2025 @12:32AM
(#44691358)
But this option already exists for tabs that are pretty much built for this purpose. It's like adding a fifth wheel to a car because there's no technical restriction even though 4 work fine
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by eviks on Saturday July 26, 2025 @01:57AM
(#44691727)
Nope, an editor can do that, but it can’t do it just as well because not all spaces at the beginning are indentation, so then you need to have more complicated rules to differentiate between those cases
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Ferret7446 on Monday July 28, 2025 @05:07AM
(#44708826)
Too bad editors can't do something as complex as recognize language syntax. Imagine if we had that feature, then we could do things like syntax coloring.
Sarcasm aside, if your editor can't recognize indentation or adjust indentation according to arbitrary preferences, you really need to update your toolset.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by quietbritishjim on Friday July 25, 2025 @03:37PM
(#44687415)
> so by using tab, one ... allows the developer to determine screen spacing to their comfort
(Allow me to reply to this age-old argument with the age-old counter argument...)
But you also have to decide at what point to hard wrap each line based on a max line length, and you can only do that based on some choice of tab size. Anyone with a different tab size preference would see the right column wandering depending on indentation level. This invalidates the only advantage of tabs (assuming file size is no longer a concern).
A common retort is that each reader's auto format (or soft wrapping) can sort out the wrapping. But if each coder is going to reformat the code anyway then they get the benefit of choosing their own indentation level regardless of tabs vs spaces.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by JohnFen on Friday July 25, 2025 @03:46PM
(#44687527)
> But you also have to decide at what point to hard wrap each line based on a max line length
I think that you should not be doing this, for the same reason that you should use tabs. It allows the user to select whichever hard wrap point (if any -- I generally choose to not have one) they prefer.
But all of this sort of thing is pointless debate these days, when it's pretty fast and easy to preprocess the files to match your preferences prior to editing.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by 1718627440 on Friday July 25, 2025 @04:51PM
(#44688305)
But you don't hard wrap at exactly the max line length anyway. You wrap at the somewhere sensible near the max line length. This is much more tolerable to size changes in indentation.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by quietbritishjim on Friday July 25, 2025 @05:02PM
(#44688439)
That's is a much worse user experience. The slack has to be greater for more-nested lines. In other words, you're really just catering to those who have wider tabs.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by quietbritishjim on Friday July 25, 2025 @04:35PM
(#44688117)
Like if my tabs are 2 spaces and I save a file like this:
line1 = wrapped
+ to_here_max
if something:
another_line
= some_val
+ other
Of course this is exaggerated, especially because most lines won't be close to max width let alone exactly at it. But you can set the width of your editor to whatever number of columns that you're hard wrapping to (i.e. what you save in the file) and be sure every line will fit.
Then someone else loads it with tab width set to 6:
line1 = wrapped
+ to_here_max
if something:
another_line
= some_val
+ other
Now the max column width of a line depends on the syntactic indentation level of it! Any width you choose for your editor will either overflow for some deeply nested lines or waste loads of space on less-nested lines.
Of course it's not a real concern because your editor can probably automatically fix this. But if it's clever enough to do that, then the supposed extra flexibility of tabs is actually possible with spaces anyway.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by citrin_ru on Saturday July 26, 2025 @07:00AM
(#44693088)
> But you also have to decide at what point to hard wrap each line based on a max line length
Exact and strictly enforced max line length IMHO unnecessary. Too wide code is hard to read, too narrow too but in between there is a wide range of acceptable values. When possible I treat max length as a recommendation, not hard limit.
When you don’t have a hard limit it’s not a problem if code added by someone who uses visual tab width 2 will go over 78 characters in the editor which tab width set to 4. Equally it’s not a problem when someone using 4 will make a line break sooner than one using 2.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by PlunderBunny on Friday July 25, 2025 @04:43PM
(#44688207)
The VAX/VMS terminals we used at university to learn Pascal defaulted to 8 space tabs, on a 80 column screen. That certainly pushed some people towards using spaces.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by 1718627440 on Friday July 25, 2025 @04:54PM
(#44688324)
I use 8-sized tabs with 72 columns in C. The human eye doesn't like moving all that much while reading and more windows fit one the screen even if it is annotated with git blame. In addition there is this argument from Torvalds, that you should mind your maximum nesting in a single function, which I also find useful.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Jensson on Saturday July 26, 2025 @01:29AM
(#44691594)
> In addition there is this argument from Torvalds, that you should mind your maximum nesting in a single function, which I also find useful.
Note that nesting is a much bigger issue in a language like C where you have to clean up after yourself, in most languages having a lot of nesting in a function isn't an issue.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by kbelder on Saturday July 26, 2025 @04:30PM
(#44696732)
Which was influenced by tab stops on typewriters... which were adjustable, but were generally set at 1/2", 3/4", or 1"... which was the equivalent to 5-12 characters, depending on your font (monospaced, but sometimes 10 cpi, sometimes 12 cpi).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by pmontra on Friday July 25, 2025 @04:26PM
(#44687997)
According to the table in the article there are more languages with a recommended value of 2 than languages with 4. I'm using 2 for Ruby and 4 for Python. I don't remember what I'm using for JavaScript, maybe the same value of the main language of the project.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Jensson on Saturday July 26, 2025 @12:49AM
(#44691433)
You should really use 3 since obviously people want a bit more than 2 and a bit less than 4. I use 3 for that reason, as I was most productive at 3. At 2 I don't get an overview easily enough, at 4 indents start to creep too far out making it hard to work in larger functions. 3 is really the smallest number where I still easily saw the big picture structure of a file, so I feel that is the optimal one, at 2 I start to not be able to eyeball how indented a piece of code is.
Not sure why people are so obsessed with having power of 2 spaces, can anyone explain that? Why argue over 2 vs 4 when you can have 3 for everything? I think 4 is better than 2 since 2 is too hard to track, but 3 obviously is better than 4.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by DanHulton on Friday July 25, 2025 @03:40PM
(#44687457)
I used to defend tabs for this reason, except I kept running into source code formatters/displays online that would attempt to display my code with the tabstop set to 8 spaces, which made it nigh-unreadable.
While I run into fewer that do this nowadays, it still reminds me that with tabs, What I Write May Not Be What You See, which can lead to readability issues, which I feel is a solid enough point against tabs that I've switched.
I write code so it is easy to read, and spaces are better for that than tabs, so now I use tabs. ¯\_(ツ)_/¯
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Joker_vD on Friday July 25, 2025 @03:16PM
(#44687179)
Like what standards, exactly? POSIX in its tabs(1) [0] and expand(1) [1] clearly states that tab stops can be wherever, and "every 8 columns" is just a default.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by zamadatix on Friday July 25, 2025 @03:16PM
(#44687181)
That still wouldn't give consensus on how many spaces people using spaces should use, it would (originally) give consensus on how many spaces a tab was supposed to be.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by g-b-r on Friday July 25, 2025 @06:29PM
(#44689262)
The few applications that don't let you configure it are less relevant now, and the alternative to consider tabs of varying lentgh would be to introduce a new spacing character in their place; hardly feasible.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by birn559 on Saturday July 26, 2025 @12:54AM
(#44691448)
The problem with this is:
1. It's relatively hard to think it through to the point that you see and have the potential benefits in all cases(*).
2. All participants and tools must fully support the solution.
It needs a momentum it never got so the world settled on a simpler solution.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by mjburgess on Saturday July 26, 2025 @11:38AM
(#44694895)
Vertical spacing, ideally, reflects the thought process behind the construction of code: it's semantic.
Read-time revisions to spacing need, only, to change the non-intentional elements of spacing -- indent depth is a very good candidate for this (hence the tab character!).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by throwawayqqq11 on Friday July 25, 2025 @03:13PM
(#44687134)
Exactly.
Indentation != spacing.
And thats all the argument i need. I dont understand why people argue with consistent text layout for all-spaces. You can use tabs to indent and spaces to align after that, in most cases.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by thih9 on Friday July 25, 2025 @03:31PM
(#44687354)
> You can use tabs to indent and spaces to align after that, in most cases.
In practice this is difficult; since the characters are invisible by default, people will inevitably mix up the two. Looks like the industry standard is to give up and use spaces everywhere, unless strict and mandatory tooling exists.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by xipix on Friday July 25, 2025 @03:49PM
(#44687561)
You can't use spaces to align because you can't assume a monospaced font will always be used. You can't use tabs either for that matter. If you need structure, use the language's punctuation and line breaks.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by eviks on Saturday July 26, 2025 @02:06AM
(#44691768)
You can use tabs, that’s exactly their role, but only in theory since in practice elastic tab stops that would work with proportional fonts aren’t implemented anywhere in code, only word processors
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by em-bee on Sunday July 27, 2025 @06:25AM
(#44700245)
no, i can't. i want to be able to align on arbitrary columns, not on tab stops. and when i add or remove character that break the alignment, tabs mess everything up. spaces don't.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by eviks on Sunday July 27, 2025 @06:29AM
(#44700259)
No, you can't do that with spaces because spaces have a fixed width, which can't always be aligned to a variable width column. Only in the primitive environment of fixed width fonts does this work, but even there the tabstops can also be placed at an arbitrary column position, check Word out
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by yencabulator on Monday July 28, 2025 @07:34PM
(#44717114)
Sticking to historical limitations can be kind of silly. I used to have a computer with 40-column text display, and I don't feel any need to limit myself to that anymore.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by em-bee on Tuesday July 29, 2025 @07:08AM
(#44721768)
i agree with you on principal, but i am not sure that this is simply a technical limitation. it feels to me more than a simple preference. i can't explain it, but looking at the example in this article: https://storck.io/posts/proportional-programming-code-fonts/ i find the apple systems font example much harder to parse (visually scanning the structure) than the monospace one below. perhaps it is simply what i am used to. but i feel like i am having a more violent reaction than i should have if mere preference and habit were the issue.
one issue is that of distinguishing similar characters, which the above projects try to address while some people claim it's not an issue at all: https://alexkutas.com/posts/non-monospace-font
there is also the issue of alignment mentioned in the first article, that can possibly be addressed by limiting font widths multiples of the smallest width.
but there is still the issue of interacting with other programmers, mentioned in this article: https://nelsonslog.wordpress.com/2021/09/12/proportional-fon...
we would all have to agree on the same font if there is any kind of alignment needed apart from indentation. right now we can say that you can choose any monospace font, and things will look as intended, but with a proportional font things will look different depending on the font choice. whether that is an issue or not needs further study i think.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by yencabulator on Tuesday July 29, 2025 @04:46PM
(#44728081)
I definitely do not enjoy the font choice in your first link. The Go font has been pretty good for me. My editor is configured to use "Go" (not "Go Mono"), I don't even notice when I switch from editing prose to editing code.
"Distinguishing similar characters" is just as much of a concern for me when I'm editing technical documentation as when I'm editing source code. Once again, the Go font has served me well. Previously I used some other humanist style font from from the Ubuntu people that had that classic IBM slash-through zero. Some fonts have overly-aggressive ligatures and such, but those fonts should not be used in any technical context, source code is not special.
Alignment is a non-issue because wanting alignment is bad. There, solved that ;-) Arbitrary diff noise over multiple lines because you added one line at the end is a problem, not a goal!
I interact with other programmers just fine. Your linked article seems to be re-engaging in the tabs-vs-spaces flamewar in an era of gofmt rustfmt et al. It's a total non-issue.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by rafram on Friday July 25, 2025 @03:34PM
(#44687380)
You use line feeds (\n) to instruct your teletype machine to feed in one more line of paper. Unless you're trying to argue that your text editor is a teletype machine, then line feeds are the wrong thing to use.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by lesuorac on Friday July 25, 2025 @03:51PM
(#44687583)
I think most people are pretty amenable to the argument that text editors are teletype machines.
Nobody cares that phone calls happen over fiber now instead of telephone lines. So, same should apply to teletype. Nobody is going to care you're reading this over fiber instead of a telephone line.
Now, people do care if they're trying to read a csv document and somebody didn't quote their commas within strings and now the values are in the wrong columns which could've been avoided by using tabs to store tabular data.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by deafpolygon on Friday July 25, 2025 @03:52PM
(#44687591)
honestly, spaces shouldn't be used; it's a design issue- use tabs only for indentation, then the language should ideally support not having to use spaces for manual alignment.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by pepa65 on Sunday July 27, 2025 @12:37AM
(#44698932)
I am very much against any alignment with spaces, just not needed, and adding a lot of unnecessary complexity to code formatting. Just use tabs for indentation, and don't mix them with spaces.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by purpleidea on Friday July 25, 2025 @03:47PM
(#44687531)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by the_mitsuhiko on Friday July 25, 2025 @03:09PM
(#44687075)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by tinco on Friday July 25, 2025 @03:56PM
(#44687658)
No one who uses tabs would ever assume a certain tab width for visual alignment. What do you base that slanderous statement on?
I've also never heard anyone argue that someone else should configure some different tab width, is there a specific language ecosystem you were in that had these insane takes?
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by ben-schaaf on Friday July 25, 2025 @10:54PM
(#44690910)
To quote the linux kernel style guide:
> Tabs are 8 characters, and thus indentations are also 8 characters.
Yes, tabs are used for alignment as well.
To quote the OpenBSD style guide:
> Indentation is an 8 character tab.
The GTK source code uses tabs when the number of spaces for indentation >=8. This goes against their coding-style document, but if you don't have tabs set to 8 you'll find the indentation broken.
git is the same: although it prescribes tabs if you don't set the width to 8 you'll find broken alignment everywhere.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by pepa65 on Sunday July 27, 2025 @12:46AM
(#44698957)
This "broken alignment" only happens when you mix tabs and spaces. If you do not align (with spaces) then all is fine. Please do not align at all, it is too arbitrary and altogether unnecessary.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by frizlab on Friday July 25, 2025 @03:56PM
(#44687651)
And yet, navigating the code, you still have to got left-left-left-left to pass the indentation and it’s stupid. Tabs are here, everybody should use them, they are the logical better option, everybody knows it.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by frizlab on Friday July 25, 2025 @07:44PM
(#44689847)
alt-arrow
But it’s not what I mean. When navigating using the arrows it just breaks the flow because suddenly you “don’t move anymore.” Hard to explain, but it is real.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Avshalom on Friday July 25, 2025 @04:15PM
(#44687895)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by GeorgeTirebiter on Friday July 25, 2025 @03:13PM
(#44687125)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Izkata on Friday July 25, 2025 @03:40PM
(#44687459)
I remember suggesting it as a jokey promise over a decade ago, but got curious and tried it myself. It also seems just right to me, and is what I've used in all my personal projects ever since.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by RGBCube on Saturday July 26, 2025 @05:18AM
(#44692645)
I also use 3 spaces myself, because 4 spaces is too damn wide and 2 spaces is a little bit too small. I would use tabs instead, but rustfmt doesn't handle it well at all in some of the nightly options, I've had it use spaces where it should use tabs a lot.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by rossant on Saturday July 26, 2025 @05:42PM
(#44697120)
TIL some people use 3 instead of a power of two. I would never had thought of it nor would I have considered it as a reasonable choice. And now I wonder why I would have thought that.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by bbkane on Friday July 25, 2025 @03:12PM
(#44687124)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by arccy on Friday July 25, 2025 @06:39PM
(#44689337)
but the autoformatter will have dictated the choice of space vs tabs for the file in question, an likely also the width of tabs (if any) for alignment. so you just need to follow the convention.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by justinclift on Saturday July 26, 2025 @02:18AM
(#44691833)
Go's autoformatter will absolutely screw up existing ascii comments when they randomly decide to change how the formatting works.
As found the hard way when one day we updated the version of the Go formatter, and much of our nice comments needed to be redone. Thanks Go formatter team (yes, that's being sarcastic).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by phplovesong on Friday July 25, 2025 @02:58PM
(#44686919)
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)
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by mananaysiempre on Friday July 25, 2025 @03:08PM
(#44687057)
That’s mostly editor braindamage (that has unfortunately leaked into some otherwise very good codebases, like LuaJIT). Indent things with tabs, align with spaces[1]:
if (foo) {
» frobnicate(bar,
» ...........baz);
}
Both camps will hate you, but things will work just as they should.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jahewson on Friday July 25, 2025 @04:28PM
(#44688025)
Actually for me this shows why tabs don’t deliver on their promise. As soon as the user’s tab size is small enough that baz doesn’t need to wrap, the user gets suboptimal formatting. As someone who prefers tabs of 2 and often views code authored with tabs of 4 I encounter this often.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by g-b-r on Friday July 25, 2025 @08:49PM
(#44690296)
Your team should settle on a maximum line length independent of which tab settings one has
Of course that will always be a compromise, either people who use narrow tab widths or those who use wide ones will have a (slightly) suboptimal experience.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by phplovesong on Saturday July 26, 2025 @04:15AM
(#44692362)
Formatting by hand is probably only going to work for private hobby projects. In 99% of the other cases there needs to be a formatter that does the formatting.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by mananaysiempre on Saturday July 26, 2025 @08:47AM
(#44693721)
That feels both largely irrelevant and false? False, because there are plenty of large projects that do have a house style but don’t use a formatter at code submission to enforce it—even if you reject the Linux kernel as an atypical example, basically every piece of commercial software from 20 years ago also fits, simoly because both formatters and presubmit checks weren’t nearly as common, and there were some chonkers there (like, I don’t know, Windows XP). Irrelevant, because it’s perfectly possible for a formatter to follow this convention (gofmt does, for example).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Arelius on Friday July 25, 2025 @03:08PM
(#44687051)
Yes, this. Which the counter point is either, Don't align things, or use tabs for indentation, and spaces for alignment.
And maybe you can enforce no alignment, but that's a hard fight to win.
And as far as tabs for indentation and spaces for alignment, I've found no practical way to enforce this via tooling/linting. And a rule without enforcement becomes inconsistent, which is how we get files full of mixtures of spaces and tabs, which is how people get frustrated with tabs, and we decide to throw it all out.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by ytpete on Friday July 25, 2025 @04:47PM
(#44688251)
These regexes don't solve what I think is one of the major common problems/complaints though: using extra tabs past the logical indent point as a shortcut to avoid typing so many spaces for alignment purposes.
To take this example from a sibling post:
if (foo) {
» frobnicate(bar,
» ...........baz);
}
Many people will wind up doing this:
if (foo) {
» frobnicate(bar,
» » » ...baz);
}
And then your alignment is all messed up if you have a different tabs setting.
Checking for that requires something more like a linter with a detailed understanding of the syntax parse tree.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by mananaysiempre on Friday July 25, 2025 @10:51PM
(#44690898)
There are degrees of “detailed”.
For example, I considered writing a small Awk program to check C code in response to another poster’s complaint about lack of tooling, but then quickly came to the conclusion that, with C’s insistence that (say) /??/<newline>* is a valid comment starter, getting this exactly correct probably does need an actual lexer that would go character by character. That sounded like it wouldn’t fit in an HN comment, so I stopped there.
(That said, that’s as far as you’d need to go in the majority of cases. A dishonorable mention is warranted for languages that use the same character as an operator and a paired delimiter simultaneously, that is C++, Java, C#, TypeScript, and Rust with their abuse of the less-than and greater-than symbols, because that would in fact require a parser. In C++ especially, you’ll need full semantic analysis with template expansion, name resolution, and consteval evaluation. Because C++.)
Yet you probably don’t actually need to be that accurate, do you? The majority of syntax highlighters aren’t, and they are still useful. You can usually afford to say that code that perverse deserves to lose, and in return I expect you should be able to gain a fair amount of language independence, which could be worth the tradeoff.
So instead of checking if things are aligned with what they should be, you would just check they are aligned with something, like a left word boundary preceded by a delimiter, and so on. I can already see unpleasant corner cases after thinking about it for a few minutes, but it doesn’t look hellish yet, it looks something like you could experiment with over a weekend to see if it was viable.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by pepa65 on Sunday July 27, 2025 @01:13AM
(#44699036)
It would be crazy that spaces would have "won" because of the silly idiosyncratic alignment that some people seem to like and then teach to others for many decades.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by PaulDavisThe1st on Friday July 25, 2025 @03:33PM
(#44687378)
It's not about semantics at all. whitespace has (virtually) no semantics in C or C++, but there are few programmers who would feel comfortable reading such code without the suggestive hinting that indentation provides.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by AdamH12113 on Friday July 25, 2025 @03:05PM
(#44687001)
I use tabs for indentation and spacing for alignment. Tables should be aligned with spaces. A wrapped line can be tabbed up to the start of the previous line and then spaced for alignment.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by TheAceOfHearts on Friday July 25, 2025 @04:09PM
(#44687814)
You can view leading spaces however you like as well. Modern text editors can be configured to display any number of leading spaces as your preferred indentation width. It's not the 1970s anymore, modern text editors easily support something so trivial.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by vouaobrasil on Friday July 25, 2025 @03:16PM
(#44687183)
I never bought this argument, because it seems the vast majority of people are fine with viewing tabs rendered as four spaces. And pretty much the default for spaces is four spaces. So I'm starting to think 99% of the world uses 4 spaces and it's the vocal minority that like 3 spaces or 5 spaces viewing for tabs. And in that case, the configurability is rather irrelevant.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by PaulDavisThe1st on Friday July 25, 2025 @03:34PM
(#44687387)
> another developer is seeing the code different than you.
but that's the whole damn point ... I like substantively indented code, you prefer minimally indented, we should both be happy (and we can be, by using tabs).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jedberg on Friday July 25, 2025 @03:50PM
(#44687573)
You could certainly make that argument. You could also make the argument that all the developers on a project seeing the same view of the code enhances collaboration and team cohesion, especially if your team does pair programming.
This is often why dev teams have more specific style guides that include things would be considered bike-shedding, like how many spaces an indent is.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jahewson on Friday July 25, 2025 @04:40PM
(#44688177)
Wait, no, if there is an 80 character line limit and you like 4 space tabs but I like 2 space tabs, we’re going to have a problem. My code will exceed the line length on your screen or be forced to wrap prematurely on my screen to suit your preferences.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jahewson on Saturday July 26, 2025 @01:49AM
(#44691689)
Personally I use a 100 character limit. Anything more and the ability to have two editor windows side by side gets impeded upon. The point is, there is a limit.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by sokoloff on Saturday July 26, 2025 @07:40AM
(#44693297)
Eh. If 1 line of code in 500 has a trailing bit of punctuation scrolled off the side for 1 in 8 coders who have chosen to have both narrow windows and wide tabs, that hardly seems like a deal-breaker, but if it is, enforce common settings/standards.
(I'm fully converted to Team Spaces, but I also don't get too wrapped up in treating what seem to be soft limits as hard limits.)
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by phplovesong on Saturday July 26, 2025 @04:17AM
(#44692369)
This if a fallacy. With tabs i can view on indent as 2,4 or even 8 spaces. With spaces i force some preset on the dev, not always a bad thing, bit less flexible.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by chrisweekly on Friday July 25, 2025 @03:11PM
(#44687107)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Etherlord87 on Friday July 25, 2025 @04:53PM
(#44688317)
And if people didn't align text, you could still make an argument that people use spaces to separate identifiers or otherwise tokens, therefore it's spaces vs tabs&spaces…
Tabs are for indentation, to align the beginning of the line, later on if you want to align text somehow, use spaces. You probably shouldn't align lines with different indentation (I align rarely so I can't remember ever to do that).
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by lioeters on Saturday July 26, 2025 @02:39AM
(#44691910)
I'm amazed that your comment is the single reasonable take among this entire discussion full of unsupported assertions and opinions.
Having two different invisible characters to represent empty space is objectively worse. Just use space, and the tab key to insert multiple spaces. Simple. Use .editorconfig and a formatter to enforce the commonly accepted standard. Done.
Sadly you still have to make exceptions for Makefile, Go, etc. that expect a mixture of hard tabs and spaces. Otherwise hard tabs are not allowed in the codebases I manage, and are replaced by the formatter.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by 112233 on Saturday July 26, 2025 @05:34AM
(#44692708)
Not to mention that space is a normal printable character, while tab is a control character, like carriage return. Control characters have very well defined meaning, that is very different in different contexts.
As an example, and I hope this is not a new information for most, in many text terminals it does not mean "advance forward to a multiple-of-8 position", it means "advance forward to next tab stop", and you can arbitrarily set those (e.g. HTS/TSC on vt220)
If tabs or spaces are mandated at editor level, how are you editing Makefile or TSV files?
I really do not understand anyone, who is against having support for any possible indentation, controlled by the user as is necessary for each use case.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jl6 on Friday July 25, 2025 @03:20PM
(#44687236)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by g-b-r on Friday July 25, 2025 @08:02PM
(#44689968)
Emacs can let a butterfly flap her wing, causing momentary pockets of higher-pressure air to form, which act as lenses that deflect incoming cosmic rays, focusing them to strike the LLM's memory; the LLM will then report the appropriate amount of spaces.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by hackthemack on Friday July 25, 2025 @03:12PM
(#44687118)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by frizlab on Friday July 25, 2025 @07:43PM
(#44689839)
I know the shortcuts. (It’s not ctrl-arrows; ctrl-arrows is to switch Space.)
There are still situations where it’s annoying, mostly when navigating the code using the arrow, moving from one location to another using the arrows, I won’t add a key modifier right in the middle of moving the cursor, it just doesn't make sense.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by DrSiemer on Saturday July 26, 2025 @04:10AM
(#44692342)
Switch space? On any Windows OS ctrl-arrows (left and right) move the cursor by word. I don't exactly understand how people work with code or even do text editing without it.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by frizlab on Saturday July 26, 2025 @07:56AM
(#44693393)
I’m on macOS and it’s alt-space.
Ctrl-space moves the cursor by “words inside words,” e.g. in theBestVariable, will go between “the” and “Best.” However it conflicts with the system ctrl-space that switch space. Not really an issue, because ctrl-shift-arrow will do the same word inside word move, but extending selection. In the end we can select until the desired location is reached, then hit a single left or right arrow to deselect and we’re there.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by TZubiri on Saturday July 26, 2025 @12:07PM
(#44695112)
You are pushing a lot of complexity to the editor here. Whereas with tabs you can uninstall a lot of garbage and link your keyboard directly with the binary representation of your code.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by hotsauceror on Friday July 25, 2025 @03:05PM
(#44687019)
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."
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by notarobot123 on Friday July 25, 2025 @03:16PM
(#44687187)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by TheAceOfHearts on Friday July 25, 2025 @03:54PM
(#44687635)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by deafpolygon on Friday July 25, 2025 @03:49PM
(#44687558)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by jedberg on Friday July 25, 2025 @03:11PM
(#44687110)
This is the first I've heard of this, but honestly, I think this would be really good for beginners!
Generally, you shouldn't have all that many indents in your function. Using this would be a good visual clue to a beginner that maybe they need to break out their function into multiple functions.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by dimava on Friday July 25, 2025 @04:57PM
(#44688371)
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]
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by DrSiemer on Friday July 25, 2025 @05:49PM
(#44688906)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by binary132 on Friday July 25, 2025 @06:05PM
(#44689046)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by dusted on Friday July 25, 2025 @06:49PM
(#44689412)
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..
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by g-b-r on Friday July 25, 2025 @08:20PM
(#44690102)
> 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..
You would have variable names not saved?
They don't matter for the future maintenance of the program?
You can have most of what you ask right now, the further step most relevant here would be to not indent anything in the saved code; with most languages you're free to do it, and it's feasible to have an editor display it with the indentation you prefer; however it could only make sense if there's no way to have your team agree on an indentation style, there's too many fldownsides with hardly any advantage otherwise.
You're always free to have your editor ignore the spaces and display the code the way you prefer, anyhow.
But it's probably not always possible to deduce how things should be aligned.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by dusted on Saturday July 26, 2025 @03:44AM
(#44692220)
of course I would have the variable name saved, but and I'd probably require the to be somewhat unique too, but I'd save them as metadata, and I'd let people decide how they want them presented, for exampled with regard to casing.
For example, a variable holding a.. users actions per second.
Say I've set up my editor for camelcase, I'd type in userActionsPerSecond,
the editor would save the metadata as user,actions,per,second.
Another programmer prefers underlines, their editor presents it user_actions_per_second, and a third user prefers it space seperated, but with a box drawn around it to indicate it's one thing and it's presented [user actions per second] or whatever.
I'd maybe add a comment as metadata to the variable too, the comment could easily be shown above the variable, just as it is today, but they can never get detached by someone adding another item between the comment and the variable.
Some people would prefer no comments at all, others want them always visible, others want them visible on mouse over.. lots of options.
I know I _can_ have almost all I'm asking for, but the hoops we jump through to get them due to storing program descriptions (source code) as plain text directly, with no really good way to add additional information to it (see the many horrors we have with annotations in different languages, for instance javadoc where comments are abused to embed a different kind of language carrying metadata which is only incidentally coupled to what it tries to decorate).
Instead of doing tricks to separate content and presentation, it should be the default approach.
Our entire infrastructure, grown organically over the past what, 40+ years, arrange itself around individual bytes arranged in text files, arranged in folders.. And I get that thinking this must be the best and final form is easy, because, honestly, software development tooling and infrastructure is some of the best and most solid software ever written, no doubt because it's written by the people using it.
It's not like I've talked with god and come with a list of solutions to problems nobody is having, only that, while I'm not really dissatisfied, I've stumbled into this way of thinking about building programs, it's partly due to some brain damage I must have gotten from learning and thinking about lisp, and while lisp does lots of things wrong, it gave my brain this twist that the models we hold of how to do things can be very different from what we're used to.
I think it's worth at least once in a while, to put some ideas on the backburner and entertain ourselves by imagining other approaches other approaches than arranging individual characters in files, which is the lowest form of computer interaction you can imagine outside of writing bits and bytes directly into memory cells. And it's a bit ironic that as we do this very high-level, high abstraction work that is composing a program, using the most primitive interaction with the machine that's still available through user-programs: manipulation of the arrangement of bytes in files.
If you look at modern development, there's still a fairly noticeable part of it that's centered about ascii-art, either directly by hand, or by instructing the editor to do it, and there's a lot of procedure that's there not to describe programs, but to help derive the programs out of the source texts.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by Brajeshwar on Friday July 25, 2025 @11:37PM
(#44691115)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by wodenokoto on Saturday July 26, 2025 @03:02AM
(#44692014)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by donatj on Saturday July 26, 2025 @03:09AM
(#44692048)
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.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by cowboylowrez on Saturday July 26, 2025 @01:50PM
(#44695817)
I would like to congratulate my fellow space using elite on our complete and total victory. I'm also now considering how to use the now empty spot in the ascii chart, I'm thinking we can use tab as an alternative pipe character as I'm tired of hunting for the existing pipe key with every friggin new keyboard I buy.
Re:The Tabs vs. Spaces war is over, and spaces have emerged ...
by hiAndrewQuinn on Sunday July 27, 2025 @04:33AM
(#44699791)
One of the best side effects of a space victory is that Tab Separated Values are a much nicer format than Comma Separated Values if you aren't bothering to use a proper library since \t appears materially much less often than , in most datasets of interest. (Which you should but, you know, just in case.) Just my two cents.
"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.
Sarcasm aside, if your editor can't recognize indentation or adjust indentation according to arbitrary preferences, you really need to update your toolset.
(Allow me to reply to this age-old argument with the age-old counter argument...)
But you also have to decide at what point to hard wrap each line based on a max line length, and you can only do that based on some choice of tab size. Anyone with a different tab size preference would see the right column wandering depending on indentation level. This invalidates the only advantage of tabs (assuming file size is no longer a concern).
A common retort is that each reader's auto format (or soft wrapping) can sort out the wrapping. But if each coder is going to reformat the code anyway then they get the benefit of choosing their own indentation level regardless of tabs vs spaces.
I think that you should not be doing this, for the same reason that you should use tabs. It allows the user to select whichever hard wrap point (if any -- I generally choose to not have one) they prefer.
But all of this sort of thing is pointless debate these days, when it's pretty fast and easy to preprocess the files to match your preferences prior to editing.
And then have merge conflicts between people who set different hard wrap points? Did you mean to say soft wrap point?
This argument fails by default if its not understandable.
Then someone else loads it with tab width set to 6:
Now the max column width of a line depends on the syntactic indentation level of it! Any width you choose for your editor will either overflow for some deeply nested lines or waste loads of space on less-nested lines.Of course it's not a real concern because your editor can probably automatically fix this. But if it's clever enough to do that, then the supposed extra flexibility of tabs is actually possible with spaces anyway.
Exact and strictly enforced max line length IMHO unnecessary. Too wide code is hard to read, too narrow too but in between there is a wide range of acceptable values. When possible I treat max length as a recommendation, not hard limit.
When you don’t have a hard limit it’s not a problem if code added by someone who uses visual tab width 2 will go over 78 characters in the editor which tab width set to 4. Equally it’s not a problem when someone using 4 will make a line break sooner than one using 2.
I don't know why it was 8, but it was.
Note that nesting is a much bigger issue in a language like C where you have to clean up after yourself, in most languages having a lot of nesting in a function isn't an issue.
It's probably the main reason why they're so controversial.
Not sure why people are so obsessed with having power of 2 spaces, can anyone explain that? Why argue over 2 vs 4 when you can have 3 for everything? I think 4 is better than 2 since 2 is too hard to track, but 3 obviously is better than 4.
(golang converted me to tabs too)
> Is it truly over? ;-)
While I run into fewer that do this nowadays, it still reminds me that with tabs, What I Write May Not Be What You See, which can lead to readability issues, which I feel is a solid enough point against tabs that I've switched.
I write code so it is easy to read, and spaces are better for that than tabs, so now I use tabs. ¯\_(ツ)_/¯
This is a very confusing final sentence. :)
Which is the right thing to do. When did the tab stopped having 8 spaces ?
That's how TFA reads to me. Never give up, never surrender.
The fact that people choose to reject this does not change the reality.
[0] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/t...
[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/e...
(*) Tabs only and no hard wraps, only soft wraps.
It will be over when we finally format code at read-time so that we respect the viewer's preferences, instead of at save-time to reflect the authors'.
Read-time revisions to spacing need, only, to change the non-intentional elements of spacing -- indent depth is a very good candidate for this (hence the tab character!).
Realistically tabs are best when you're alone and spaces are better when you're collaborating IMO.
> 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...
Indentation != spacing.
And thats all the argument i need. I dont understand why people argue with consistent text layout for all-spaces. You can use tabs to indent and spaces to align after that, in most cases.
In practice this is difficult; since the characters are invisible by default, people will inevitably mix up the two. Looks like the industry standard is to give up and use spaces everywhere, unless strict and mandatory tooling exists.
But the new problem is linters and formatters don't understand alignment, so they always want those extra spaces removed, making a mess.
I’m not sure what are you referring to, could you give an example?
What? Well aligning e.g. a long SQL statement is asinine and does not improve readability??
perhaps the issue is the specific choice of fonts. the author in that article exclaims that if you allow proportional fonts then any font can be a programming font, while the author of the following claims otherwise and set out to make his own proportional font that is suitable: https://timgord.com/2024-01/lisnoti-a-proportional-font-that... other such projects are https://input.djr.com/info/ and https://go.dev/blog/go-fonts
one issue is that of distinguishing similar characters, which the above projects try to address while some people claim it's not an issue at all: https://alexkutas.com/posts/non-monospace-font
there is also the issue of alignment mentioned in the first article, that can possibly be addressed by limiting font widths multiples of the smallest width.
but there is still the issue of interacting with other programmers, mentioned in this article: https://nelsonslog.wordpress.com/2021/09/12/proportional-fon... we would all have to agree on the same font if there is any kind of alignment needed apart from indentation. right now we can say that you can choose any monospace font, and things will look as intended, but with a proportional font things will look different depending on the font choice. whether that is an issue or not needs further study i think.
more discussion of pros and cons can be found here: https://stackoverflow.com/questions/218623/why-use-monospace...
"Distinguishing similar characters" is just as much of a concern for me when I'm editing technical documentation as when I'm editing source code. Once again, the Go font has served me well. Previously I used some other humanist style font from from the Ubuntu people that had that classic IBM slash-through zero. Some fonts have overly-aggressive ligatures and such, but those fonts should not be used in any technical context, source code is not special.
Alignment is a non-issue because wanting alignment is bad. There, solved that ;-) Arbitrary diff noise over multiple lines because you added one line at the end is a problem, not a goal!
I interact with other programmers just fine. Your linked article seems to be re-engaging in the tabs-vs-spaces flamewar in an era of gofmt rustfmt et al. It's a total non-issue.
Give it two weeks.
Unless you're trying to argue that your code is a tsv file then tabs is the wrong thing to use.
Nobody cares that phone calls happen over fiber now instead of telephone lines. So, same should apply to teletype. Nobody is going to care you're reading this over fiber instead of a telephone line.
Now, people do care if they're trying to read a csv document and somebody didn't quote their commas within strings and now the values are in the wrong columns which could've been avoided by using tabs to store tabular data.
So you're ok if your text editor interprets the LFs of a Unix text file as mere line feeds, without ever going back to the beginning of the lines?
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.
It's hard to view your opinion as unbiased when you think this is how people indent with spaces.
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.
I've also never heard anyone argue that someone else should configure some different tab width, is there a specific language ecosystem you were in that had these insane takes?
> Tabs are 8 characters, and thus indentations are also 8 characters.
Yes, tabs are used for alignment as well.
To quote the OpenBSD style guide:
> Indentation is an 8 character tab.
The GTK source code uses tabs when the number of spaces for indentation >=8. This goes against their coding-style document, but if you don't have tabs set to 8 you'll find the indentation broken.
git is the same: although it prescribes tabs if you don't set the width to 8 you'll find broken alignment everywhere.
But it’s not what I mean. When navigating using the arrows it just breaks the flow because suddenly you “don’t move anymore.” Hard to explain, but it is real.
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.
As found the hard way when one day we updated the version of the Go formatter, and much of our nice comments needed to be redone. Thanks Go formatter team (yes, that's being sarcastic).
[1] https://www.emacswiki.org/emacs/SmartTabs
Of course that will always be a compromise, either people who use narrow tab widths or those who use wide ones will have a (slightly) suboptimal experience.
And maybe you can enforce no alignment, but that's a hard fight to win.
And as far as tabs for indentation and spaces for alignment, I've found no practical way to enforce this via tooling/linting. And a rule without enforcement becomes inconsistent, which is how we get files full of mixtures of spaces and tabs, which is how people get frustrated with tabs, and we decide to throw it all out.
And inevitably, that's part of how spaces "won"
Addind a comment with the right amount of tabs as a table header and align all fields with spaces after the tabs would do the trick.
To take this example from a sibling post:
Many people will wind up doing this: And then your alignment is all messed up if you have a different tabs setting.Checking for that requires something more like a linter with a detailed understanding of the syntax parse tree.
Anyhow, if code reviewers always use tools that highlight the tabs during the reviews, there's a good chance to catch these things.
Maybe you could also have the tab width set randomly at every review, to make these horrors stand out
For example, I considered writing a small Awk program to check C code in response to another poster’s complaint about lack of tooling, but then quickly came to the conclusion that, with C’s insistence that (say) /??/<newline>* is a valid comment starter, getting this exactly correct probably does need an actual lexer that would go character by character. That sounded like it wouldn’t fit in an HN comment, so I stopped there.
(That said, that’s as far as you’d need to go in the majority of cases. A dishonorable mention is warranted for languages that use the same character as an operator and a paired delimiter simultaneously, that is C++, Java, C#, TypeScript, and Rust with their abuse of the less-than and greater-than symbols, because that would in fact require a parser. In C++ especially, you’ll need full semantic analysis with template expansion, name resolution, and consteval evaluation. Because C++.)
Yet you probably don’t actually need to be that accurate, do you? The majority of syntax highlighters aren’t, and they are still useful. You can usually afford to say that code that perverse deserves to lose, and in return I expect you should be able to gain a fair amount of language independence, which could be worth the tradeoff.
So instead of checking if things are aligned with what they should be, you would just check they are aligned with something, like a left word boundary preceded by a delimiter, and so on. I can already see unpleasant corner cases after thinking about it for a few minutes, but it doesn’t look hellish yet, it looks something like you could experiment with over a weekend to see if it was viable.
No wonder why spaces "won"
I am fine with a (single) space being an important part of syntax, just don't use more than 1 please.
But if you must you can start with a new line and the right indent.
Accessibility is not a joke.
See, I can do it too. This is why there is an ongoing discussion. Because there is no clear cut answer, just opinions.
At least this article brings some data to the discussion.
but that's the whole damn point ... I like substantively indented code, you prefer minimally indented, we should both be happy (and we can be, by using tabs).
This is often why dev teams have more specific style guides that include things would be considered bike-shedding, like how many spaces an indent is.
On punch cards, teletypes, or VGA CRTs? Absolutely. On SVGA CRTs? Probably. On anything modern? No.
(I'm fully converted to Team Spaces, but I also don't get too wrapped up in treating what seem to be soft limits as hard limits.)
Why not bikeshed the bikeshedding?
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.
[TAB][TAB][TAB]ShortTypename[SPACE][SPACE]variable_name
[TAB][TAB][TAB]LongLongLongTypename[SPACE]variable_name2
ps. the [SPACE] counts above are illustrative, not accurate.
Tabs are for indentation, to align the beginning of the line, later on if you want to align text somehow, use spaces. You probably shouldn't align lines with different indentation (I align rarely so I can't remember ever to do that).
Having two different invisible characters to represent empty space is objectively worse. Just use space, and the tab key to insert multiple spaces. Simple. Use .editorconfig and a formatter to enforce the commonly accepted standard. Done.
Sadly you still have to make exceptions for Makefile, Go, etc. that expect a mixture of hard tabs and spaces. Otherwise hard tabs are not allowed in the codebases I manage, and are replaced by the formatter.
As an example, and I hope this is not a new information for most, in many text terminals it does not mean "advance forward to a multiple-of-8 position", it means "advance forward to next tab stop", and you can arbitrarily set those (e.g. HTS/TSC on vt220)
If tabs or spaces are mandated at editor level, how are you editing Makefile or TSV files?
I really do not understand anyone, who is against having support for any possible indentation, controlled by the user as is necessary for each use case.
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.
There are still situations where it’s annoying, mostly when navigating the code using the arrow, moving from one location to another using the arrows, I won’t add a key modifier right in the middle of moving the cursor, it just doesn't make sense.
Ctrl-space moves the cursor by “words inside words,” e.g. in theBestVariable, will go between “the” and “Best.” However it conflicts with the system ctrl-space that switch space. Not really an issue, because ctrl-shift-arrow will do the same word inside word move, but extending selection. In the end we can select until the desired location is reached, then hit a single left or right arrow to deselect and we’re there.
Also, any use of hard tabs breaks diffs, which should make tabs a non-starter.
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.
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.
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.
Generally, you shouldn't have all that many indents in your function. Using this would be a good visual clue to a beginner that maybe they need to break out their function into multiple functions.
Are you a superior 4-spacer or is that too much for your weak IDE on that 4:3 screen?
It doesn't work for indent-sensitive languages like Python, but it works for most of the other major languages.
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
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.
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.
You would have variable names not saved? They don't matter for the future maintenance of the program?
You can have most of what you ask right now, the further step most relevant here would be to not indent anything in the saved code; with most languages you're free to do it, and it's feasible to have an editor display it with the indentation you prefer; however it could only make sense if there's no way to have your team agree on an indentation style, there's too many fldownsides with hardly any advantage otherwise.
You're always free to have your editor ignore the spaces and display the code the way you prefer, anyhow.
But it's probably not always possible to deduce how things should be aligned.
For example, a variable holding a.. users actions per second. Say I've set up my editor for camelcase, I'd type in userActionsPerSecond, the editor would save the metadata as user,actions,per,second. Another programmer prefers underlines, their editor presents it user_actions_per_second, and a third user prefers it space seperated, but with a box drawn around it to indicate it's one thing and it's presented [user actions per second] or whatever. I'd maybe add a comment as metadata to the variable too, the comment could easily be shown above the variable, just as it is today, but they can never get detached by someone adding another item between the comment and the variable. Some people would prefer no comments at all, others want them always visible, others want them visible on mouse over.. lots of options.
I know I _can_ have almost all I'm asking for, but the hoops we jump through to get them due to storing program descriptions (source code) as plain text directly, with no really good way to add additional information to it (see the many horrors we have with annotations in different languages, for instance javadoc where comments are abused to embed a different kind of language carrying metadata which is only incidentally coupled to what it tries to decorate).
Instead of doing tricks to separate content and presentation, it should be the default approach.
Our entire infrastructure, grown organically over the past what, 40+ years, arrange itself around individual bytes arranged in text files, arranged in folders.. And I get that thinking this must be the best and final form is easy, because, honestly, software development tooling and infrastructure is some of the best and most solid software ever written, no doubt because it's written by the people using it.
It's not like I've talked with god and come with a list of solutions to problems nobody is having, only that, while I'm not really dissatisfied, I've stumbled into this way of thinking about building programs, it's partly due to some brain damage I must have gotten from learning and thinking about lisp, and while lisp does lots of things wrong, it gave my brain this twist that the models we hold of how to do things can be very different from what we're used to.
I think it's worth at least once in a while, to put some ideas on the backburner and entertain ourselves by imagining other approaches other approaches than arranging individual characters in files, which is the lowest form of computer interaction you can imagine outside of writing bits and bytes directly into memory cells. And it's a bit ironic that as we do this very high-level, high abstraction work that is composing a program, using the most primitive interaction with the machine that's still available through user-programs: manipulation of the arrangement of bytes in files.
If you look at modern development, there's still a fairly noticeable part of it that's centered about ascii-art, either directly by hand, or by instructing the editor to do it, and there's a lot of procedure that's there not to describe programs, but to help derive the programs out of the source texts.
[1] https://www.unison-lang.org/docs/the-big-idea/
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
Just use tabs!
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.