Linus Torvalds reiterates his tabs-versus-spaces stance with a kernel trap

motytrah

Ars Tribunus Militum
2,942
Subscriptor++
You would prefer XML, perhaps?

I don't love YAML. I simply view it as less bad than the other plausible options in a given space, for the most part.

For most application deployments I was just fine with stock .properties file. Couple dozen lines. Super clear what each line was for. No issues with tabs or spaces.
 
Upvote
2 (2 / 0)

motytrah

Ars Tribunus Militum
2,942
Subscriptor++
Lowly sysadmin here. Editing JSON files on a virtual console is a nightmare. YAML for all its short comings at least is easy to read and edit outside of an IDE.

Now don't get me started on dealing with an unfamiliar server in which nano is the default editor.
I agree, JSON is overkill and problematic. I haven't seen a compelling reason why YAML is better than stock .properties files.
 
Upvote
5 (5 / 0)

Spudster

Seniorius Lurkius
16
Subscriptor
I just can't understand why someone would want to hit a key sequence 2/4/6/8 times versus ONE time in order to accomplish the same effect. Extra bonus: A decent editor will allow configuration of that spacing for tabs so you can customize it to your preferences. Personally, I'm a tabs person, I have no hate for those who aren't. To quote the kids these days, "You do you, boo." In this context, this really is a personal preference issue, so there is no right or wrong answer.

As for the debate in relation to a code parser, I just don't get it. For as long as I can recall, most things I've ever used treat tabs, and spaces (and sometimes hard spaces*) identically as they were considered "whitespace characters." Honestly, as previously mentioned, if your parser is having issues with a tab, change the code, not the data.

* Hard spaces = chr$(255), or for the REALLY old farts, holding the alt key down while typing "255" on the numpad. The only time I recall this being an issue was back in ye olden days where hard spaces were allowed in filenames when regular spaces weren't.
 
Upvote
-7 (0 / -7)
Serious question, what actually are the benefits of using spaces instead of tabs?

The only one I can think of is that it ensures that the reader views the layout of the source code in exactly the same way as the original author intended.

Even then, I’m not entirely sure that has that much value. At least not with the languages I use - which isn’t Python.
Spaces are good for giving you RSI (Repetitive Strain Injury), or a muscular spasm akin to Parkinson's Disease, from hitting the space bar all the time.
 
Upvote
-9 (2 / -11)

AusPeter

Ars Praefectus
5,086
Subscriptor
For most application deployments I was just fine with stock .properties file. Couple dozen lines. Super clear what each line was for. No issues with tabs or spaces.
Genuine question. Can you store hierarchical and/or list data in a .properties file? Because in my one exposure to using YAML I ended up with something like:

Object1:
- Name1A
- Name1B
- Name1C
- etc

Object2:
- Name2A
- Name2B
- Name2C
- etc

I could consume this and generate an internal data structure that matched the YAML structure.

It looks like to me that a .properties file is simply a list of key/value pairs, so anything more fancy than that will require me to write code. And I really love this quote:

Unlike many popular file formats, there is no RFC for .properties files and specification documents are not always clear, most likely due to the simplicity of the format.
 
Upvote
4 (4 / 0)
Using blocks of spaces in computer programming, instead of using the specific character only intended for this purpose (tabs) reminds me of office administrators who make data tables in Microsoft Word with tabs or spaces (no CR/LF, they just keep adding spaces until the cursor comes around to the next line), instead of using actual tables.

Also somewhat maddening: the PHP FIG (Framework Interop Group) held votes on various language syntax standards several years ago. There were roughly equal numbers of votes for tabs vs. spaces. So one of the people in charge of the project, who personally favored spaces, decided to impose an edict that henceforth, standards-compliant PHP shall only use spaces (not tabs!) Could there be any clearer evidence that the group's governance model is broken?
 
Upvote
-4 (4 / -8)
If you're only thinking of indenting to denote scope, then yeah, the tabs people have a point. But scope is not the only reason we indent. Sometimes you want to break a line of code up into multiple lines, and want to align parts of it for readability. Like a function call or definition with many parameters, where you want every parameter on its own line, and want them to all line up.

So a tab person would be forced to use both tabs and spaces to get things to line up. Then the next tab person comes along, who has set their editor to 3-space tabs for some reason, and nothing looks right. But if everyone just uses spaces all the time you never have that issue.

