5 ms·
> it's not possible for human beings to write correct C code It's not possible for human beings to write correct code. The hardest bug I ever found in a C pro
by kps 4y ago
> it's not possible for human beings to write correct C code
It's not possible for human beings to write correct code.
The hardest bug I ever found in a C program, one that took cumulative weeks of work until a tractable reproduction was found, came down to a ‘<’ that should have been ‘<=’. No language would have stopped that.
Yes, different languages have different levels of expressiveness, and can preclude or expose different kinds of errors. You'll never have a stray pointer in Python, and you'll never OOM making an accidental copy in C.
- deterministic 4y agoNot true. Check out CompCert, seL4 etc.
- preseinger 4y agoobviously yes yet c code is inarguably more error-prone than basically any other language
- lelanthran 4y agoNope. Many errors in JavaScript, python, PHP, etc are caught at compile time in C. Of course, the errors that do get through might be more severe in C than in python, but not always. After all, the most expensive and destructive RCE ever was in a piece of Java software.
- tialaramex 4y agoI assume this was a logic error, that is, the code as written was a valid C program that didn't do what you meant. In that case this could have been caught with more careful unit tests, which would have exercised the erroneous condition, and potentially with fuzzing to excite corner cases. C is... not great for either of these.
- gavinhoward 4y agoI don't know why you say that C is bad for exercising error conditions or fuzzing. In my experience, it's the best at those.
- tialaramex 4y agoIt doesn't come with either capability, so you're adding third party tooling to get these working.
- gavinhoward 4y agoWell, sure, but that's true of any language.
- tialaramex 4y agoNope, when I write tests in my Rust the out of box cargo test will check those tests pass. If I wrote inline Markdown documentation for part of the Rust code with an example, cargo test will try to build my example, and check it works - not much good having a purported "example" which doesn't even work, is it? And yet many languages don't do this.
- gavinhoward 4y agoYou said fuzzing and exercising error conditions. Rust's tooling does not do that. You need something to generate those tests. Fuzzing is still not part of the default Rust tooling.
- GoblinSlayer 4y agoMere existence of a test runner is infinitesimal compared to your proposed careful testing. Saying this as someone who wrote my own test runner, it's a few lines of code.