Live data from Hacker News

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

news.ycombinator.com

51–60 of 92 posts

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

#51
Every language has its own merits, there's no single language that's universally the best for every task.

With that said, C++ and Rust both occupy similar domains (high-performance, low-level, often interacts with OS syscalls or hardware).

Pros of C++:

- More mature, excellent library ecosystem, decades of code to reference from.

- Syntax is arguably easier to read and write

- It's very popular (top 6th language on GitHub), lots of talent to hire from.

Pros of Rust:

- Memory safety, it's much harder to introduce bugs of a certain type.

- The borrow checker makes it easier to reason about lifetimes of objects.

- Cargo is great for pulling in libraries (just needs more of them).

For me personally (graphics / game-dev), cost and speed of development is the deciding factor. I use both: C++ by default, and Rust for low-level, safety-critical code.

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

#53

Earlier quoted context omitted.

In which ways does Rust need to improve, in your opinion?

Here we go. I'm not taking this bait.

I understand your hesitation, but I’d really appreciate your take, given you seem to know your stuff.

Personally I think the sibling comment is pretty accurate, and rust is held back by:

- slow compiling of larger projects

- async stuff can quickly lead to very complex shenanigans

- embedded still requires you to write HAL stuff for MCUs that is supported out of the box for C

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

#54

Earlier quoted context omitted.

I've had to refactor a heck of a lot more C++ than Rust. C++11, std::optional, concepts and ranges, std::format, etc. It's not even that I dislike these changes necessarily, but you're always rewriting C++ to keep up with the language. In rust it's mainly been nightly stuff getting merged to stable, pre-1.0, and async. Much more stable overall.

> you're always rewriting C++ to keep up with the language If that's what you want to do, which is a big if. I guess strictly speaking the same is true for Rust but in Rust, with it being new, it "feels" more like I should keep up (at least for me). In c++, I would mostly just not mess with old code that works...

I'm approaching this from an enterprise perspective of "how confident am I that this code is safe and correct?"

If you hand me a pile of c++03 code that happens to compile, my confidence in it meeting both of those criteria is fairly low. If you ask the standards committee or bjarnes, what they're going to tell you is to rewrite it in modern C++, which constantly evolves.

Contrast that with rust where it's probably fine if it compiles.

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

#55
Existing library support. The rust ecosystem in some domains (Large parts of embedded) are immature. And, (hot take), while generally Rust's syntax is nicer than C++'s across the board (Not having headers, clearer struct and function syntax, array refs vice pointers etc, avoiding scattered/global state), the friction generated by generics and async in some parts of the ecosystem negates them.

So, if you use rust on a given project, you may end up re-inventing things that could be libraries, due to lack of support, or the libraries having missing features or a poor/poorly-documented API. Normally, auto-generated Rust docs are a good way to learn a library, but generics negate it by ending the link trails.

I think you'll find the tooling, and (non-async, non-generic) syntax of Rust are a step up from C++.

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

#56

One I don't see mentioned here is market. There are far more c++ developers out there. Whether you're writing a library that someone else will be using, or you want to hire people (or have people contribute), c++ is a much larger "market". This doesn't mean I'm necessarily advocating for c++ or rust, but c++ definitely has advantages over rust, even if they're not just intrinsic.

Rust has good FFI with C++ meaning that you can write Rust libraries that are consumed by C++ programs.

C++ developers understand all of the concepts needed to easily pick up Rust. As long as it's not a quick project that will be immediately thrown away getting C++ to use Rust will be worth it.

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

#57
post #3

If you need to interact with existing C++ code or libraries obviously C++ is going to be a much easier path than using Rust. If you don't have such a requirement, or you think that the available Rust libraries are good enough for what you're doing, then use whatever you want.

I just started a new project in C++ for two reasons:

1. I already know (some) C++

2. more mature GPU ecosystem, particularly CUDA support

I don't mind learning new languages, so CUDA was the deciding factor for me. Maybe someday as Rust's GPU support improves I'll consider a rewrite.

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

#58

I am a retiring engineer/entrepreneur. I made a lot of money with C++. It is hard for me to tell anyone not to use it. I recently developed an oil and gas derivative tool in Rust. IMO Rust has a long way to go. It reminds me of OCaml. I spent 2 years developing a Compliance System on DEC/OSF1 in OCaml. We made the mistake of adopting that language too early. Also, the C++ community is a lot more tolerant. A big plus…

> Also, the C++ community is a lot more tolerant. A big plus for C++.

Well I completely disagree with this. The C and C++ communities seem to me personally to be a lot more "elitist", engaging in extreme pedantry or dunking on each other over knowing obscure language trivia. Both the language and the community are beginner-hostile in comparison to Rust.

Not that the Rust community is perfect, because it's obviously not - but lack of "tolerance" has never seemed like one of the problems it has.

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

#59

Earlier quoted context omitted.

> you're always rewriting C++ to keep up with the language If that's what you want to do, which is a big if. I guess strictly speaking the same is true for Rust but in Rust, with it being new, it "feels" more like I should keep up (at least for me). In c++, I would mostly just not mess with old code that works...

I'm approaching this from an enterprise perspective of "how confident am I that this code is safe and correct?" If you hand me a pile of c++03 code that happens to compile, my confidence in it meeting both of those criteria is fairly low. If you ask the standards committee or bjarnes, what they're going to tell you is to rewrite it in modern C++, which constantly evolves. Contrast that with rust where it's probably f…

> standards committee or bjarnes, what they're going to tell you is to rewrite it

The same will be true for Rust in 50 years (assuming Rust doesn't die any time soon). If they didn't think it was worth modernizing, they'd just leave C++ alone (which I think they should, but that's another matter).

For old C++, you run valgrind and a linter on it and if nothing comes up it's also "probably fine". At least it's hard for me to think of a situation where the most productive/profitable-for-buisness thing a developer can be doing is modernizing their old C++.

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

#60
post #38

Earlier quoted context omitted.

In which ways does Rust need to improve, in your opinion?

Compile time, async, steep learning curve are things that come to mind

I’ll add, thanks to their age, C and C++ have more compatibility with boards, OS’s, GUI’s, libraries you might need, etc. Especially in embedded, you have way more options if using or hiring for C/C++. There were also more tooling for analyzing the C/C++ software but they often cost $$$.

For common scenarios and platforms, Rust’s library situation did get way better really quickly.

Post reply on HN