Luke Winikates

30 October 2016

The Long Spike

I wrote a small piece of code today to add a new feature to Hockey Tonight– tagging the games whose “interestingess” is in the 90th percentile for the coming week with a “weekly top game” badge. It ended up being easy– Clojure has a built-in frequency map function and Stuart Sierra published a library that builds standard deviations and percentiles on top of that.

I’ve been trying to think about when and why I do or don’t practice TDD on my own side projects. I explain my understanding of TDD to people all the time, and I listen to skeptics all the time too. I’m happy using it on all my professional projects. I do it for about half of my side projects, including some where I do it all the time, so where I do it on half the code, and some where I don’t do it at all. Hockey tonight has tests for about 10% of the code– specifically the css generator and the stuff about dates is well tested.

I tested this feature by hitting the refresh button in the browser and reloading the page to see what happened. Writing a test would have been harder, a longer path to feedback, and the feedback would probably have been worse, because I was really looking for a gut feeling about whether it was more useful to me this way or not. I think it is. I’m also not all that concerned about keeping it from breaking. I’ll probably change my mind later and depending on whether the changes need me to write code that’s most easily tested by inspecting data structures or by looking at the UI, I’ll either write an automated test for it or I won’t.

So I guess the point is that testing is not a particularly informative way of looking at this code. I’m not really doing any math with subtle properties of correctness – and what math I’m doing is either trivially easy and I can verify the correctness faster visually than I could with test cases, or it’s like the interestingness algorithm, just thrown together to express my suspicion that games between closely matched teams with strong records will be the best ones to watch. Nothing has substantial edge cases, nothing is interactive, and everything that happens is visible on the single landing page. It’s more like bonsai than like building something for a purpose. It’s a long spike. A charcoal sketch of a more serious program that could exist. A lego building that I’ll put together differently the next time I pick it up.