3 ms·
Unit tests and type checking solve very different problems. In practice there is a lot of overlap, but there are gaps in both that the other covers, thus you ne
by bluGill 7y ago
Unit tests and type checking solve very different problems. In practice there is a lot of overlap, but there are gaps in both that the other covers, thus you need both if you want the best quality (if you want the best quality you will also look at formal proofs which is a super set of type checking and can catch even more problems that the above two won't - but even that will not catch everything)
Unit tests prove that everything you thought of works correctly. Formal proofs show some ares where you didn't think of something still work - but they can fail because the assumptions are wrong.
- josephg 7y agoI agree that you need both. But in my experience you need far fewer unit tests in a typed language in practice to be reasonably confident of correctness. Like, maybe 1/3 of the number of tests. The reason you need so many tests in JS is that its just so easy to accidentally refer to a variable that doesn’t exist anymore or something like that. And the only real way to be safe from that sort of mistake is to go overboard with unit tests and aim for 100% coverage, which destroys velocity. As you say, unit tests and type systems are good for different things. Unit tests can be used as a poor mans type system, but that seems like an amateurish deal now we have typescript & friends. Well, at least for code you want to maintain long term.