What Does C++ Do That Rust Doesn't?
Tags: healthydebate, rust, cpp
Published: 2019-12-21 01:12:44

I want to preface this by saying these are my two primary languages.  I have a healthy respect for both and plan to focus on both regardless.  I know this is a provocative question, and I am a beginner in both languages.

I'm not talking about stuff where you're supposed to use [JavaScript](https://en.wikipedia.org/wiki/JavaScript) or [C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29) or something - even though [Rust](https://www.rust-lang.org/) is [actually kinda okay](https://www.rust-lang.org/what/embedded) at [those too](https://www.rust-lang.org/what/networking) and [improving all the time](https://www.rust-lang.org/what/wasm).  I'm not even talking about [C](https://en.wikipedia.org/wiki/C_%28programming_language%29), even though I think eventually we might be able to have that conversation too.  I'm specifically asserting that Rust could conceivably compete head-to head with [C++](https://isocpp.org/).

That said, as I learn more about C++, I learn more about how much I don't know about both C++ and programming in general.  From my perspective, the [Hindley-Milner](https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system)-inspired type system is a perfect match paired with the granular control over memory for the kind of data manipulation Rust is targeting. I am more than willing to be shown why I am wrong.

I recently posted about a Rust tree I implemented with a workaround for how Rust is restrictive, but the very first alternative I mentioned was [`unsafe`](https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html).  Of course, there is always the need to directly manipulate memory.  Many standard library tools are by nature implemented in `unsafe` Rust, with a safe API written that's been vetted by the talented Rust team and the OSS community at large.  There are many `lib*-sys` crates that are essentially the same thing.  Any FFI with C will include `unsafe` raw pointers.

That's how any tool, OSS or proprietary, is deemed "safe", though, right?  Smart people look at it?

I see talk of [templates](https://en.cppreference.com/w/cpp/language/templates) with a reverence, but to me they're a clunkier [Rust trait](https://doc.rust-lang.org/book/ch10-02-traits.html).  What can you do with templates that Rust traits + macros can't?  Speaking of which, [Functors](https://v1.realworldocaml.org/v1/en/html/functors.html) in [OCaml](https://ocaml.org/)?  [Jane Street](https://www.janestreet.com/technology/) is making a solid case for that tool even over Haskell or C++.  OCaml itself is an amazing language for [UNIX/Linux programming](https://ocaml.github.io/ocamlunix/).  C++ is cemented, but new code is written all the time.  Am I off the mark with where C++'s power lies?

Why not, all memes aside, write all brand new applicable-domain software in Rust, and write Rust interfaces where needed?

I understand that C++ imposes fewer restrictions by default, allowing people to override the machine where people know better.  I don't know that I'm sold on why that precludes a new *foundational* language that's an improvement over what we have, and why Rust isn't it.

*Photo by Edvin Johansson on Unsplash*