Rust seems to take all the little design lessons I've learned in 20 years of C++ programming, and consolidates them into one language:
- It's not best that everything is mutable by default, and
const
if the programmer points it out. It's healthier the other way around. - The fundamental string type is a sensible, immutable string slice (in Rust, a
&str
). This is great for zero-copy parsers, such as nom. Our code has had that for a decade – I named itSeq
, orSeqPtr
. C++ is addingstd::string_view
in C++17. - Elegant built-in variant with pattern-matching (in Rust, this is an
enum
). C++ is addingstd::variant
in C++17. - Type traits solve the problems of abstraction and generics, providing both static and dynamic dispatch, in an apparently more elegant manner than C++ inheritance (which is dynamic-only) or templates (which are static-only). Traits seem similar to concepts, which for now (unfortunately) remains a glimmer in Bjarne Stroustrup's eye.
- Universal function call syntax. Something else Bjarne would like to introduce to C++.
- Macros. Gawd, better macros (though not ideal – too templatey).
- And of course, the crown – which sadly can't be brought to C++: compile-time memory safety!
This post does not yet have any comments.