On Mar 11, 2:31 am, Jon Harrop <j...@ffconsultancy.com> wrote: > > 2. The whole thing does not need to be complete or even functional for > > you to start unit testing. > > Apples and oranges: unit tests are not the same between dynamic and static > code bases because dynamic code bases rely upon a huge number of additional > unit tests to serve as a poor man's substitute for static type checking.
This doesn't have to be the case. There is nothing inherently magical about a types that makes them more concise to define than a unit test. If you wished, you could create something like QuickCheck to automatically generate a test based on a type definition: (data + Integer -> Integer) (data count [a] -> Integer) (data str a -> String) The only benefit of a static type system is that it gives you absolute guarantees that a unit test cannot. In Haskell, I can be certain that a function will not return an incorrect type. In Clojure, I can merely say that it is extremely unlikely the function will return the wrong type. The question is whether the guarantees a good type systems offers poses a significant advantage. I've done a fair amount of programming in Haskell, but I don't believe the type system offers any real advantage over unit tests. Guarantees sound good on paper, but the guarantees even a language like Haskell offers are very basic, unless you're willing to go to a great deal of trouble. You can be certain that a function will only return integers, for example, but can you be certain a function will only return even numbers? A while ago, I did some brute force tests on a simple stack-based language to get some testable metrics on how many unit tests you need to guarantee correctness. With a language of 7 instructions and a maximum program size of 8 instructions, there are about 6.7 million program permutations. Testing a single random assertion resulted in the elimination of 99.997% of all incorrect programs. Adding a second assertion resulted in 100% of all incorrect programs being discarded. Obviously this test was extremely small, and bares little resemblance to real programs, which are exponentially more complex. But it does seem to tie into my experience, which is that unit tests are surprisingly good at ensuring a program is correct, enough that they seem comparable to the security of static types. I haven't noticed any significant different in bug rates between Haskell and Clojure, so static typing doesn't appear to have made a whole lot of difference. On the other hand, I do seem to get less bugs than with Ruby, so perhaps immutability is a more significant factor than static typing when it comes to creating robust applications. - James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---