HACKER Q&A
📣 sptth

Modern C++ or Rust and why?


It's a simple question still there are many opinions out there. I want to ask this here as it is one of the most active comunities amongst programmers. So if you are a C++ developer who migrated to Rust or viceversa, please tell me what you miss or what you dont miss from your former programming language. Also any links to benchmarking or studies stating one is better than the other would be interesting.

Thanks in advance ;)


  👤 jmillikin Accepted Answer ✓
Learn both.

If you learn C++ first, and then learn Rust, you'll find that Rust is sort of a pleasant syntactic cleanup over modern C++ idioms. You'll be happy with the high-quality standard library, mechanically-enforced best practices around nullptr/const, and a core language team that is actively engaged with driving forward progress.

If you learn Rust first, and then learn C++, you'll be amazed by the wealth of libraries that are available. There are still entire ecosystems (looking at gRPC and Protobuf here...) that are C/C++ first, with bindings to other languages, and basically no first-party support for Rust. There's a lot of benefit to being able to reuse existing work.

And once you've learned both, and gotten a handle on the FFI syntax, it becomes natural to write greenfield code in Rust while being able to "drop down" into C/C++ when necessary.

The number one rule here is you must focus on modern C++, not old-school stuff with void* pointers and reinterpret_cast<> everywhere. It's easy to learn low-level programming the wrong way, which will cause your C++ code to be low-quality and frustrate your learning of Rust because you'll constantly be colliding with the guardrails.


👤 nfreising
Similar question asked earlier today: https://news.ycombinator.com/item?id=31232722

👤 Q6T46nT668w6i3m
Excuse the rambling!

I use both. I like both.

I like to use Rust for “systems programming,” i.e., writing POSIX utilities. Truthfully, I am not the biggest fan of the programming language itself and have become less and less of a fan as I started using it more and more. However, the combination of Cargo and std make it unbeatable for these types of programs. They are truly wonderful.

I have recently been doing a lot of numerical analysis and using C++ has been tremendous for my productivity since, frankly, it doesn’t annoy the programmer that’s trying their best to maintain a tricky balance of SOTA correctness and SOTA performance across a variety of architectures. I suppose this is also a reason not to use C++.

I am more than happy as so-called modern C++ is fantastic, but sometimes I do wish Rust had a better numeric and heterogenous-architecture support since I’d love to use Cargo and I think there’s a lot you can do around safety and using the type system to guarantees around things like stability.

Frankly, I find it strange the Rust working groups have done less to recruit influencers from the scientific or gaming communities than areas like writing micro services or web apps. This is especially evident when you look at std and you see it’s missing extremely basic numerical functionality yet has robust file system features. Their perspective about what is and isn’t fundamental to a programming environment is clear, unfortunately it isn’t mine!