4 ms·
> Once it compiles, it works (usually). How does Rust help prevent logic bugs? I thought tests helped prevent logic bugs. Or does the author mean "works" in th
by rajin444 6y ago
> Once it compiles, it works (usually).
How does Rust help prevent logic bugs? I thought tests helped prevent logic bugs. Or does the author mean "works" in that it runs where an interpreted language would not (i.e, syntax error)?
- pitaj 6y agoThe type system is very powerful. Enums help prevent a lot of logic errors.
- chewbacha 6y agoWhen I repeat this I’m generally talking about type-tests versus logic-tests. In dynamic languages, you only know if it’s fails at runtime so being statically typed eliminates a category of specs. Rust excels here, in my mind, because of its expressive type system which can allow you to encode logical building-blocks as types and hoist the logic into the type system, eliminating even more specs in favor of compiler errors. Ultimately, with a sprinkling of logic tests, you can feel confident that compilation means success.
- Dowwie 6y agoRust compiler isn't going to tell you that your mortgage amortization logic is incorrect. You're still going to need to write tests to validate that the business logic is correct. However, the way that the calculations are implemented can be done in a way with Rust that offers higher levels of confidence about how systems will behave in production.
- andoriyu 6y agoWell, Rust (or any language) won't prevent business logic bugs. > Or does the author mean "works" in that it runs where an interpreted language would not (i.e, syntax error)? More than that, but close. i.e. you won't get NPE from java. Syntax error or type mismatch from interpreted language. In addition, NewType pattern will stop you from passing seconds into a function that takes ms and vice versa. You won't get data races. You also won't get an `undefined is not an object`. Long story short, due to language verbosity it's hard to make logical mistakes.