by Cesare Rocchi

Static Types vs Unit Tests

by Cesare Rocchi

Tags: development

Only 36% “see the value” of static types. In contrast, 62% – nearly twice as many – see the value of unit testing. Developers are nearly twice as likely to “enjoy using” unit tests (33%) as compared with static types (18%).

Empirical Analysis of Programming Language Adoption source

I am usually skeptical about papers like this. There’s a lot to pay attention to in surveys. For example:

  • how they gathered subjects?
  • how are the subjects representative of the community?
  • how the survey was conducted?

and much more.

For example the analysis I quoted above was extrapolated only by considering developers that self-identified as professionals.

Observations are blurry in the whole paper, most likely because in the community of developers borders are blurry. There’s experts, self-proclaimed experts, experts that still think to be beginners and many more combinations.

That said I relate a lot with the point extrapolated. I grew up with Lisp and then switched to Java. I felt the friction introduced by the compiler. The resulting code in Java maybe was tidier, but I perceived more fatigue to get to the intended result. The same happens these days when I switch from Ruby to Swift.

A programming language with dynamic types gives you more freedom, which leads to more opportunities to screw up. You compensate it with tests.

When a program compiles you have made the machine happy. You are not done, you are just “formally done”. When the tests pass, depending on the test coverage, you are more confident that your program does what it’s supposed to do.

If you are into UI testing, even better. When tests pass, again depending on test coverage, you know that your customer is having the experience you have thought for him/her.

Jon Reid has also an interesting take on the subject.

Please notice that this post addresses developer confidence and customer happiness. It does not mention – on purpose – the performance of the resulting program, which is definitely a relevant element but out of the scope of this post.