But, I mean, look. The furor of the debate is out of proportion with the size of the harm. Programmers just tend to like things to be just so. It's one of the qualities that make people self-select for programming.
One thing that causes furor in this debate is that is some assumption, basically, that the other side is essentially doing stupid things. I think tabs are better than spaces if people use their tools properly, and I don’t think it is really up for debate, but I also don’t think people who are using spaces are, like, trying to do headstands while typing or something ridiculous.

There isn’t an alignment issue between different tab widths if you use tabs for indenting, and spaces for alignment. The way it works is, you indent with tabs as appropriate for the scope. That all happens on the left side of the row, before you hit any syntax. That’s where tabs go, they are the only thing that goes there, and that’s the only place they go. There aren’t any issues around variables or operators having different widths, because there spaces where tabs and variables go don’t overlap.

<tabs>var = eqn <spaces> ! Comments <tabs>longVar+= eqn2<spaces> ! Comments

As you can see, “tabs” can be any width, there’s no chance of an alignment issue. It gets pretty frustrating to have people describe this apparent problem, which requires us to do something stupid to have it, as if it is a real problem.

Similarly, some tabs supporters think that people are actually hitting spacbar a bunch of times to get the right number of times. I agree with them that tabs are better, but they are incorrect to assume the people using spaces are that stupid. Every ide worth using has the ability to automatically do the space indenting. I assume that is similarly annoying.
 
Upvote
3 (10 / -7)
I just can't understand why someone would want to hit a key sequence 2/4/6/8 times versus ONE time in order to accomplish the same effect. Extra bonus: A decent editor will allow configuration of that spacing for tabs so you can customize it to your preferences. Personally, I'm a tabs person, I have no hate for those who aren't. To quote the kids these days, "You do you, boo." In this context, this really is a personal preference issue, so there is no right or wrong answer.

Nobody, nobody is arguing against the tab button. We all like pressing tab to insert a large gap before our text. People who "don't like tabs" don't like the tab character, for various reasons.

One thing that causes furor in this debate is that is some assumption, basically, that the other side is essentially doing stupid things. I think tabs are better than spaces if people use their tools properly, and I don’t think it is really up for debate, but I also don’t think people who are using spaces are, like, trying to do headstands while typing or something ridiculous.

There isn’t an alignment issue between different tab widths if you use tabs for indenting, and spaces for alignment. The way it works is, you indent with tabs as appropriate for the scope. That all happens on the left side of the row, before you hit any syntax. That’s where tabs go, they are the only thing that goes there, and that’s the only place they go. There aren’t any issues around variables or operators having different widths, because there spaces where tabs and variables go don’t overlap.

<tabs>var = eqn <spaces> ! Comments <tabs>longVar+= eqn2<spaces> ! Comments

As you can see, “tabs” can be any width, there’s no chance of an alignment issue. It gets pretty frustrating to have people describe this apparent problem, which requires us to do something stupid to have it, as if it is a real problem.

Similarly, some tabs supporters think that people are actually hitting spacbar a bunch of times to get the right number of times. I agree with them that tabs are better, but they are incorrect to assume the people using spaces are that stupid. Every ide worth using has the ability to automatically do the space indenting. I assume that is similarly annoying.
If everybody followed that convention perfectly, it would be nice enough - but not notably better than just using spaces for most people. Yes, you could configure the depth of your indentation. That's about the only advantage I can see. But Hell is other People, and in no universe will people consistently use tabs without spaces before text, and no tabs in the middle of a line. At the end of the day we're all still stuck relying on pre-commit hooks to unmangle the code.
 
Last edited:
Upvote
5 (6 / -1)

fepp

Ars Scholae Palatinae
945
Subscriptor++
YAML is a plague trying to currently strike at every corner of programming and I absolutely HATE it! White space/indent delimited languages are bad enough but who the f*** thought it was a good idea for CONFIG files? What exactly was wrong with JSON? (I get why XML is annoying though)
At least YAML can have comments. Big plus in my book.
But yes, two-space indents that just have to be just right is a pain.
Block delimiters rule.
Python taught to world to accept whitespace as actual structure.
Only defense for whitespace-as-structure is that you cannot obscure logic with clever indenting.
 
Upvote
3 (3 / 0)

ScifiGeek

Ars Legatus Legionis
18,968
Tabs allow the programer to visually setup their own visual style, spaces do not. You can setup that a tab be visible as 1 to 8 characters, in a developer text editor.

Only with perfect unity, where everyone agrees, and no one ever inserts spaces. You tend not to get that unless doing machine formatting.

In the real world when you allow tabs, you get a mix of tabs and spaces, and that's a mess unless you use the same exact tab width as the codes author.

