11 ms·
Isn't C++ with RAII reasonably safe? I tried to learn/like Rust but it's against how I use to think. If no friendlier safe high speed programming language appe
by DeathArrow 3y ago
Isn't C++ with RAII reasonably safe? I tried to learn/like Rust but it's against how I use to think.
If no friendlier safe high speed programming language appears, I rather use C/C++ and trade safety for friendliness.
- zaphar 3y agoIf you have no users then go for it. However if you do then you are doing those users a disservice by exposing them to unnecessary risk. Maybe the risk is mitigated in other ways. Your software runs as a cli and not a service. It doesn't process outside input. It is run in an ironclad sandbox. But honestly, if you think the way C++ with RAII want's you to then you should already be following the rules that Rust want's you to follow for the most part.
- binary132 3y agoso what you’re saying is proper C++ is fine?
- zaphar 3y agoWhat I'm saying is that if you are sufficiently smart then you could concievably write perfectly safe C++. But since almost no one in practice has ever been able to be sufficiently smart consistently enough to ship C or C++ code that doesn't have memory safety issues, I don't trust anyone to do so and would rather people stop writing stuff in them when there are better languages to use where I don't have to trust you as much.
- binary132 3y agoHere’s what Stroustrup says: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2687r0.pdf https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p26...
- woodruffw 3y agoRAII is great (especially as a developer’s aid), but I don’t think it’s had a huge effect on memory unsafety: it’s still very easy to UAF in a RAII-only codebase, thanks to all of the flexibility C++ allows in constructors and destructors (and unintuitive behavior in moved-out-of objects). Rust is generally perceived as having many of the same developer kindnesses as C++, while having same-class performance. Learning it has a bit of a curve, but I found that it eventually clicked (I have a C and C++ professional background).
- tobias12345 3y agoRAII is great, but unfortunately it breaks down when the resource it manages leaks out of the RAII type. E.g. Whenever handing out the raw pointer stored in a unique_ptr, the code receiving that raw pointer can delete it, which will very likely lead to a use after free and certainly to a double free issue.
- xdavidliu 3y agoI was shocked to learn that reaching an end of a function without returning is actually UB and the compiler doesn't stop you; only warns. For example: ``` class Foo; Foo get_foo() { std::cout << "whoops, I forgot to return\n"; } int main() { const auto foo = get_foo(); } ```
- trealira 3y agoModern C++ can still be unsafe. I recently wrote a comment about it here: https://news.ycombinator.com/item?id=38576681 https://news.ycombinator.com/item?id=38576681