Hacker News new | ask | show | jobs
by jpcooper 2005 days ago
After years of using statically type checked languages like Haskell, I’ve observed that I am quite lazy. If I went to a language without static type checking today, I wouldn’t trust myself to provide the right function arguments in the right order all the time, or to send the right message types, especially after refactoring. It would be a nightmare for me to have to write unit tests for this. Maybe that would improve over time, or maybe I’m just a crap programmer.
1 comments

Well, as strong a type system as Haskell likely prevents enough bugs in the code to let you feel safe without unit tests. That's what I'm talking about; that -feeling- of safety.

Do any of these languages help prevent you from writing code that simply does the wrong thing? No. You multiplied instead of adding; no static type checker is going to catch that, because you semantically told the computer to do the wrong thing.

That's why I wrote extensive tests; I needed to make sure the code did the right thing, reliably. It's also why we chose Erlang; supervisor trees and immutability meant that as long as we tested and felt good about the happy path, the unhappy paths would generally take care of themselves.

As an aside, in Haskell, you actively have to make tradeoffs around laziness, too. Both these data types are Integer -> I either have to create a custom data type to distinguish them (increasing level of effort as a dev), or I risk getting them in the wrong order if they're both passed into the same function. Named parameters might be a better solution here, and that can be done regardless of typing.

Yes. I agree that you certainly need to write tests for algorithmic code unless you are formally proving it. I definitely would not feel safe about a data structure I wrote in Haskell without writing a large suite of tests. If your tests cover a good portion of the code, then errors arising from incorrect arguments will be quickly found. It's nice to have that eliminated by the compiler when possible though.