logoalt Hacker News

knorkertoday at 1:09 PM1 replyview on HN

I've been thinking about things like that a bit. I see a very useful and safe Rust pattern, and wonder if I can possibly implement it in C++. Mostly the answer is no, because C++ is too powerful.

I would love to proved wrong, but everything I can think of still leaves a footgun that's easy to trigger by accident, and thus negates the point of the solution.

I think the can't-reference-after-moved-from and objects-are-not-Copy-by-default are key to creating these types (at least enforced at compile time). And that would require major language changes, at least as big as the C++11 changes.


Replies

pjmlptoday at 2:04 PM

Static analysis is the answer for some of these questions.

While many of us that like C++, would wish for a different evolution process, some of this stuff can be enforced by static analysis tooling.

Just like despite being safer than C++, we still use Sonar, FindBugs, FxCop/Roslyn Analysers, go vet, rust clippy, one more reason to actually use Sonar, clang-tidy, PVS, MSVC analyse,... with languages like C and C++.

In some of these you can add your own rules even, even if not always that straightforward.