Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Anyone doing a large project in an weakly-typed language will eventually spend more time writing unit tests than features.

No-one should even be thinking about unit tests if they are not already using a language in which all code paths can be evaluated and type-checked at compile time. Why get a dog and bark yourself?



This is not why you write tests. You write tests to be sure nothing breaks when you make changes.

And you should do this with any language, typed or not.


Using a language with static typing means that there are a lot of tests you don't have to write. Do you remember the units trick from physics? If you forgot which equation you're supposed to use, keep on using identities until you're in the units you're supposed to be. Static typing checks that your units are correct for free.


Well, not entirely for "free", but I do agree that the price is much lower than what you end up paying eventually for the convenience of dynamic typing.


I don't ever have to write a test in OCaml to tell me what I need to fix if I change a function signature, or add another item to a struct or an enum, or change a function to return something else, or anything like that. The compiler does it all. Every code path is evaluated at compile time. 90% of unit testing is just not needed in OCaml or Haskell (and that which you do need, there's QuickCheck for).


I had the same experience when writing Haskell. I would start by inserting a function call at the top level referencing a function I hadn't written yet, and then start hacking on the function and all its helpers. Without fail, as soon as the program compiled it was basically correct. The only thing that could go wrong were legitimate algorithmic errors, such as using the wrong base cases for recursion or something.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: