3 ms·
> Rust users outside of game dev praise the "if it compiles, it's usually correct", Why do people keep echoing this sentiment? I don't find this to be particul
by capableweb 4y ago
> Rust users outside of game dev praise the "if it compiles, it's usually correct",
Why do people keep echoing this sentiment? I don't find this to be particularly true, in my sense of "correct". Yes, it does what the code says it'll do, but rarely the problem I actually get stuck at are language/syntax/semantic errors, it's usually domain/logic errors.
Same can be said for PHP, JavaScript and a bunch of languages, as every program that is possible to run without error, is correct, at least in the eyes of the interpreter. But again, the difficult errors are not syntax/language errors.
- FpUser 4y ago>"but rarely the problem I actually get stuck at are language/syntax/semantic errors, it's usually domain/logic errors." Exactly my case. I've forgotten last time I've had memory alloc / free/ overrun /free after use etc. related bug in my C++ projects. I am using modern C++ which in combination with STL containers makes me forget about all this C++ is scary FUD. I am however not being "turn everything into template" maniac and in general trying for code not to be fancy but rather readable.
- patrick451 4y agoYeah, it's such as silly sentiment, which honestly makes me wonder about the skill of the programmers repeating it. Exactly none of the bugs I've fixed in the last month had anything to do with memory corruption or data races or other undefined behavior.
- Yoric 4y agoIt feels like something was misquoted at some point. The main benefit of Rust towards safety is not memory safety or data race safety or undefined behavior. The main benefit of Rust towards safety is a strong type system with affine typing. When used properly, this eliminates huge classes of bugs. Most of the bugs that I need to fight when I'm writing in Python or JS, for instance, are simply impossible in Rust. Of course, when I'm writing C++ (which I don't do a lot these days), I really miss all the features that you mentioned.
- virtualritz 4y agoI think the phrase is a misquote. I think the original quote is "if it compiles, it runs." Secifically for canonical, safe Rust. As in: "if it compiles it runs and does not explode in your face in a place you didn't expect." After four years of Rust (and 25+ of C++) I find this very true for the former and rarely for the latter except in extremely simple programs. And yes, this says nothing about correctness as far as what the code is intended to in the first place. But you are wrong when saying this, too, applies to e.g. PHP or JS in this context. For the simple reason that they are dynamically typed alone. The class of errors/side effects that this enables is a whole different league.
- K0nserv 4y agoI first heard this phrase applied to Haskell. Both Haskell and Rust have sophisticated type systems, Haskell more-so than Rust. With a sophisticated type system, you can accurately encode the rules of your domain in the types and thus, when the program compiles you can be confident it will do the right thing. Having written a fair amount in both languages as well as many others I find this to hold true. The phrase isn't, primarily anyway, about Rust's memory safety guarantees in my mind.