Top-down TDD for Clojure
I’ve recorded a 43-minute screencast. It’s a decent example of my current style of TDD for Clojure. It emphasizes:
-
The use of Midje prerequisites (mocks) to support top-down development.
-
Using metaconstants to make tests more abstract and readable.
There are two sources for the video:
- Vimeo: http://www.vimeo.com/19404746
-
Download: https://github.com/marick/Midje-videos/raw/master/robozzle.mov (If that fails with “blob too big”, go here and select Downloads:
You’ll get a zip file containing the video in its own directory.
UPDATE
Alert watcher Mark Derricutt notices that I got east and west mixed up. I, um, I… I did that deliberately (no, really!) to illustrate an important point about TDD. TDD helps you do what you intended. It is not particularly good at helping you intend the right thing. Indeed, the flow experience it can induce probably makes you worse at noticing you’re proceeding smoothly in the wrong direction.
For example, I had a niggling feeling throughout that I was getting the orientation wrong. That, plus general principle, made me shy away from just copying the answers from the tests into the rotation maps—instead, I recreated them. All for naught: the incorrect mental image I used when I calculated the first left turn had captured my mind.
This getting stuck in a rut is one of the reasons why you still need testing with a fresh mind (either someone else’s or your own, after a rest).
It’s interesting to speculate whether this bug would ever become visible. If, just after finishing the kata, I’d wired up a UI and chosen four ship images, I’d probably again get east and west flipped, meaning all would look well to the user. It’d be like using y
as the variable representing horizontal position and x
for vertical position: functionally correct if you do it consistently, but death to any sane mind reading the code.
If I chose ship images later, I’d be more likely to get them right (that is, wrong given the bug). I do at times know east from west.
February 1st, 2011 at 12:20 am
[…] Exploration Through Example » Blog Archive » Top-down TDD for Clojure exampler.com/blog/2011/01/31/top-down-tdd-for-clojure/ – view page – cached I’ve recorded a 43-minute screencast. It’s a decent example of my current style of TDD for Clojure. It emphasizes: * The use of Midje prerequisites (mocks) to support top-down development. […]
February 2nd, 2011 at 1:17 am
Thank you, Brian — I’ve had quite a nice time watching this screencast over morning coffee just now.
My present comment is beside your main point, but for what it’s worth, I notice that the need to increment the move-count (41:45) could be avoided by taking from the original move list instead of the trail:
(trail (voyage start (take move-count moves)))
February 4th, 2011 at 11:07 am
[…] RT @marick – Top-down TDD for Clojure: I’ve recorded a 43-minute screencast. It’s a decent… […]
February 4th, 2011 at 12:24 pm
Actually I use often x and y for vertical and horizontal directions, respectively, in Matlab. When representing an image as a matrix, this way you get x to index the rows and y to index the columns; at the same time the right hand rule still works.
East and West are probably less useful to flip, but someone has tried: http://flourish.org/upsidedownmap/ :)
February 24th, 2011 at 8:09 am
Brian, I get a “blog too big” error message when trying to download robozzle.mov.
jlink: I’ve updated the instructions with an alternate source.