Hacker News new | ask | show | jobs
by PaulHoule 4197 days ago
I find myself bouncing between at least three modes.

There are some things that I really know how to code correctly out of my head and in cases like that sometimes I put very little effort into testing.

If I am writing something greenfield that I don't completely understand (say some algorithm inspired by binary search or any other place where off-by-ones could eat you alive) then I would say there is little difference between coding and testing; mostly I use tests and the Java debugger the same way that Ruby or Python people use the REPL, except my tests get checked in at the end.

Another case is dealing with legacy code where I often end up writing tests to document existing behaviors and prove that the system behaves correctly after refactoring. I've seen many code bases that were awful (written by the kind of people who struggle to have unique primary keys) but were salvageable because they had a test suite.

Then on top of that there are a number of special cases too; for instance, if you are doing something with threads that is complicated at all you probably want to write a load balancer or if you're doing classic Map/Reduce you'd better test your mappers and reducers thoroughly before you ever touch a cluster.