logoalt Hacker News

Jtariitoday at 9:31 AM3 repliesview on HN

Most bugs are logic bugs which rust does nothing to help you with.


Replies

JuniperMesostoday at 10:17 AM

I disagree; Rust's type system, which supports pretty rich algebraic data types, makes it easier to specify the correct data model for your system than it would be in languages with simpler type systems like C or Python. The ability to define enum types with arbitrary shapes for each variant, and then match on them in code, allows programmers to build better, more-accurate abstractions and have less fear of screwing up and causing a logic bug.

kawogitoday at 10:14 AM

In my experience, it absolutely does (at least if you use it idiomatically). Using the type system (esp. enums, Result and newtypes) makes a good bunch of invalid states irrepresentable.

This also helps to focus on the remaining things that could go wrong.

The integration of unit tests also lowers the barrier to just sprinkle some tests in, if you're unsure that you got an edge case right. Anf clippy (not stricly the language, but still kind of a core component) greaty helps to stay on the idiomatic track.

No silver bullet of course, but I never had so few runtime issues with any other programming language so far.

What logic bugs did you encounter the most?

edit: mobile typos

chloriontoday at 11:07 AM

Rusts memory safety is enforced via type safety. You can enforce more than just memory safety related invariants with the same type system?

I've seen many people make this claim and it's wrong but also silly. How do you think type systems work?