Tabs are 8 characters, and thus indentations are also 8 characters. There are heretic movements that try to make indentations 4 (or even 2!) characters deep, and that is akin to trying to define the value of PI to be 3.

I am in love with this awsome document; I love its guidelines, and coding conventions.

However, when Rust was introduced into the kernel, they butchered these beautiful guidelines, I know it’s hard to look at such heretic actions, but you have to see this:

The default settings of rustfmt are used. This means the idiomatic Rust style is followed. For instance, 4 spaces are used for indentation rather than tabs.

How can this even relate to the ideology of the first document? I am deeply saddened by these new rules.

I know this is “The Rust experiment”, but this must be fixed before it’s too late! This has to reach someone.

A counter-argument might be:

The code should be formatted using rustfmt. In this way, a person contributing from time to time to the kernel does not need to learn and remember one more style guide. More importantly, reviewers and maintainers do not need to spend time pointing out style issues anymore, and thus less patch roundtrips may be needed to land a change.

And to that I say that rustfmt is configurable per project, and if it isn’t, then it has to be. Doesn’t something like .editorconfig exist?

Edit: I think I read enough comments to come up with a conclusion.

At first, forcing another language’s code style upon another sounds backwards, but both styles are actually more similar than I originally though, the kernel’s C style is just rustfmt’s default with:

  • 80 character line.
  • 8-space hard tabs.
  • Indentation limited to 3.
  • Short local-variable names.
  • Having function length scale negatively with complexity.

The part about switch statements doesn’t apply as Rust replaced them with match.*

The part about function brackets on new lines doesn’t apply because Rust does have nested functions.

The bad part about bracket-less if statements doesn’t apply as Rust doesn’t support such anti-features.

The part about editor cruft is probably solved in this day & age.

The rest are either forced by the borrow checker, made obsolete by the great type system, or are just C exclusive issues that are unique to C.

I left out some parts of the standard that I do not understand.

This all turned up to be an indentation and line-size argument. Embarrassing!

*: I experimented with not-indenting the arms of the root match expression, it’s surprisingly very good for simple match expressions, and feels very much like a switch, though I am not confident in recommending to people. Example:

match x {
5 => foo(),
3 => bar(),
1 => match baz(x) {
	Ok(_) => foo2(),
	Err(e) => match maybe(e) {
		Ok(_) => bar2(),
		_ => panic!(),
		}
	}
_ => panic!(),
}

  • DoodsOP
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    6 months ago

    But how else are you going to enforce a specific line size? (I remembered formatters exist, don’t mind this)

    I was thinking of something else, something better, but I do not know if it exists, I’ll say it:

    The thing I don’t like about space indentation is how you can individually delete and select each space while editing, which is aesthetically unpleasing and error prone, which makes a formatter necessary. Using spaces is also weird in the sense that indentation is supposed to be a block of continuous whitespace, not little things joined together.

    However, using tabs creates inconsistent results when copying code to a browser or online view in general.

    My idea is: configure your editor - ideally through .editorconfig - to interpret 8 continuous spaces as a tab, and display them as such, and when the time comes to save, you tabs are actually saved as 8 spaces, which solves both the aesthetics and portability problem.

    Is this possible? does this already exist? I do not know.

    Edit: I forgot your second paragraph

    Maybe it’s because I use 18.5 inches and 1366x768*, but an 80 character long line already makes me shift my eyes in a way I prefer not to. Low line length is just comfortable.

    It’s worth mentioning that I recently increased my coding font size to Neovide’s default (from 12 -> 14), which made me realize why people do things like Ok(()), sticking parentheses look weird on low font sizes.

    I believe that limiting indentation - to 3 - makes code better, an opinion I based on the Linux guide and a video with good animations.

    *: I only needed to fix it once in the last 10-14 years; I don’t remember anymore. Why change what’s working? it’ll only make playing video games awkward needing to pipe everything through Wine’s FSR.

    Speaking of that one repair job, the repairman just replaced all of the monitor’s insides with another model’s, and now I cant tweak brightness or contrast or use anything but auto adjustment.

    which you happen to have configured to 8 spaces locally because you’re some sort of masochis

    Edit II:

    which you happen to have configured to 8 spaces locally because you’re some sort of masochis

    8 space tabs have been the default since the K&R days.

    Tabs being 8 spaces has been the norm since the typewriter (actually not)

    Despite the fact that five characters were the typical paragraph indentation on typewriters at that time, the horizontal tab size of eight evolved because as a power of two it was easier to calculate with the limited digital electronics available.[citation needed]

    Why do people hate them that much nowadays?

    Edit III:

    I think the intersection between people who have a low resolution, narrow aspect ratio screen and people who code in rust is significantly lower than C or C++

    Maybe you’re right, I should ignore the sunk cost of reading a 3rd of The Rust Programming Language book, and leave Rust to the cool new generation with their HD displays, and non-DIYed setups)**, and social media usage, and their computers are fast so just write it in javascript and forget about older systems and 3rd world countries and the poor and environment hurting emmisions, and just go learn C. I always felt like I fitted in with people 1 or 2 generations older. (I am not actually going to do that, that’s a joke)

    **: BTW, my speaker’s left channel is an old radio that is connected to my speaker’s cable. My left speaker broke when I pushed it off the table, served for a good 8-12 years; I still don’t remember anymore.