←back to thread

517 points bkolobara | 8 comments | | HN request time: 0.935s | source | bottom
1. amai ◴[] No.45049911[source]
"I have found that Rust's strong safety guarantees give me much more confidence when touching the codebase. With that extra confidence I'm much more willing to refactor even critical parts of the app, which has a very positive effect on my productivity, and long-term maintainability."

That is usually why you have tests for your code. But if you have no tests a programming language with a strict compiler is of course more helpful. But the best is to write tests. Then you can also refactor code with confidence written in "sloppy" programming languages.

replies(4): >>45049998 #>>45050001 #>>45050061 #>>45051630 #
2. lock1 ◴[] No.45049998[source]
Agree with your point. Writing good tests & utilizing type system properly should help a lot with catching bugs.

But for some reason writing tests always reminds me with xkcd "Standards" (https://xkcd.com/927/). Instead of "fixing standards by create another standard", now it's catching code bug with more code.

At least for type system, it gets maintained by language maintainers, not project maintainers.

3. IshKebab ◴[] No.45050001[source]
Nope, it's better for properties to be statically proven by the compiler where possible, rather than tested with runtime tests.

Tests should be used where you can't prove correctness statically. But it's better if you can.

The ultimate end point of this is formal verification, where you need very few - if any - runtime tests. But formally verifying software is extremely difficult, so you can't usually do that.

replies(1): >>45050101 #
4. Isn0gud ◴[] No.45050061[source]
And then each time you refactor your code, your work doubled as you now also need to refactor your tests.
replies(1): >>45050155 #
5. pjmlp ◴[] No.45050101[source]
Even formal verification requires tests though, because there may be bugs on the logic proofs.
replies(1): >>45050678 #
6. amai ◴[] No.45050155[source]
If your tests are testing the structure of your code, then this is true. But if you test for functionality/features of your API then you can freely refactor below that layer of abstraction.
7. IshKebab ◴[] No.45050678{3}[source]
True. Well usually. In some cases the property you're writing is so simple you wouldn't need any tests, for example in a compression library you just check decompress(compress(x)) == x. If that is proven there's no need for tests.

But yeah usually it's a good idea to have a few tests anyway. You just need fewer tests the more properties you can prove formally.

8. lmm ◴[] No.45051630[source]
In my experience a Rust codebase with no tests warrants more confidence than any practical level of testing seen in sloppy programming languages, at least until you get to SQLite-style "10x as much test code as main code" projects. A decent type system lets you reach a given level of confidence at much lower cost than doing the same thing with tests. A decent type system plus a handful of judiciously chosen tests lets you reach a higher level than you would ever achieve with tests alone.