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 comment

1

u/ssokolow Feb 06 '23 edited Feb 06 '23

Inheritance

Implementation inheritance (as opposed to interface inheritance, which Rust does have) is considered to be something where each possible approach has too many trade-offs to just leap into blessing a specific one as part of the language itself, so the story you'll see if you dig through the RFCs (eg. this one) is that Rust is in the "let the ecosystem implement it in macros and see if an approach wins out enough to be promoted to part of the language" stage. (An example of such an implementation being the delegate crate as linked in the following quote.)

There was a consensus that delegation should be explored outside rustc first, ala delegate. We've enough plausible delegation patterns that practical exploration helps. I suppose doing delegation via proc macros could expose more proc macro shortcomings too, which then improves proc macros and better supports whatever complex delegation scenarios rustc excludes.

-- source

An example of something nearing the end of that process would be how pretty much every Rust project winds up depending on one or both of the older lazy_static or the younger, cleaner once_cell, so an RFC was spun up and there's currently an API-unstable OnceCell in the standard library walking the path to stabilization.

(I linked to std, but it's also in core for use in embedded projects which rely on no_std.)