Which is probably why all the style guides we had at work had "Spaces only" policy. That way the code looks the same for everyone.
 
Upvote
8 (8 / 0)

Scribit

Wise, Aged Ars Veteran
106
You would prefer XML, perhaps?

I don't love YAML. I simply view it as less bad than the other plausible options in a given space, for the most part.

That brought back memories of one gig where I had to parse some JSON that was returned by a Cisco REST API. The blob it returned, once parsed, had a parameter that was... a JSON string that I had to parse. In there was another parameter that was a JSON string that I had to parse. In that was the parameter that I actually needed. Yes, that's right: three JSON parses to get at the parameter that I specifically needed to look at.

Whoever wrote the code that returned that abomination deserves to burn in Hell for eternity.
At least you could schema validate XML and the better toolchains were good at creating & analysing.

Anything more than 10 lines of YAML shouldn't be intended for manual editing, looking at you k8s!

JSON is a crap data contract. Yes you can human read/edit it, but you shouldn't need to do this for data flowing between services. And people write terrible JSON structures with no versioning and leave it up to the API consumer to correctly parse their shit.

Sometimes I miss ASN.1 & DER (Good sign I need to go get more coffee, as I don't miss naive parsers and buffer overflows)
 
Upvote
3 (3 / 0)

mrkite77

Ars Tribunus Militum
1,759
"eight-character tabs"

What's an eight character tab? I was under the impression that it's up to every text editor and any other viewer how many spaces to use to display a tab. I tell VS Code to use 4 spaces for a tab, and I am pretty sure I could get away with that editing kernel code.
Except 4 character tabs means you might go over the 80 column limit when your code is viewed with 8 character tabs.

(Although the 80 column limit was changed into a soft limit a couple years ago)
 
Upvote
0 (0 / 0)

torp

Ars Praefectus
3,369
Subscriptor
Spaces are good for giving you RSI (Repetitive Strain Injury), or a muscular spasm akin to Parkinson's Disease, from hitting the space bar all the time.

Your editor isn't set to automatically indent with spaces when you press tab? :)

We're talking here about the tab vs space characters, not the keys.
 
Upvote
6 (6 / 0)
Nobody, nobody is arguing against the tab button. We all like pressing tab to insert a large gap before our text. People who "don't like tabs" don't like the tab character, for various reasons.


If everybody followed that convention perfectly, it would be nice enough - but not notably better than just using spaces for most people. Yes, you could configure the depth of your indentation. That's about the only advantage I can see. But Hell is other People, and in no universe will people consistently use tabs without spaces before text, and no tabs in the middle of a line. At the end of the day we're all still stuck relying on pre-commit hooks to unmangle the code.
It depends on the project kinda, I think. On a proper project with a style guide and code review, just reject any patches that do it wrong.

It might not be better for most people, but it isn’t worse for anybody. And it is useful. For example, if I want to get a high-level overall view of the structure of my code, I can zoom out and set tab width to 8. Normally, I keep it at 3. The Linux kernel coding guide has it set to 8, with the justification:

Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations.

Now, some people will claim that having 8-character indentations makes the code move too far to the right, and makes it hard to read on a 80-character terminal screen. The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.
IMO, large tabs can be kind of annoying, but they are also good for scanning for these “more than 3 levels of indenting” messes, which need inspection, so having them flexible is really nice.

In a properly written program, converting tabs to spaces doesn’t just implement a preference. It destroys information about the programmer’s understanding of the control-flow of the program in a non-reversible way. It is a malicious thing to do.
 
Upvote
-2 (3 / -5)

rschroev

Ars Centurion
255
Subscriptor++
SQL:
Code:
SELECT u.id, u.name, u.email
  FROM users AS u
 INNER JOIN address AS a
    ON u.id = a.user_id
 WHERE a.state='CA'
   AND a.country='USA'
 ORDER BY u.id
;


What is wrong with that? I happen to have written SQL over the last 30 years with that same convention. And where did I learn that 30 years ago? The Oracle and IBM DB-2 manuals.
That style looks very weird to me in that it makes it seem as if INNER and JOIN are separate things, and that it puts ON and AND on the same level as INNER JOIN and WHERE.

I would format this statement like this:

Code:
SELECT u.id, u.name, u.email
FROM users AS u
INNER JOIN address AS a
    ON u.id = a.user_id
WHERE
    a.state = 'CA'
    AND a.country = 'USA'
ORDER BY u.id
;

Maybe it's just because that's what I'm used to, but to me that's much easier to read.
 
Upvote
4 (5 / -1)

el_oscuro

Ars Praefectus
3,129
Subscriptor++
Greetings friend. On behalf of my brothers and sisters, I invite you to the church of assembly language.

We care not for curly braces or significant whitespace, or tabs vs spaces. We do wear cowled robes, eat raw red meat, and write witheringly fast code.

Sure, you'll probably never finish another project for the rest of your life but you'll get to brag about how fast it would be if you did.

Kidding aside, I hope the tabbers and the spacers will find peace and harmony. If we can't solve that one, what hope do we have for the world's more substantial problems?
Well, I haven't coded assembly in about 30 years. But my favorite project was on the C-64.

I was a broke teenager and couldn't afford the macro assembler cartridge. So I wrote my own assembler in C-64 BASIC, which included support for address labels and the entire 6502 instruction set. Since the C-64 didn't have a text editor, I wrote a version EDLIN, also in C-64 BASIC.

Best $35 I didn't spend.
 
Upvote
8 (8 / 0)

Fluppeteer

Ars Tribunus Militum
1,652
Subscriptor++
There isn’t an alignment issue between different tab widths if you use tabs for indenting, and spaces for alignment. The way it works is, you indent with tabs as appropriate for the scope. That all happens on the left side of the row, before you hit any syntax. That’s where tabs go, they are the only thing that goes there, and that’s the only place they go. There aren’t any issues around variables or operators having different widths, because there spaces where tabs and variables go don’t overlap.

Unfortunately until you use some kind of tool (such as diff variants) that put anything at the start of the line which may or may not be wider than a tab.

<tabs>var = eqn <spaces> ! Comments <tabs>longVar+= eqn2<spaces> ! Comments

As you can see, “tabs” can be any width, there’s no chance of an alignment issue. It gets pretty frustrating to have people describe this apparent problem, which requires us to do something stupid to have it, as if it is a real problem.

It would certainly change the configuration I've generally met in tools. Particularly:

<tabs>foo = myfun(z * (17 * x + <tabs> 13 * y));

...where I can hit tab once on the second line and get indented to match the opening parenthesis - but I certainly wouldn't rely on all my tools being set up to distinguish spaces from tabs when doing so.

For what it's worth, the elastic tabstops I've been mentioning in these comments let you write:

<tabs>var<tab>=<tab>eqn<tab>! Comments <tabs>longVar<tab>+=<tab>eqn2<tab>! Comments

... and the tab spacing grows so columns on adjacent lines line up (which saves a lot of messing about when you get reallyLongVar added on a third line). Especially useful if you're writing assembly and want the operand arguments aligned. A real shame they're not more widespread.

Similarly, some tabs supporters think that people are actually hitting spacebar a bunch of times to get the right number of times. I agree with them that tabs are better, but they are incorrect to assume the people using spaces are that stupid. Every ide worth using has the ability to automatically do the space indenting. I assume that is similarly annoying.

Yes, that's just crazy. Hit tab once, or not at all if you find that less annoying to undo unnecessary indents when the IDE gets it wrong.
 
Upvote
1 (1 / 0)

benInMa

Ars Tribunus Militum
2,198
I could have sworn in 1998-1999 I got flamed for submitting a patch for a module that had tabs. When I was in college I was 100% a tabs guy. Almost all my code didn't have anyone else working on it so it was never an issue. It wasn't Linus who flamed me. I'd have remembered if it was him. I can't remember who it was, but it really turned me off from helping cause the flaming was WAY out of line relative to the offense. I had put in a solid week of work to write a device driver for a chip Linux didn't have support for, about 10k lines of code. The guy was saying he was going to come kill my mother or something horrible over the tabs vs space stuff.

Maybe different parts of the kernel for modules get to have different code standards?

Every single job I have ever had since graduation (25 years) has had spaces as the standard IIRC. Editors handle this so well now. At this point we've moved on to new types of stupid arguments. The project I'm on right now if you don't put a space after "if" before the condition that will literally break the build our code standards are so rigid. That is mostly to eliminate giant PR/MR stuff that makes code review hard, and we have good auto format tools to mostly get rid of the pain of writing whitespace in an exact way in language which do not care about whitespace.
 
Upvote
2 (2 / 0)

LimeJuice

Ars Praetorian
410
Subscriptor
What kind of maniac uses a proportional font to write code?
Someone who understands the importance of readability -- and that fixed-width fonts are less readable. That's why books, newspapers and this website use proportionally-spaced fonts.

Sure, it's not such a big deal if all your variable names are one or two characters -- but it's not the 20th century any more: use proper meaningful names for variables, clases etc. And write decent comments. All these things mean you need a more readable font.
 
Upvote
-11 (0 / -11)
Unfortunately until you use some kind of tool (such as diff variants) that put anything at the start of the line which may or may not be wider than a tab.



It would certainly change the configuration I've generally met in tools. Particularly:

<tabs>foo = myfun(z * (17 * x + <tabs> 13 * y));

...where I can hit tab once on the second line and get indented to match the opening parenthesis - but I certainly wouldn't rely on all my tools being set up to distinguish spaces from tabs when doing so.

For what it's worth, the elastic tabstops I've been mentioning in these comments let you write:
The Linux command “column” can do something like the elastic tab stop you’ve described, I think, if you pass it the -t argument it’ll look at all your columns and pick a column width so that they fit tidily. These aren’t really tabs though (although you could tell it that the column separator is the tab character).

I think the reason this isn’t built into more text editors is that it requires passing over the whole file to find the maximum width for each column, for the file. For this use-case in particular it could be interesting to just scan across the current screen though, or a limited space around it… You could get some annoying jumping as you scroll through a file, but that isn’t the end of the world.
 
Upvote
1 (1 / 0)

J.King

Ars Praefectus
4,390
Subscriptor
Someone who understands the importance of readability -- and that fixed-width fonts are less readable. That's why books, newspapers and this website use proportionally-spaced fonts.

Sure, it's not such a big deal if all your variable names are one or two characters -- but it's not the 20th century any more: use proper meaningful names for variables, clases etc. And write decent comments. All these things mean you need a more readable font.
I'll disagree with you there. Proportional fonts may make natural language more readable, but I've found they make machine languages deceptively more readable i.e. my brain is more likely to interpret something which is not quite a natural-language word in the code as something other than what is actually written.

While the advice of using clear symbol names is good, it's rare that the code I write is the only code I'm interacting with, and that's before you get into style guides (like Rust's) which advocate terseness.
 
