r/linux • • Apr 14 '21

Kernel [RFC] Rust support in the Linux kernel

https://lkml.org/lkml/2021/4/14/1023
608 Upvotes

316 comments sorted by

View all comments

0

u/[deleted] Apr 14 '21

[deleted]

17

u/soruh Apr 14 '21

We decided to go with Rust's idiomatic style, i.e. keeping rustfmt defaults. For instance, this means 4 spaces are used for indentation, rather than a tab. We are happy to change that if needed -- we think what is important is keeping the formatting automated.

→ More replies (9)

11

u/Zethra Apr 14 '21

If you're not familiar with Rust's tools. The official former does default to 4-space but that can be changed to tabs or whatever.

→ More replies (4)

10

u/inamestuff Apr 14 '21

I have to agree, very dumb choice.

I mean, even if the Rust team has a very weird fetish preference for 4-space indentation, that shouldn't be promoted as the default.

I've seen endless discussions about how many spaces should be used when the solution is as simple as "use a semantically meaningful tab", so that anyone can pick their preferred value. And I'm not even taking into account accessibility...

25

u/Unicorn_Colombo Apr 14 '21

I will take default 4-pace identation any time, thank you.

I had to wade through code that used what it looked like a random indentation. There was 3, 4, 7 and probably others. And that was Python of all things.

18

u/jarfil Apr 15 '21 edited May 12 '21

CENSORED

5

u/inamestuff Apr 15 '21

Tab with a width of 4 is more modular, if your preference changes while time passes by you can just set a different width in the editor settings without touching the source code.

Tab are a very powerful yet simple abstraction that represents an indentation level. Using whatever number of spaces to indent code is just like using <div>s all over your HTML instead of semantic tags like <button>s.

9

u/[deleted] Apr 14 '21

I use a tabstop of 4 or 6 depending on my font.

It's like people don't even consider that not every monospace font has the same width.

11

u/inamestuff Apr 14 '21

Same, and I also used to indent with a width of 4 or more, but currently I'm using a width of 2, just because of personal preferences. No changes to the source code required, just a simple setting in the IDE/Text Editor and that's it - as it should be

0

u/natterca Apr 14 '21

I don't see why an editor couldn't do the same thing with leading spaces.

6

u/Autoradiograph Apr 15 '21

Of course an IDE can reindent your code, but that would change every line of the file unnecessary. Unless you're talking about virtually hiding certain spaces. But either way, that leads to a larger problem:

How can the IDE tell the difference between the spaces used for an indent from the additional leading spaces on that same line used for lining things up neatly?

The proper solution is to use tabs for indenting, then additional spaces for alignment of multi-line lines of code. Then people can set their preferred tab stop in their settings and everything just works.

7

u/dreamer_ Apr 15 '21

It shouldn't.

0

u/[deleted] Apr 14 '21

[deleted]

0

u/[deleted] Apr 14 '21

[deleted]

0

u/[deleted] Apr 15 '21

[deleted]

7

u/Autoradiograph Apr 15 '21

I think you're missing the whole point. People are saying they want an indent to look a certain width. If you change to a narrower font that indent will also look narrower. So if tabs are used instead, when they switch to a narrower font they can increase the tab width to keep indents looking the same because maybe that helps them understand the code at a glance easier.

→ More replies (2)

0

u/[deleted] Apr 15 '21

[deleted]

0

u/[deleted] Apr 15 '21

[deleted]

→ More replies (5)

0

u/[deleted] Apr 15 '21

Yes, and because thr font is not in the files, people ARE going to use different fonts, resulting in the described problems.

6

u/dreamer_ Apr 15 '21

I've seen endless discussions about how many spaces should be used when the solution is as simple as "use a semantically meaningful tab", so that anyone can pick their preferred value. And I'm not even taking into account accessibility...

Personally, I prefer tabs and do exactly this, but you need tooling in place to make the code correctly formatted, otherwise it's a hassle and a source of pointless discussions. Aside of this - StackOverflow polled the users a few years ago, something like 80% of programmers in the wild avoid/don't use tabs altogether.

-2

u/OsrsNeedsF2P Apr 14 '21

Do you not have an IDE?

6

u/[deleted] Apr 14 '21

I use vim, not sure if it qualifies as an IDE.

sw=6 ts=6 noet

6

u/[deleted] Apr 14 '21

It is the best IDE

2

u/MPeti1 Apr 15 '21

Well, an extensiible text editor that can be made to be an IDE, but not necessarily is one when not needed

3

u/[deleted] Apr 15 '21

With that argument you can call VSCode an IDE. No, there is something between an IDE and a text editor called source code editor and vim is (like Emacs, VSCode and Atom) one of them.