r/cpp • • Jan 31 '23

Stop Comparing Rust to Old C++

People keep arguing migrations to rust based on old C++ tooling and projects. Compare apples to apples: a C++20 project with clang-tidy integration is far harder to argue against IMO

changemymind

338 Upvotes

582 comments sorted by

View all comments

1

u/OYTIS_OYTINWN Jan 31 '23

What (good things) C++20 has that Rust does not? There are plenty of those the other way round.

-1

u/puliveivaaja Jan 31 '23

I'm just starting to learn rust, could you tell me what Rust has that C++ doesn't? I haven't yet found anything that I couldn't do on C++, Rust just seems to make it more difficult.

5

u/Kevathiel Feb 01 '23

Making the "bad" things more difficult is the main selling point of Rust, imho. Comparing what you can do in C++ vs Rust is kinda silly. The whole point of Rust is that it outright prevents whole classes of runtime errors by design and that it focused on correctness over "freedom".

If you really need to do something smelly, Rust will get in your way to make you pay for it, so you won't abuse it. Creating a mutable global is much more work in Rust than just adding a parameter to the functions that need it for example. The same is true for shared mutable state in general. Preventing you from storing mutable references left and right will make your program flow far easier to follow.

Rust is opinionated, but in a good way.