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:

There are two sources for the video:

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.

5 Responses to “Top-down TDD for Clojure”

  1. Twitter Trackbacks for Exploration Through Example » Blog Archive » Top-down TDD for Clojure [exampler.com] on Topsy.com Says:

    […] 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. […]

  2. Matthew Todd Says:

    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)))

  3. What you need to be reading this weekend: 02/04/2011 — Scrumology Pty Ltd Says:

    […] RT @marick – Top-down TDD for Clojure: I’ve recorded a 43-minute screencast. It’s a decent… […]

  4. giorgiosironi Says:

    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/ :)

  5. jlink Says:

    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.

Leave a Reply

You must be logged in to post a comment.