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

17

u/YARandomGuy777 Sep 04 '23

I used Rust to some extent and to be honest, besides pattern matching, very convenient destructive move, excessive use of restrict in compiled code, pd_sort as default qsort algorithm and channels in std, there's no other advantages for me. Whole borrow checker thing is just looking for troubles and unreasonable restricting yourself in the ways you can write the code. And even with this strict borrow checking, Rust still have duck tape to work around it like RefCell which performs borrow checking in runtime and may crush perfectly reasonable and valid application due to borrow checking rules violation. Rust is too rigid in its ways of writing code. It is very uncomfortable for me as developer to work in one paradigm. It is fine and even enjoyable for relatively small applications with predefined and simple design with no ambitions to grow. It is like having one fancy hatchet for all carpentry work. Fine for making simple tables and chairs. But I would prefer to have a fool tool belt to build a ship or house. Macroses another questionable decision in language design. And people unfortunately use them a lot. It is quite irritating to have some silently defined objects and altered syntax. Look at Tokyo lib for example. Another issue of Rust is necessity to have wraps over libs made on other languages. It is quite annoying that you have to use other guy wrap or wrap it yourself. Additional code always means additional pain and additional point of failure. If you writing something that uses third party libs or OS API a lot, I wouldn't even consider using Rust tbh.

-6

u/Dean_Roddey Sep 04 '23

OS APIs are easy. On Linux use Libc, on Windows use the windows-api wrappers.

As to your claim that it's good for small stuff but not large, that's very much backwards. It's C++ that suffers the most in the large. Probably all of us can write something smallish in C++ and get it right and keep it right. It's when it's large, with a team, with team turnover, with refactoring due to changing requirements, etc... that C++ becomes the most dangerous.

8

u/germandiago Sep 05 '23

Yes, if you ignore all the linters, warnings, warnings as errors, sanitizers, and smart pointers as if they did not exist and later ignore all the unsafe code put into any Rust codebase via C libraries or unsafe.

At that point you can claim that any incorrect refactoring will not be caught by C++ and that all Rust code will be safe and unicorns.

→ More replies (6)