Functional Programming as a Testing Tool
Posted by kilfour on August 4, 2009
I’ve been looking into Functional Programming for a while now. The paper ‘Why Functional Programming Matters’ by John Hughes is what got me interested. The problem imperative languages have dealing with multithreading compared to a functional language was an extra motivation (see f.i. Herb Sutter’s paper ‘The Free Lunch is Over’).
Even though I had been unit testing for a while in different languages, doing it in OCaml, which was the functional language I chose to play around with, seemed to be a lot less rewarding than in an imperative language. No side-effects to take into account f.i., so the tests were quite simple.
Last year I decided to look into Haskell. One of the first things i did (after playing around with the out-of-the-box OpenGL support ) was check out the testing tools. So there’s HUnit, an xUnit family tester. Looked very familiar to OUnit (for OCaml ). Then there’s QuickCheck, and it blew my mind.
And then I came across this very persuasive John Hughes talk.
Since then I’ve played around with the ideas in C# ( which is more and more starting to look like OCaml btw ).
I am convinced that using functional techniques to test (even non-functional) systems is a more productive way of testing than the xUnit pattern I had been using up ’til now.