Upvote
12 (12 / 0)
Someone who understands the importance of readability -- and that fixed-width fonts are less readable. That's why books, newspapers and this website use proportionally-spaced fonts.

Sure, it's not such a big deal if all your variable names are one or two characters -- but it's not the 20th century any more: use proper meaningful names for variables, clases etc. And write decent comments. All these things mean you need a more readable font.
Proportional fonts are intended to make reading comfortable not necessarily super legible. How many Ls and how man Is are in the line below? Answer fast!

lIlIIl
 
Upvote
6 (6 / 0)
I'm so dedicated to tabs that I actually write all my code in a spreadsheet, and then copy/paste it to a text editor before compilation! :biggreen:
You should really help out people who are using spaces to do their aligning by hand. They seem to have trouble with it. Whenever you see a project that uses spaces, run something like:

cat whatever.c | tr -s ‘ ‘ | column -t > tmp mv tmp whatever.c git commit -a -m “finally everything is aligned with spaces” git push
 
Upvote
0 (0 / 0)

Californian

Wise, Aged Ars Veteran
112
The key reason I switched to (and like) tabs is that it separates the content from the presentation.

As in, I can set the tab size on my editor to whatever number looks great for me (which is 2) - meanwhile others can set it to whatever number looks great for them.

[edit] I lied. I just checked and must have switched my tab size to 4 some years ago. Thankfully I don’t need to go back and update all my old code.
That's one big problem I have with tabs: if you want to align things vertically or have a fixed max line length, tabs aren't consistent and introduce unnecessary variability.

Also, I'm curious whether the author wrote this article just for engagement bait so we'd argue about this in the comments 😆
 
Upvote
2 (3 / -1)
I too am a filthy tabs person. And I prefer vi over emacs (though these days nano is common). I also put pineapple on pizza.
Actually EMACS was all the rage for a time until Clifford Stoll found that notorious hole. Long live VI and “set -o vi“ for command retrieval. Try this: barbecue sauce, ham, 1/4 Muenster, 3/4 Pepper Jack, pineapple and snippets of green onion.
 
Upvote
-1 (0 / -1)
Proportional fonts are intended to make reading comfortable not necessarily super legible. How many Ls and how man Is are in the line below? Answer fast!

lIlIIl
If the inability to distinguish between I and l is a huge problem for the project l think something much deeper is wrong.

Still though, I would like a font where the lower case l’s are little cursive loops.
 
Upvote
-3 (1 / -4)