5 ms·
Could someone explain to me why you would want to add Rust to the kernel, without using the word "safe".
by sdfhdhjdw3 4y ago
Could someone explain to me why you would want to add Rust to the kernel, without using the word "safe".
- varajelle 4y agoConvenience of using zero-cost abstractions to get the same things done faster/easier?
- sdfhdhjdw3 4y agoThat's the guiding design principle of C++.
- webkike 4y agoRust is more fun to program in than C. I was a pure C guy before I learned Rust.
- dieortin 4y agoSurely being fun is not the best reason to add a language to a kernel.
- webkike 4y agoWell, the OP took one of them away, and other people are pointing out other reasons. It’s just one reason. But maybe I can elaborate a little further: it’s as fast as C, but more fun.
- pornel 4y agoLinus has commented that using C may eventually be an obstacle to attracting new contributors. Rust is attracting new developers and gaining mindshare. From Rustaceans' perspective C looks tedious and antiquated — not fun to work on.
- sdfhdhjdw3 4y agoReally? Is this the same Linus that has commented that he likes the fact that C turns people off, because people who get turned off that easily probably don't have the grit to contribute to the kernel, and so he doesn't want them anyway? (paraphrasing)
- webkike 4y agoWell, he certainly won’t lose that by switching to rust judging by the comments in this thread!
- pornel 4y agoThere's a difference. One comment was about having a language that will scare away amateurs, the other was about having a language that will not scare away valuable contributors. Besides, fighting with the borrow checker requires a lot of grit ;)
- sdfhdhjdw3 4y agoI don't know anything about Rust, but I've heard about fighting the borrow checker. I wonder - doesn't that mean that either the borrow checker is a bit shit, OR you're systematically doing something wrong and don't realize it?
- oconnor663 4y agoThe truth is definitely some mix of both of those things. There are cases where the borrow checker can't understand some code that everyone can agree should be allowed, and maybe a larger set of cases where there's some debate about what should be allowed. The 1.0 compiler was substantially worse about this, and the introduction of "nonlexical lifetimes" in 2018 was a major improvement, though there's still plenty more to do. One of the reasons that "fighting the borrow checker" is such a common experience, is that it can be hard to tell the difference between cases like "this doesn't work because you forgot a small piece of syntax" vs "this doesn't work because you need a special helper type to make it work" vs "this doesn't work because fundamentally Rust will never allow this to work". For example, sharing objects between two threads often requires the `Arc<Mutex<...>>` pattern, which is a combination of two different helpers, and beginners who've never seen that combination before are very unlikely to discover it on their own. But once you have some experience with common patterns, and you know how to avoid writing code that will fundamentally never work, compiler errors are much more likely to be helpful. A lot of people ultimately decide that "the compiler was right all along" and that their code is really better now that they've learned to satisfy the borrow checker. Personally, I think learning how to write Rust code is a helpful shortcut to learning how to write safe and correct C/C++, because the "borrow checker in your head" pushes you towards designs that work well in all three languages. But this is definitely a matter of opinion, not to mention extreme selection/survivorship bias, etc.
- monocasa 4y agoWhy should we constrain ourselves to not use the word 'safe' in the context of one of the most privileged portions of code running on a computer? Linus has made it pretty clear that it's why he's allowing it; it provides something above and beyond other system languages wrt to writing correct code while still working with the kernel's structure and requirements (with a little elbow grease).
- sdfhdhjdw3 4y agoThe reason why is asked "without the word safe" is that on HN rust seems like cargo cult, in the sense that the word "safe" is used as a thought stopping - after all, who is against "safe"? - and so its meaning is never really explained.
- adgjlsfhk1 4y agoThe meaning of "safe" is pretty straightforward. It means that you don't read memory that you have freed, don't read memory that you haven't initialized, and don't read or write memory that you don't own.
- adgjlsfhk1 4y agoBecause 3/4ths of the security problems in C code are memory errors which rust removes, while still providing the low level code necessary to write a kernel.
- jcranmer 4y agoRust actually does a (marginally) better job of being a low-level, almost portable assembler kind of language than C does. This isn't even really about things like undefined behavior (of which Rust still has quite a profusion), but in things like being able to actually pun types. Additionally, Rust is a newer language that has incorporated some of the past 50 years of programming language design lessons that C has not incorporated (and likely never will).
- sdfhdhjdw3 4y agoThis is not a bad answer.
- eigenform 4y agoThe compiler and language make it easier to unambiguously specify a program.
- josephcsible 4y agoCould someone explain to me why people need to breathe, without using the word "oxygen".