Hacker News new | ask | show | jobs
by rkrzr 3456 days ago
> Statically type checked code has all of its code paths effectively tested by the compiler

The type checker just ensures that a program is well-typed (i.e. free of type errors).

The better the type system the more program properties can be encoded in it and the more errors it can catch (up to the point of proving correctness of your program).

But you are right that type checking alone is no substitute for testing. They are orthogonal concepts and both should be employed to ensure that your programs behave correctly.

One nice thing of statically typed languages is that they can automatically generate some tests for you, like e.g. the QuickCheck library for Erlang and Haskell.

2 comments

They are not orthogonal at all. Both verify your code against invariants. While the typing system tries to prove an invariant holds, a test tried to prove that it does not hold.

That means that false positives are the problem for typing systems, while false negatives are the problem for tests. But that's the biggest difference you will find.

One does even replace the other.

Clojure has quickcheck as well: https://github.com/clojure/test.check
Good point. Of course you have to specify the type of the values that you want to test in the test itself then, so you have to specify some types one way or the other.
You can feed those types from clojure.spec now :)