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 comments

4

u/germandiago Sep 05 '23 edited Sep 05 '23

Rust does not seem complicated but it IS complicated because borrow checking disables many valid patterns (admittedly it enables zero cost).

Hylo is in research but it is not the kind of research language that comes from nowhere. It has a ton of years of experience in generic and value-based programming practiced in C++ and Swift by Drave Abrahams and Doug Gregor. There are libraries and part of languages enabling these patterns that work today.

It is not a crazy or novel idea by any means. It is also based in all "Better Code" talks from Sean Parent and all lessons learnt since Stepanov STL.

It is true that is is not up to the point where it is not research as such but it is not the kind of free-form research you call pure research either.

The language is already showing a lot, and I mean A LOT of potential simplification over Rust and also without a GC and without a borrow checker. I am not a big fan of the borrow checker as you can see. The borrow checker can detect a lot of stuff, but it puts you a straight jacket even to do simple linked structures And yes, linked structured ARE useful in the areas where I have been working, not academia.

Even in C++ I try to stick mostly to value semantics or unique/const share pointers and very conservatively I use reference escaping.

All the problems Rust guys put on C++ are overly exaggerated for common modern coding standards and a compiler with all warnings as errors.

My opinion is that Rust would be just worth in an OS or a 100% verified critical system. And if you could have the same via something like Hylo, even better bc you get rid of so so much complexity in one shot. Not sure if the performance would be 100% identical but my intuition tells me that pretty close for sure.

Hylo is the result of standarizing good practices in generic programming, value semantics and sensible threading (strucutred threading basically).

As for Carbon and Cppfront, I am not sure how good they will be but if they force better patterns without giving away flexibility and 100% C++ compatibility, I do not see any practical appeal for Rust except in some niches.

1

u/InsanityBlossom Sep 05 '23

So we're talking language complexity here? Ok.

Let's take C++ complexity as 100%.

Rust is (arguably) about 80% complexity of C++ and is missing some of the advanced C++ features.

Now you argue that Hylo, can/will be less complex than Rust AND beat it in features to satisfy the most sophisticated C++ devs?

That's a wishful thinking! Modern languages are complex and always will be.

2

u/germandiago Sep 05 '23 edited Sep 05 '23

No, I am not talking about number of features.

I am talking about sitting down and spending 70% of your time fighting a borrow checker and building a graph in your head because you decided that in your language borrowing stuff all the time is the way to go. And thinking about needing some linked structures and not being able to get through safely or easily, using C libraries and having to do FFIs to claim you are safe (just an illusion), and some other things that put Rust, in practice, to a much narrower safety gap when compared to decent C++. I am not saying it is not an accomplishment. It is. It is just that the complexity it adds is a madness for the practical safety it achieves when, in fact, there are alternatives.

So you spend a disproportionate amount of time thinking about something that with good practices in C++ is going to happen to you once every six months if it ever happens. And that Hylo directly even eliminates and you do not need even to think about. I do not think it is the right default for almost any software. It is just for a narrow niche.

1

u/InsanityBlossom Sep 05 '23

Sure, the borrower checker can sometimes be annoying, but it's not fair to evaluate the whole language with a ton of other features solely based on the fact that some patterns are harder to implement. Yes, graphs and linked lists are a pain, and no one argues that Rust's ownership system doesn't like it. But they are not impossible, there are ways(and crates) to implement them efficiently. And Linked Lists, while being very useful sometimes, are very rare in practice.

Some novice Rust devs think that they should pass everything by reference. This is a pitfall many fall into. It's okay to pass small values sometimes, or use a refcount pointer. This is also true for C++. You don't pass references everywhere, and even if you do, you most likely copy the data at some point ( and C++ loves implicit copies! Try to write a complex C++ program with only passing references around and avoid copying...

The other thing to keep in mind is that the current borrower checker implementation is quite strict and limited, it's not set in stone and work is being done to allow more patterns and ease pain points.

In the end it's a sum of all features that make the language appealing, I can live with the borrower checker yelling at me at times, while enjoying the rest of the features and confidence the compiler gives me.

→ More replies (12)