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.
2
u/InsanityBlossom Sep 06 '23
These arguments seem fabricated to me.
Unlike in C++ libraries, where you often need to pass a ton of flags just to make the library compile/link in Cargo, you can pass features, i. e. conditional flags to enable/disable certain library features. The majority of the flags affect the whole compilation. Again, first we need to state the problem and then solve it using language/toolchain methods and not trying to port C++ solutions to a different language.
Rust builds everything from source which means the intermediate artifacts it produces ( compiled dependencies ) are temporary and will be invalidated (recompiled) if changed. In Rust, you don't link pre-compiled binaries from one build into another - you build everything at once into a single binary. Or maybe I didn't understand your question precisely, I'm not an expert in this area.
Can C++ ( or any other language do this ? ) Obviously no, not 100% safe, but in Rust it is much safer, especially if it's a well written library with a decent API. You wrap the
unsafecalls into a shim layer with a strong interface requirement and forget it, the compiler won't let you misuse it.Why are there so many CVEs open for GCC, MSVC, Clang and numerous libraries? Rust doesn't live in isolation, it coexists with various platforms limitations and issues, and it's built on LLVM which has its own share of CVEs.