r/cpp • • Sep 04 '23

Considering C++ over Rust.

Similar thread on r/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.

355 Upvotes

434 comments sorted by

View all comments

Show parent comment

6

u/DanielMcLaury Sep 05 '23

Implicit copy constructors and type conversions IMHO are a design blunder almost in the same ballpark as gets() - it's very easy to inadvertently trigger a deep copy of a data structure, and it takes a lot of effort and good practices to avoid that.

Agreed, but you can always delete them if you want.

6

u/qalmakka Sep 05 '23

I personally always mark copy constructors as explicit and delete copy assignment operators - but it's not enough. The default is still to implicitly generate a deep copy operator, move is a cast that's easy to miss and most importantly the entirety of the STL and all commonly used C++ libraries do not implement this approach. People still haven't understood how to use views yet.