by netbioserror · 1y ago · 0 comments
In C and C++, it's easy to write incorrect code, and difficult to write correct code.
In Rust, it's also difficult to write correct code, but near-impossible to write incorrect code.
The new crop of languages that assert the inclusion of useful correctness-assuring features such as iterators, fat-pointer collections, and GC/RC (Go, D, Nim, Crystal, etc.) make incorrect code hard, but correct code easy. And with a minimal performance penalty! In the best-case scenarios (for example, Nim with its RC and no manual heap allocations, which is very easy to achieve since it defaults to hidden unique pointers), we're talking about only paying a 20% penalty for bounds-checking compared to raw C performance. For the ease of development, maintenance, and readability, that's easy to pay.
Except most bugs are about unforeseen states (solved by limiting code paths and states) or a disconnect between the real world and the program.
So it’s very possible to write incorrect code in rust…
Study after study shows that's not true, unless you include buffer overflows and the various "reading and writing memory I didn't mean to because this pointer is wrong now" classes of bugs.
It's possible to write logic errors, of course. You have to try much harder to write invalid state or memory errors.
Rust makes it near-impossible to make typos in strings or errors in math formulas? That's amazing! So excited to try this out!