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

ERIFNOMI

Ars Legatus Legionis
17,973
Goland had their own formatter, which had a bug in the early versions. Oh, what fun that was when your IDE reformatted one way and then you ran go fmt in your Makefile - and you wondered why the hell your git was showing all these changed files to commit. 😭

Maybe it wasn't even a bug, but just a different reading of the Go style guide. Not longer an issue anyway.
Not using the official formater is just stupid. Who in the god damn thought it would be a good idea to maintain an exactly equivalent formatter?
 
Upvote
4 (6 / -2)

clewis

Ars Tribunus Militum
1,848
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.
Interesting. I believe I developed that style independently. I've only ever used open sourced RDBMs. But it's entirely possible that I saw it somewhere, latched onto it, then retconned it to be my own invention.

I generally try to avoid writing SQL directly. But when I do, they're usually full page queries. The style is very helpful for developing the query. Like, it's really easy to move those WHERE clauses into the JOIN ON clause without having to do a lot of editting. That's also why the semi-colon is on it's own line instead of the ORDER BY. I also tend to write

SQL:
INSERT INTO users (id, name, email) VALUES
                  (1,'me','me@my.com')
                 ,(2,'you','you@my.com')
                 ,(3,'him','him@ymy.com')
;
for the same reasons.
 
Upvote
7 (7 / 0)

el_oscuro

Ars Praefectus
3,199
Subscriptor++
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
;
This is true, you ALWAYS use space indentation for SQL, because SQL has NO indenting structure to make it easier to read (it's technically just one line with all runs of spaces, tabs and newlines considered as a single space), and lining up the operands like you did is by far the best thing to do if you ever want to be able to read it again later.
Besides being easier to read, having SQL formatted like this can actually prevent some forms of SQLi. While the real solution for SQLi is bind variables and/or static prepared queries, I still see SQLi in new code. Most SQLi payloads rely on the -- end of line comment to discard the remaining SQL so the injection works. New lines will break that - and prevent the exploit from working.

So even when bind variables are properly used, having new lines and nicely formatted SQL strings can improve security - in the case of someone introducing a vulnerability later. It might be the only thing that prevents a data breach.
 
Last edited:
Upvote
3 (4 / -1)

arsisloam

Ars Scholae Palatinae
1,402
Subscriptor
Removes pointless characters that don't add information.

Strictly enforces good layout.

And so is easier to write and read.
People who like loose syntax usually say it's more expressive. It's like I'm always telling my friends, "Wow, this code was written so expressively. It sure is easy to read and maintain!"
 
Upvote
5 (5 / 0)

Riddler876

Ars Scholae Palatinae
1,372
We're on page 5 of this thread and it is a prime example of Religious Wars in coding and software development.

The zeal and righteous certainty displayed by some posters (you know who you are - and are probably proud of it) at the level of dogma of topics more akin to the "sandal vs gourd" fights in Life Of Brian is what makes me happy that I am approaching retirement age and can soon leave it all behind.

I'm certainly glad I don't have to work with some of those people (anymore - I certainly have had to in the past).

Between "the tab key is an outdated construct and should be abolished" to "Nobody that slings code for a living uses spaces for indentation". I'd pay money to get those 2 sides into an arena to fight it out!
That's a really common view. But no offence I actually really hate that attitude.

In between the extremes of people arguing for lolz there's an actual real accessibility argument for people with various handicaps. I've tried to have this discussion on language standards debates when default styles are set and it's impossible to have a discussion about it because most people will chime in with that "lol it's religious war, close thread" attitude.

My point above was nobody would dare make that kind of comment in a thread about adding aria tags to a UI in order to better support screen readers. Of course we should discuss that. But god help you if you want to discuss making the code itself more accessible to people.

I appreciate that wasn't the purpose of your comment. But It furthers the narrative there isn't an actual concern in here that affects people we actually need to discuss.
 
Upvote
12 (14 / -2)

TheAxMan

Ars Scholae Palatinae
1,111
Subscriptor
I should have said, in that initial comment, that nobody used spaces for indentation WHEN IT MATTERED. I apologize for overgeneralizing, and while I thought I was being funny, I can see that it totally went flat, and that's totally on me. My apologies to everyone for writing an over-sweeping anachronistic generalization, though I will say in my defense it was mostly for comedic purposes, see toilet paper cascade comment. I included this apology back in the original article.

It almost never matters anymore, because hardly anyone codes in a character-mode text editor these days in a commercial or group setting, and mostly, good riddance. Go back a decade or so (say, to the point where Silicon Valley had a joke about it), and it was still a bit relevant.
Well, joking around about tabs vs. spaces is like throwing kipple into a koi pond.. what did you expect :D :D
 
Upvote
3 (3 / 0)

Marakai

Ars Scholae Palatinae
895
Subscriptor++
I appreciate that wasn't the purpose of your comment. But It furthers the narrative there isn't an actual concern in here that affects people we actually need to discuss.

Indeed it wasn't and if the focus was to address the concerns you raised, then we should be having those conversations and try to resolve them with a correct solution to the best of our ability and knowledge.

But that's not what these comments are about, sadly. As becomes blatantly obvious pretty quickly.
 
Upvote
9 (9 / 0)

clewis

Ars Tribunus Militum
1,848
Subscriptor++
Since I'm making people angry, I'll throw out one of my favorite experiments.

I was doing some complex data structure work with chaining. It was better that the indentation structure matched the data structure instead of the code. I no longer have access to the code, but I remember it to be something like
Code:
$data.open_tag('user')
           .add_element('name',$name)
           .add_element('email',$email)
     .close_tag() # user
     .open_tag('address')
           .open_array()
               .add_element('state',$state)
               .add_element('country',$county)
           .close_array()
     .close_tag() #address
;
Feels like I was doing something in XML?

Of course somebody auto-formatted the code about 7 days later.
 
Upvote
5 (6 / -1)
I've worked in software development for 20+ years, most of it in evil big tech (sigh...) but I have never worked in a codebase where tabs were permitted
Exactly. 40+ years here. Tabs only ever permitted in makefiles.

I got spanked one time for a check-in of files I edited using MS VC, which defaulted to tabs; my fault, didn't know, didn't check. I wondered "what does it mean, white space changes?"
 
Upvote
4 (7 / -3)
Since I'm making people angry, I'll throw out one of my favorite experiments.

I was doing some complex data structure work with chaining. It was better that the indentation structure matched the data structure instead of the code. I no longer have access to the code, but I remember it to be something like
Code:
$data.open_tag('user')
           .add_element('name',$name)
           .add_element('email',$email)
     .close_tag() # user
     .open_tag('address)
           .open_array()
               .add_element('state',$state)
               .add_element('country',$county)
           .close_array()
     .close_tag() #address
;
Feels like I was doing something in XML?

Of course somebody auto-formatted the code about 7 days later.
Javascript is a morass of things that are hard to read no matter how you format them. Lambdas especially are infuriating to read when you don't very carefully control where your closing parens, braces, and semicolons go.
 
Upvote
10 (10 / 0)

Riddler876

Ars Scholae Palatinae
1,372
Indeed it wasn't and if the focus was to address the concerns you raised, then we should be having those conversations and try to resolve them with a correct solution to the best of our ability and knowledge.

But that's not what these comments are about, sadly. As becomes blatantly obvious pretty quickly.
Indeed, not something we will fix on an ars forum! I'm just saying be careful because I'm not kidding I really have tried to have these discussions with the people who set the standards. That attitude bleeds straight through and you can't do it. It's very hard to even get the idea there's an important point in here taken seriously by anyone. The issue has too much baggage which does lead (with some justification I fully appreciate) to the view it's just a holy war.
 
Upvote
6 (8 / -2)

mert

Ars Tribunus Militum
2,086
Subscriptor
All code on my project is automatically run through a pretty printer; by automatic, I mean the act of saving the file triggers the pretty printer. The pretty printer is configured to convert tabs to spaces. The pretty printer handles everything: indentation, capitalization (super handy with a case-INsensitive language!), etc. Love the pretty printer!
 
Upvote
-1 (1 / -2)

CenterLess

Ars Tribunus Militum
2,587
Subscriptor++
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.
I believe the 3, the trinity is holy and sacrosanct. I consider 2 too dense and 4 too sparse. Practitioners of 1 or anything else should be considered beyond redemption.
 
Upvote
5 (6 / -1)

clewis

Ars Tribunus Militum
1,848
Subscriptor++
Javascript is a morass of things that are hard to read no matter how you format them. Lambdas especially are infuriating to read when you don't very carefully control where your closing parens, braces, and semicolons go.
I've had easy to read lambda's, written in Perl. But you really have to go out of your way to write readable Perl.
 
Upvote
6 (7 / -1)

kohukohunui

Seniorius Lurkius
30
Subscriptor
PS: with one exception that you mentioned: a couple of years ago, I gave TDD a try to see what the fuss was about.

Plenty of software practices have some merit or valuable ideas at heart. As does lighting on an aerodrome runway, but that's not the issue:

Their destination is a clearing in the forest that looks like a landing strip. But the only airplane present is a full-size wooden replica of a light aircraft. On one side of the strip lies a control tower made of bamboo. On the other sits a satellite dish built of mud and straw. Undeterred by the apparent lack of any actual aviation technology, some of the men light torches and place them alongside the runway. Others use flags to wave landing signals. Everyone raises their gaze to the sky in anticipation.

They wait. But the planes never come.
 
Upvote
2 (2 / 0)
I use those as well (in fact they ended up as my Trinity of Languages over the years, it just happened). Python is a dream to debug in something like PyCharm. C# - hmm, yes, used to use it a lot then just returned to it after some years and I find I'm frowning a lot. What they've done to the language is what I'd call "PL/1-ificiation" (yes, I still was exposed to that, barely). "we don't just need the kitchen sink thrown in, we need all the appliances and those from the laundry room too".

Still will take C# over Java.
Yeah.. We use vs code at work and and it sucks with python.

Yeah, c# over Java.

For what I do work wise I like go for giving me ease of doing something along with ease of doing it with decent performance.
 
Upvote
2 (2 / 0)

CenterLess

Ars Tribunus Militum
2,587
Subscriptor++
As someone who knows just enough about code to be dangerous...I'm completely confused why you would EVER want to use spaces instead of tabs. Tabs are an inherently superior way to separate things in every use case I've ever had for them. Would love to hear from someone here who actually likes using spaces.
I use an editor that automatically converts tabs to spaces. So even though I use the tab key, it just replaces the tab character with 3 spaces. I prefer it being spaces in the file and not tabs. Don't get me started on variable width fonts. There's a guy at work who does this and it looks like an unholy mess every time we stare at his screen when we're doing code reviews.
 
Last edited:
Upvote
4 (4 / 0)

Riddler876

Ars Scholae Palatinae
1,372
I use an editor that automatically converts tabs to spaces. So even though I use the tab key, it just replaces the tab character with 3 spaces. I prefer it being spaces in the file and not tabs. Don't get me started on variable width fonts. There's a guy at work who does this and it looks like an unholy mess every we stare at his screen when we're doing code reviews.
Up next: support for non-integer number of spaces
 
Upvote
21 (21 / 0)

kohukohunui

Seniorius Lurkius
30
Subscriptor
YAML is designed to be read and written by humans or computers.

JSON is designed to be read and written by computers.

Horses for courses.

JSON is not actually that great for computers either, which is one of the reasons binary formats like Protobuf, CBOR etc exist.
 
Upvote
11 (12 / -1)

Marakai

Ars Scholae Palatinae
895
Subscriptor++
Yeah.. We use vs code at work and and it sucks with python.

Yeah, c# over Java.

For what I do work wise I like go for giving me ease of doing something along with ease of doing it with decent performance.

Oof, there's another can of worms I'd rather not open in this thread.

Every so often I try VS Code. Load it with all the addons I need, all the language plugins I require.

And stop, go back to Jetbrains within days. I pay for my own universal sub and you can pry it from my cold dead fingers.

But some people will likely bring "Thou shalt use VS Code" torches and pitchforks.
 
Upvote
1 (3 / -2)

bpatb

Ars Centurion
244
Subscriptor
As someone who knows just enough about code to be dangerous...I'm completely confused why you would EVER want to use spaces instead of tabs. Tabs are an inherently superior way to separate things in every use case I've ever had for them. Would love to hear from someone here who actually likes using spaces.
Spaces all the way here.. have been that way since the early 90s. I set my tab stops in vim to be 2 spaces and all my code is indented as such. Why would I care if I can just view the code how I want to view it in vim? Well for the simple reason that vim isn't the only place I view code. Sometimes it's a more command sometimes cat, sometimes it's pasted into a rocket chat code block. With spaces my code will look the same no matter where it's viewed -- especially in places that don't let me configure the tab length.
 
Upvote
8 (9 / -1)
Oof, there's another can of worms I'd rather not open in this thread.

Every so often I try VS Code. Load it with all the addons I need, all the language plugins I require.

And stop, go back to Jetbrains within days. I pay for my own universal sub and you can pry it from my cold dead fingers.

But some people will likely bring "Thou shalt use VS Code" torches and pitchforks.
We for better or worse use office, azure, teams, ect. As for vs code I really just care about the standardization at work. One guy got permission to use a jet brains ide and I had to debug why a json file he created was breaking in a tool I wrote. It was because by default the ide was adding some stupid invisible char at the start of the file.

As for actual use, it's okay most of the time until it randomly breaks in some weird way.
 
Upvote
2 (2 / 0)
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.
This.
Having grown up with nested tables and innumerable <font> tags in HTML, I've been eternally traumatised by mixed content and presentation.
I don't want my indentation preferences to irritate someone else who has different ones or confuse diff tools because I've got my editor set up differently to someone else.
It's not just code editing, word processing too, where someone has used spaces for indentation is a real pain especially with proportional fonts if you change the typeface or size, and the alignment goes crazy.
 
Upvote
2 (3 / -1)

AusPeter

Ars Praefectus
5,216
Subscriptor
What kind of maniac uses a proportional font to write code?
I work with a PLC programming tool. The default font for the system is Times New Roman. Seriously. And nobody seems to care about readability (or code quality) except me. So in every installation of this tool that I encounter I sneakily set the default to Consolas.
 
Upvote
7 (7 / 0)

bthylafh

Ars Legatus Legionis
17,276
Subscriptor++
I work with a PLC programming tool. The default font for the system is Times New Roman. Seriously. And nobody seems to care about readability (or code quality) except me. So in every installation of this tool that I encounter I sneakily set the default to Consolas.
I sincerely wish that surprised me about the embedded world. I've heard horror stories, such as that of an enthusiastic young support tech just out of college who decided to update firmware on aaaaaallll the devices on a site he was helping to bring back up after a maintenance period. You can guess what happened next.
 
Upvote
-1 (0 / -1)

terrydactyl

Ars Tribunus Angusticlavius
7,915
Subscriptor
I clicked the Tabs vs Spaces link expecting to be transported to YouTube for an episode of Silicon Valley. Instead I was linked to an old Ars article. Disappointment. Clearly missed reference.
I remember that episode. The protagonist meets a girl. But the relationship was doomed. He's a tab person and she's spaces.
 
Upvote
3 (3 / 0)

ScifiGeek

Ars Legatus Legionis
19,089
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.

The problem I've seen is that even when tabs are chosen/allowed, there will always be people that mix in spaces. So while it may look fine at your specific tab setting, it won't work at other peoples specific tab setting because intermix of tabs and spaces only looks right at specific settings.

Where I've worked, we specified spaces only, and setting your editor to output spaces with the tab key, so aligned code was aligned for everyone.
 
Upvote
7 (7 / 0)