r/cpp • u/isht_0x37 • Sep 04 '23
Considering C++ over Rust.
To give a brief intro, I have worked with both Rust and C++. Rust mainly for web servers plus CLI tools, and C++ for game development (Unreal Engine) and writing UE plugins.
Recently one of my friend, who's a Javascript dev said to me in a conversation, "why are you using C++, it's bad and Rust fixes all the issues C++ has". That's one of the major slogan Rust community has been using. And to be fair, that's none of the reasons I started using Rust for - it was the ease of using a standard package manager, cargo. One more reason being the creator of Node saying "I won't ever start a new C++ project again in my life" on his talk about Deno (the Node.js successor written in Rust)
On the other hand, I've been working with C++ for years, heavily with Unreal Engine, and I have never in my life faced an issue that usually the rust community lists. There are smart pointers, and I feel like modern C++ fixes a lot of issues that are being addressed as weak points of C++. I think, it mainly depends on what kind of programmer you are, and how experienced you are in it.
I wanted to ask the people at r/cpp, what is your take on this? Did you try Rust? What's the reason you still prefer using C++ over rust. Or did you eventually move away from C++?
Kind of curious.
18
u/jsadusk Sep 05 '23
So, I say this as a C++ dev for a couple decades that is now using Rust, the transition is different. People arguing that Java/D/Scala/Go/whatever will replace C++ were really arguing that higher level programming with memory management will replace the need for low level programming. And, in many domains they did, there's no need to use C++ to write a web app server most of the time. But the core need for C++, to do performance critical work that directly manages memory but still provides strong abstractions continued to exist.
Rust isn't a higher level language, its not garbage collected, it doesn't have a runtime. In theory you could transpile rust to C++, they operate on the same concepts. Rust solves one very real issue with C++, memory safety and protection against undefined behavior. The number of vulnerabilities attributable to this (arguable) flaw in C and C++ is staggering. So, rust fixes it. With the main trade off being that certain dev patters are harder to express, notably self referential datastructures.
The point is, unlike your other examples, anything that can be done in C++ can also be done in Rust. Its not a replacement in the sense that everyone is going to start using it, its a replacement in that it solves the same need as C++. And it could be arguable that it does it better. Better is subjective, so take with a grain of salt.