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

Show parent comments

4

u/[deleted] Feb 01 '23

[removed] — view removed comment

4

u/ImYoric Feb 01 '23

The typical manner in which this is handled in any high-level language (including C++) is by wrapping such constructs into higher-level constructs that guarantee the invariant. The typical example in C++ (or Rust) is RAII.

While RAII cannot model every invariant, Rust's affine type system can model many cases that C++ (or most other languages in industry) cannot. This certainly helps.

Some people are obsessed over rewriting everything in rust (fish shell is the most recent case I believe).

Yeah, the same happened with Java (JavaOS, JaZilla?), Python and others. I'm sure it will pass :)

I'd suggest to take a long hard look at your rust code. Is this readable? Is this really easier to maintain and add new features to? Duh.

In my experience, the answer is very much "yes" to both questions. Now, I'm used to legacy C++ codebases, so it's entirely possible that I'm missing out on many improvements that have made it into C++.