3 ms·
C++ semantics are no less safe than any other language with an “unsafe” mode. The difference is that C++ makes it convenient to write unsafe code, but that it
by hedora 8y ago
C++ semantics are no less safe than any other language with an “unsafe” mode.
The difference is that C++ makes it convenient to write unsafe code, but that it also makes it possible to write safe systems code at a much higher level of abstraction than any other language I’ve heard of (templates are Turing complete, and modern tooling makes them reasonable to work with).
So, the question is, what does Rust make C++ developers give up that can’t be achieved via C++ style guidelines?
Also, 10 years from now, when the state of the art of systems programming advances, we’ll be able to backport the ideas C++ (just like we do today).
Does Rust have a track record of supporting that?
- vvanders 8y agoC++ makes it really easy to corrupt the heap or stack which depending on tooling can take days or weeks to track down. I don't mind trading a bit of flexibility with and optional escape hatch (unsafe). I'm really skeptical of backporting Rust's wins to C++. The concept of mutability cuts across the language and I don't see how you do it without bifrucating an already complicated language.
- UncleEntity 8y ago> The concept of mutability cuts across the language and I don't see how you do it without bifrucating an already complicated language. How hard would it really be for someone to write a static analyzer for C++ that ensures there is only one non-const reference/pointer to an object active at any given time? Throw in an object lifetime tracker for allocs and you'd have pretty safe C++ without having to rewrite a billion line of code.
- deleted 8y ago[deleted]
- pjmlp 8y agoMicrosoft and Google are having a go at it.
- c-cube 8y agoIt doesn't seem possible to backport pattern matching, sum types, borrow-checker, and the expression based language into C++. This kind of things really needs to be there from the start. At work we use a pretty big C++ library maintained by absolutely brilliant people, and there still are memory issues and the occasional segfault. It gets tiresome. I'm not convinced anyone can write really safe C++, whereas outside of `unsafe` it's quite easy to write safe rust.