3 ms·
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").
by saagarjha 6y ago
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").
- geofft 6y agoYeah, 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.)
- alexhutcheson 6y agoResult 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 https://abseil.io/docs/cpp/guides/status
- mlindner 6y ago> 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.
- alexhutcheson 6y agoNo, 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-or-exceptions 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.