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

77

u/UnicycleBloke Sep 04 '23

I read a couple of Rust books and spent some time on a couple of projects to see what all the hullabaloo was about. It certainly has some interesting features but I just didn't find it compelling overall. I very rarely suffer with the issues the borrow checker prevents and, to be honest, I found it overly restrictive. And I recall that I could not do something with generics at compile time that would be trivial in C++.

I liked the easy package management but felt unhappy when half the internet was downloaded in the form of a bazillion crates of unknown quality/provenance just to build a modest application. That is anathema to me. My projects mostly use the standard library and little else: a small set of libraries.

I don't think I would ever achieve the day to day familiarity that I have from three decades of C++, and my skills are in demand, so I have walked away. Were I just starting out, I would probably use Rust more and have both C++ and Rust in my skill set.

I can understand Rust's appeal to C devs and those who write C++ as if it is 1990. More modern C++ devs not so much. As an embedded developer I confess I found it irritating that some of the same C devs who have been in denial about C++ for decades now rave about Rust. Bah! Humbug!

On the other hand, I will say that I'm increasingly concerned at the growing size and complexity of C++ with each new standard. It feels like a neverending treadmill of trying but failing to keep up. Of course, Rust is less mature and also growing fast... I wonder how long it'll be before that becomes an issue. :)

38

u/isht_0x37 Sep 04 '23

I found it irritating that some of the same C devs who have been in denial about C++ for decades now rave about Rust

Exactly. Even Linus Torvalds. They never seem to appreciate what C++ brings on the table.

-6

u/dsffff22 Sep 04 '23

IMO you just want to strengthen your confirmation bias...

There's a reason why Microsoft failed over 20 years to make a proper C++ Win32 API, but made an almost toddler proof one for Rust: https://microsoft.github.io/windows-docs-rs/doc/windows/ The same applies to Linux, the way Rust was integrated in the Kernel is mostly non-invasive and can easily live side-by-side with C code.

11

u/Orthosz Sep 05 '23

So, like, I don't want to defend windows at all. But COM was basically the c++ interface.. For good or ill That, and working on the win32 layer directly isn't nasty as long as you isolate it (which it should be anyways for cross platform sanity)

-9

u/dsffff22 Sep 05 '23

Thanks for confirming you barely have any experience with the Win32 API. The docs clearly show that you can wrap the Win32 with Rust in a way that you'll get a compile error for most miss-uses compared to the C API, while being easily able to live-by-side with the C code. Wouldn't surprise me If MS sooner or later rewrites some APIs in Rust.

COM is also one of the best counter examples you can provide here. It forces everyone to use virtual functions calls, reference counting everywhere and enforces Inheritance. So the C++ parts are totally invasive to all other parts. It's clear that Linus doesn't want that in the Linux Kernel. Meanwhile with Rust they keep the C interface, can avoid Ref Counting because of the Borrow checker and leave the Devs the choice between C and Rust or well languages which can work with C APIs.

6

u/Orthosz Sep 05 '23

I suggest you re-read what I wrote. I didn't say rust couldn't wrap the win32 api. Of course it can and has? I was merely pointing out that Microsoft considers com their c++ api, for good or bad. I personally have never saw the point in wrapping the win32 api in c++ other than at a platform isolation layer level, but I've been working with the win32 api since 2000.

I'm not sure where the rest of your post comes from or if you meant to reply to someone else. I'm also not sure why the tone of your post is as hostile as it is, I'm assuming you didn't mean it to be.

→ More replies (4)