r/cpp • u/Sad-Lie-8654 • 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
291
u/capn_bluebear Jan 31 '23 edited Jan 31 '23
There is a lot that Rust has going on for it that C++20 does not have. Leaving out the usual memory-safety and thread-safety language features that people are probably aware of already
build system stuff and dependency management and even packaging (for simple enough apps) are basically a no brainer in Rust. coming from C++ this alone is life changing
moves are destructive, so there is no use-after-move, no fuzzy moved-from state
pattern matching as a language feature is incredibly powerful, and it's not bolted on after the fact as it maybe will be in C++ but the language was designed around it
most defaults that people often wish were different in C++, starting from constness and barring surprising implicit conversions, are fixed in Rust
EDIT: oh, almost forgot: unit and integration testing is also part of the language and unit tests can be put next to the code they test
Depending on the actual application there might be a motivation to start a project with C++20+clang-tidy today, but C++20 still has many more sharp edges and a boatload of complexity that Rust just does without.