4 ms·
There's a way I like to phrase this: In C and C++, it's easy to write incorrect code, and difficult to write correct code. In Rust, it's also difficult to wri
by netbioserror 2y ago
There's a way I like to phrase this:
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.
- spacechild1 2y ago> but near-impossible to write incorrect code. Rust makes it near-impossible to make typos in strings or errors in math formulas? That's amazing! So excited to try this out!
- grandempire 2y ago> but near-impossible to write incorrect code. 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…
- deleted 2y ago[deleted]
- netbioserror 2y agoTrue, but I think errors in real-world modeling logic are part of our primary problem domain, while managing memory and resources are a secondary domain that obfuscates the primary one. Tools such as exceptions and contract programming go a long way towards handling the issues we run into while modeling our domains.
- grandempire 2y agoIndeed, but you said something more extreme in the first comment.
- jayd16 2y agoThey should have said safe/unsafe. Correct implies it also hits the business need, among other baggage.
- kstrauser 2y ago> Except most bugs are about unforeseen states 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.
- gpderetta 2y agoParent said bugs, not security bugs.
- grandempire 2y agoImagine a backlog full of buffer overflows and nil pointers.