I am trying to make a case for myself to use TDD and the usual punch line is that if you do TDD you don’t spend much time debugging. I am programming in F# and find that I spend little time debugging and code usually works first time around.
So the question is does the TDD punch line works in other direction – if I don’t debug much then I don’t need tests? What is your experience of using TDD with F# or Haskell? Are there any good open source projects in F# or Haskell which use TDD? Does other benefits like preventing overengineering outweigh the costs?
You spend less time debugging F# programs because the type system and emphasis on immutable data structures and pure functions eliminates whole classes of invalid programs.
So the converse of the statement “if you do TDD you don’t spend much time debugging” does hold to a certain degree but should be “if your programming language has features that require you to debug less, then that may imply that you require less unit tests”. That is, unit tests are used to prove the correctness of your code, but some languages like F# have compilers which can prove a lot more about your code for “free” than, say, a dynamic language.
That being said, unit tests are still a very powerful tool in languages from the ML family like F# for proving the correctness of your code, but you are able to focus on the correctness of your functionality rather than the correctness of your use of the language.
All of my F# open source projects have rigorous suites of unit tests (and I think they’re pretty good 🙂 and they have given me an invaluable peace of mind and protected me several times against regression issues.