5 ms·
> but it feels like more of its complexity is front-loaded and that you run into difficult patterns that test your knowledge more quickly. That might just be my
by spease 3y ago
> but it feels like more of its complexity is front-loaded and that you run into difficult patterns that test your knowledge more quickly. That might just be my impression though, I'm tackling the two languages at different times of my life and I'm doing different things with them.
That’s exactly it. C++ will let you do things that are 100% wrong, or worse, occasionally wrong, and you have to “just know” how to do them right. Rust will absolutely refuse to compile until you’ve used the correct concept to solve the problem.
It doesn’t eliminate pure logic bugs, but it can vastly reduce the set of possible inputs and code paths to include a subset of possible failure modes you’d find in C++ code. Which would only be enforced by discipline or code reviews, and forces everyone to be consciously anal-retentive to avoid introducing subtle errors in the codebase.
In addition, a lot of C++’s additions have been more type-safe constructs to partially accomplish some of the safety in Rust, but it doesn’t have a way to drop additions. As a result, the “bad practice” solutions are the ones that got there first and are easiest to reach for, and the best practice solutions have more complex syntax.
For whatever reason, new C++ additions also seem to often be half-baked because support isn’t added to other parts of the STL that they interact with, even if it’s painfully obvious you would absolutely want to reach for those tools. For instance, the limited types supported by std::to_string, or hash tables not supporting tuples for multiple editions (haven’t checked C++23).
So yeah, if you stick to or start out with C++03, single-threaded programming, small codebase, it seems simpler. But once you start scaling the complexity of the code or the size of the codebase, or digging deeper into the language (I haven’t even mentioned template metaprogramming), you keep on encountering more and more complexity.
Whereas with Rust, if you’re writing it idiomatically anyway, the difficulty tends to plateau as
(1) the language is in the background minimizing side effects and enforcing cross-module constraints so the volume of code you have to “just know” to safely work on something doesn’t scale with the codebase
(2) your initial learning only consists of the modern best practices constructs, and after that additional learning tends to be more bite-sized.
When you factor in C++’s still-chaotic DIY buildscript, packaging, linting, formatting situation, the level of cognitive overhead for the parts of a practical C++ project that you actively have to manage tends to be far, far greater than Rust.
And some teams just throw up their hands and decide they aren’t even going to try to keep pace, and just negotiate some arbitrary point in the past they’re going to keep the codebase.
So the editorial comparisons between the safety of bleeding-edge modern C++ and Rust aren’t even really practically relevant, because a lot of teams fall off from how user-unfriendly C++ tooling and later editions wind up being.