Wednesday, June 21, 2006

Sailing too far from the shore

I've been looking for a metaphor to describe the situation when too many tests are broken. In the normal course of TDD only one or two tests are broken at a time (generally the new one I just wrote). However, sometimes I find myself breaking lots of tests, maybe lots of my code doesn't even compile. I've come to recognise this as a bad situation, because although my purpose is correct, and the changes I am making are valid, any significant time where my tests are broken (so I can't check in) is bad. The time taken to fix broken tests is roughly proportional to the number of broken tests, so the more that are broken, the longer it will be before I can check in.

Now when I see these signs, I turn to my pair and ask, "Do you think we might be sailing too far from the shore?". To understand the metaphor, imagine that you are traveling along a beautiful coastline in small sailing boat. You progress in a series of zig-zags, sailing out into the sea, then returning to the shore. Dry land represents the security of all tests passing, while the sea is the dangerous world of broken tests. The wind feels stronger over the more dangerous water - perhaps you are traveling faster. However, the further you are from the shore, the more tests are broken, and the longer it will take you to sail back to dry land, or to fix the tests. If something goes wrong while at sea (your compass breaks, your sail tears) then the coast guard tows you back to the point that you were last on dry land. This failure scenario represents having to throw away your changes, and no real progress being made. The change of your excursion failing is greater if it is a larger step, so it could be more efficient to make lots of small excursions than a few larger ones. It all boils down to saying "check in often".

I find this particular metaphor useful because I like to visualise the journey to get the code back into a passing state. It also makes me think about the size of task that I am biting off, and try to find a way to break it down into a series of smaller excursions into the sea.

0 Comments:

Post a Comment

<< Home