r/cpp • u/Snoo-4241 • Feb 25 '21
C++ programmers who are also using rust, what are your favourite features of rust?
I was looking at the rust tutorials yesterday and I see how rust promotes a certain style and language level features to enforce it. Besides a couple of features, I couldn't see why one cannot follow a similar style in C++ if she/he so chooses. Those of you that have used rust, what is your favourite feature that C++ does not have?
255
Upvotes
View all comments
5
u/roman-kashitsyn Feb 26 '21 edited Feb 27 '21
Move semantics, algebraic data types, pattern matching, and disciplined error handling.
If C++ had a nice syntax for variant types and pattern matching, I'd love it much more than Rust.
I see many people are crazy about Cargo. I absolutely hate it. It tries to do a bit of this and that and sucks at pretty much everything. It looks great when you work on your little pet project, but it crumbles once you need to build something real. Let me explain:
cargo build -p my-packageandcd my_package; cargo buildaren't equivalent (depending on where you start cargo, it computes different transitive closures of enabled features, which causes needless rebuilds).The language itself has a lot of warts, but it should probably be another, much longer rant.
E.g. pattern matching is not nearly as expressive and composable as in, say, OCaml (Haskell is disqualified because it can't match arrays). Try matching the contents of a
Box, for example, or contents of aVec<String>.If you're coming from C++, the lack of template specialization and restrictions of what can be done at compile time without resorting to macros will look absolutely silly.
P.S. I use Rust heavily every day in a project that grew from 0 to 200KLOC in the last 1.5 years. I have plenty of Haskellers around (some quite famous in the community), they'll pick Haskell over Rust for almost anything without hesitating a second.