Re: [TECH TOPIC] Rust for Linux

Miguel Ojeda
2021-07-08T00:28:00Z

On Thu, Jul 8, 2021 at 1:41 AM Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> I don't think anyone ever claimed that C++ offers the same kind of
> compile-type checks that rust does, so there's no disagreement there.

My apologies if I have misinterpreted your claims (or those of Bart).

The thing is, claims such as "C++ is as safe as Rust, you just need to
use modern C++ properly!" are still way too common online, and many
developers are unfamiliar with Rust, thus I feel we need to be crystal
clear (in a thread about Rust support) that it is a strict improvement
over C++, and not a small one at that.

In any case, please note that I am not a Rust "fan" or "believer"
(somebody mentioned that word) -- if the C committee opens up to add
these kind of things, I will gladly work on that as my free time
permits. But Rust works, and it works today, and the language brings
many other things too in a fairly well-designed package (though it is
not perfect either).

> The discussion has drifted from rust in the kernel to features that C is
> missing and that make our life painful when it shouldn't be. Some of
> those features are fairly basic (such as features that would allow
> implementing RAII idioms with a syntax that wouldn't make all developers
> want to jump through the window), and available in multiple languages,

The C committee is looking into adding `defer`, so you may actually
get RAII in C ;)

They are also looking into adding lambdas (with a similar syntax to C++'s).

> This being said, I don't think C++ would be a particularly good
> alternative even for that limited goal, as there could be more drawbacks
> than advantages. Furthermore, if we're considering supporting a second
> language in the kernel, it would likely be best to pick a language to
> would bring us as many benefits as possible. Rust is a good candidate,
> even if I'm not convinced at this point that the gains outweight the
> costs (especially when it comes to the disturbance to the development
> flow, see the discussion in this mail thread about subsystem-wide or
> kernel-wide changes). Time (and discussions) will tell.

This is fair, thank you.

> Speaking of sweeter syntax, in the "if only I had a time machine"
> category, I wish rust would have picked a syntax closer to C when
> departing from it wasn't strictly necessary :-(

Interesting -- in which regard? i.e. it is actually quite close, their
designers were clearly going for something relatively familiar to
C/C++ programmers (at least in its current state, not the very early
design iterations of Rust).

Cheers,
Miguel