Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Check out out slides 20-21 from Linux Security Summit 2019 - there are specific reasons why Linux didn't like C++ that don't apply to Rust. https://ldpreload.com/p/kernel-modules-in-rust-lssna2019.pdf

Basically, we think (and we hope Linus agrees) that Rust has the relevant benefits of C++ without the downsides that have so far kept C++ from being adopted. (It has other great features that C++ doesn't have like compiler-enforced memory safety, too, but I agree with you that RAII is a pretty important and obvious win for the kernel just by itself.)



I fail to see how Rust solves any of the issues in ways that don't apply to C++ (the solution largely seems to be "don't use those features").


Yeah, it's possible to write a disciplined form of C++ that abides by those rules, but I think it's important that the idiomatic form of error handling in Rust is returning Result types instead of unwinding, the standard library doesn't have coercions that allocate, etc. If you write some Rust code following a Rust tutorial, it would probably be kernel-suitable. That's also largelytrue of C but not of C++.

(And Linus noticed one of the big parts where Rust doesn't live up to this - the idiomatic thing for memory allocation failure is to unwind - and that's a solvable problem.)


Result types can be just as idiomatic in C++. The codebase I work in has exceptions disabled and uses absl::Status and absl::StatusOr[1] everywhere.

[1] https://abseil.io/docs/cpp/guides/status


> Result types can be just as idiomatic in C++

If it `can be idiomatic` it means it's not currently idiomatic, and C++ isn't really heading in that direction. There's also a vast suite of C++ programmers out there to who it's very much not idiomatic and downright foreign. So if you're going to fight against how everyone else writes the language, it's best not to use the language.


No, by “can be idiomatic”, I meant “is already idiomatic in many codebases”. To name one prominent example among many, LLVM disables exceptions and requires that errors be returned as a value: https://llvm.org/docs/CodingStandards.html#do-not-use-rtti-o....

Disabling exceptions isn’t “fighting against how everyone else writes the language” - it’s pretty common and well-supported.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: