Live data from Hacker News

Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

news.ycombinator.com

11–20 of 92 posts

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#11
1. Better integration with existing libraries, there is a lot of software the exist in C/C++, and a lot of it is weird and opinionated, and having to write bindings for that isn't great.

2. Continuing on that, QT is still good for large desktop GUI projects. It doesn't seem it's well bound to Rust, and Rust is still trying to figure out their comparable UI story.

3. Ironically, in some certain circumstances, with good discipline, (And mostly interfaces that looks like C) C/C++ can compile faster then Rust.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#12

C++ seems easier to work with, tools for C++ are plenty and more mature, so if productivity and speed of development matters, those are good reasons to use C++.

While I can imagine that familiarity with tooling can be a massive boon, I have to say I tend to pick Rust over C++ for the exact opposite reason. I find Rusts tooling a lot easier to use than the C++ tooling. Clear compiler messages showing what's wrong, far easier error handling and logging, and far easier dependency handling through cargo.

On the other hand there's of course the borrow checker which means you need to think a bit more about how you do your lifetimes, which can slow you down a bit, but I find that that prevents me from writing bugs more often than not.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#14

Consider cross-platform -ness. For example, if you make a new app with domain logic in C++, you can build it on iOS through Swift/Objective-C++ >> C++, or on Android through Java JNI >> C++, or on React Native through JavaScript Interface (JSI) >> C++, or on Linux through wxWidgets >> C++, or... etc. Other than that, Rust is a great language with a great compiler eliminating whole categories of bugs possible with C++…

I don't disagree that broader platform support is a reason to choose C++, but Rust is just as capable at integrating with the specific platforms you're talking about.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#15
The benefit of using Rust is that management of 3d party libraries compared to C++ is a lot easier with cargo, so you can do things quicker.

The downside to using Rust is that its still an evolving language so you may have to refactor your code down the line. Generally Rust use case is targeted towards enterprise software, where you have lots of people working on it, and it needs to be fast, and you want to minimize chances of introducing memory bugs. For personal use, I don't think its honestly worth it tbh, it just slows you down.

Personally, I use Python and C exclusively. Its pretty easy to write C extensions to Python to handle the things you need to go fast, and then let Python handle the launching of the code. For example, I was playing around with MCTS, and I would have the tree set up in Python, and then use multiprocessing to split the tree into x processes, and each process would launch C code that did the search a lot faster. Overall the implementation was super easy since I didn't have to write the low level C code for the initial setup, with memory management and so on.

There was a recent video about using torch to compile custom CUDA kernels (https://www.youtube.com/watch?v=nOxKexn3iBo). I have implemented this for some custom data processing that I do that I previously had C code to do on the CPU, and its WAY faster using CUDA.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#16
I think the biggest reasons to go with c++ over rust would be mature compilers and the relative abundance of mature libraries, and possibly your existing knowledge of the language.

It seems like the bigger question is what are the goals of your project(s)? Like if gaining more experience with rust is a primary goal, then the aforementioned advantages are pretty much moot. OTOH if a project could benefit a lot from leveraging mature compilers and libraries, or if you can't afford the additional time investment associated with becoming proficient with a new language, then c++ may well make more sense.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#17
I think the question could be answered with... why do we use JavaScript at our company? Because there are a lot of libraries that are available and maintained there. Many times the existing libraries are more important than the programming language itself.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#18
Firstly, my background is in Haskell and Rust. I generally defer to safety-conscious languages. So please no responses extolling the virtues of type safety, type systems, etc. I know, I agree, but that doesn't change what I'm going to say.

Rust is awesome, but honestly modern c++ is quickly catching up. Rust has safety going for it, but one of the issues is that sometimes you have to be more inefficient for it (reference counting), and pay the price of code litter (Boxes everywhere). Also, realistically type safety takes time to think about (although not much). Either way, you will spend time playing type golf before your code even runs and compiles.

C++ is strictly more powerful, even ignoring the memory safety. Modern c++ with its smart pointers basically has rust ownership semantics builtin, with the option to fall back to manual memory management, which is sometimes necessary. Modern c++ has concepts, template metaprogramming (MUCH more powerful than rust), constexprs, etc. This alone, for me, has made developing interpreters and compilers much easier in C++ than Rust.

Finally, after almost a decade being a professional Haskell developer I have come to appreciate the benefit of being able to prototype fast. The truth is, type-safe languages are great for final work, but having the option to throw it all out the window to just get something done, is also really nice. In my ideal world, we would have a language with well-defined semantics for ill-typed programs (even with undefined behavior) and then an option to strict-ify the type-checking when releasing. Yes, I know rust has unsafe, and this is good, but maybe I just don't know enough unsafe rust to be efficient. I find it not obvious to use. Haskell of course has a REPL which (in my opinion) makes it easier to prototype in than both Rust and C++, so while it has type safety, the REPL makes prototyping easy. Without either a REPL or an untyped fallback, I think Rust takes more time.

One more thing... Rust has great abstractions, but unlike the Haskell world where abstractions are taken to their logical conclusions fast, it seems to me rust is more conservative in its approach (multi-param traits, for example). This seems to have worked out in terms of popularity. But for me at least, when working with Haskell, I often start to reach for yet more advanced features that really ought to work. Usually, when that feature is not implemented yet, I will find an approved GHC RFC for it, and just wait for the next version of the compiler. In Rust, it seems things move much more slowly. I have found myself endlessly frustrated with what I perceive to be weaknesses in its trait system (no existentials... :( ).

At the end of the day, both are solid programming languages, with Rust being much better for anything dealing with business logic, while C++ is better for projects involving heavy meta-programming. I have personally myself done a lot of prototyping in Haskell (due to the REPL) and then implementing the runtimes in C++. Rust I've used for one-off tools, utilities, and anything to do with high-perf async IO.

Re: Ask HN: Are there any good reasons to use C++ over Rust for new projects today?

#19
I'm "Rust curious", but I'm coming from a web/app background (Dart, JS, TS, Java, Python), so take my ideas with a grain of salt.

1. One context, which appears to be yours, is when a team or individual has extensive C++ experience.

You see, for me, learning C++ with all its decades of good/bad parts feels overwhelming, so Rust makes sense for me even if it's still the hardest language I've ever learned, but as you are already an experienced C++ dev, it might make sense to continue cpping.

I'm used to simple, standard formatting tools, packaging, dependency management (Rust is great in that sense even for beginners), so to figure out how that's correctly done in cpp in 2023 would be hard. But again, for you, it's easy, you already know all that!

Apart from that, I guess there can be libs that are great in C++ and still lacking in Rust.

Also, need to consider if memory safety is really such a big issue for you and your future project.

Post reply on HN