What Does C++ Do That Rust Doesn't?

Ben Lovy - Dec 21 '19 - - Dev Community

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 or C# or something - even though Rust is actually kinda okay at those too and improving all the time. I'm not even talking about C, 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++.

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-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. 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 with a reverence, but to me they're a clunkier Rust trait. What can you do with templates that Rust traits + macros can't? Speaking of which, Functors in OCaml? Jane Street is making a solid case for that tool even over Haskell or C++. OCaml itself is an amazing language for UNIX/Linux programming. 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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .