Hacker News new | ask | show | jobs
by Gankro 3293 days ago
Yeah the only thing that Rust might have over C, in terms of really optimized implementations, is low-level idioms that C declares to be UB, but Rust declares to be defined (generally to be what x64 hardware does).

Maybe something that leverages signed overflow, overlong shifts, or type punning.

But if you have enough control over your codebase to mandate the compiler/flags its built with, then you can generally tell the major C compilers to act like Rust in these cases.

That said, the expected win for Rust over C(++) in practice is that you can be more "reckless", because you have a stronger type system protecting you from messing things up. A production-quality C(++) codebase might rightly do more copies, use more reference counting, and use less concurrency just because the risk of doing otherwise isn't worth the potential performance wins.

Organizations have limited resources to commit to optimizing/verifying code. Rust is intended to get you more bang for your buck.

1 comments

> That said, the expected win for Rust over C(++) in practice is that you can be more "reckless", ...

I'm glad to see somebody articulate this observation. SaferCPlusPlus[1] is meant to, in part, bring this benefit to existing C++ code bases. The question is, would a borrow checker for C++ make sense?

[1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus