WHY RUST CANNOT REPLACE C++, BUT QUITE THE CONTRARY

Jose Crespo
2 min readJan 22, 2024

The evolution of C++ in its recent standards (C++11 and later) has significantly closed the gap in safety and ease of use, which are hallmark-strengths of Rust. Features like smart pointers, move semantics, and improved RAII (Resource Acquisition Is Initialization) for concurrency have made C++ not only more robust but also easier and safer to use.

Modern C++ Features Reducing Cognitive Burden

  • Smart Pointers
    Smart pointers (std::unique_ptr, std::shared_ptr along with utility functions like std::make_shared ) automate memory management, significantly reducing the risk of memory leaks and dangling pointers.
  • Generic Templates
    Modern C++’s advanced template features, including template metaprogramming, allow for more expressive and reusable code, reducing redundancy.
  • RAII for Concurrency
    C++ has enhanced its concurrency toolkit with RAII-based mechanisms (like std::lock_guard and std::unique_lock), simplifying resource management in multithreaded environments.
  • Lambda Expressions and Auto Keyword
    Features like lambda expressions and the auto keyword make C++ code more concise and readable, reducing cognitive load.

Impact on Rust’s Critiques

These advancements in C++ address many of the criticisms that Rust aims to solve, particularly regarding safety and memory management.
With these features, C++ offers a level of safety that is much closer to Rust, while still providing the flexibility and performance it’s known for.

The argument that Rust’s strict safety model is essential may appear less compelling when modern C++ practices are correctly followed, which brings less cognitive load compared to Rust’s often convoluted, overengineered, and highly verbose borrowing and ownership rules.

So, what remains useful in Rust? Its functional flavor, type system, and error-checking mechanisms, which resemble Haskell’s monads like Maybe and Either, stand out, but for that I have already the best version:Haskell itself. However, for the most part, Rust may remain a niche language, not as widely adopted as C++, given that its trade-off between safety and cognitive burden seems clearly biased towards the latter.

So, thank you, Rust, for providing such valuable insights. Now, you can take your leave.

--

--