July 08, 2005

Those other red bars

You have prepared your kata, you can perform it in 35 minutes top, eyes closed, speaking in the same time. You can mentally see the lines flow, as you finally rehearse your speech in the subway, on your way to the dojo. Nothing will prevent you from success -- that is, getting in an hour from nothing to a full-featured piece of code that passes all the acceptance tests, with everyone understanding your code enough to be able to rewrite it alone at home later.

Then you do it. You start writing code in front of everyone else, the first ten minutes and three tests going smooth. Then you write the fourth test and say confidently that it's going to be a bit trickier here everyone please pay attention. And you realize that some in your audience start frowning. You're writing your sixth line of code (you know you need seven to have the test pass) and someone eventually say -- "ok, please stop here. I'm lost. What are you trying to do?"

First you want to dismiss the comment and just go on, since you know that any stop and discussion will prevent you from finishing on time. And then you remember that you have to have everyone on board when you finish. So you open your mouth to answer, "well, I'm trying to pass this test". But of course everyone knows that, already. That's actually when they started losing you. So you just say "could you please wait for one more line, then you'll understand what I'm doing". So you write your extra line, the test pass, but nobody understands why. And now you start explaining the subtleties of your design, but someone cuts -- "wait, I still don't get it. Where are your tests ?"

This is the moment when you start getting pissed off. You are sure that the person actually knows what you mean, they are just attempting to trick you into not finishing the kata and proving you wrong. You want to say something snappy, you realize the moment you are about to say it that it is actually very rude, or vulgar, or both. You eventually gather some courage, and admit how pissed off you are, put a bit of self-deprecating humor behind it to make sure everyone knows it is nobody's fault but yours, you take a deep breath, and face the fact -- you still don't master the kata.

When we perform in front of everyone, we tend to focus on the test bar. When it's red, we want to have it turn back to green as soon as possible. In the same time we don't want to write tests that are too simple -- just in case it would take too long to perform the whole kata. It seems that we are looking for a compromise between the complexity of the test and the time the test bar remains red. While this sounds sensible, we need to realize that there are actually other red bars.

One of them is when your audience stop understanding what you do. It's ok for a while if what you write is unclear, as long as you fall back to some clear state very soon after. When we write bigger tests, we risk keeping this second bar red for too long -- and 'long' here is actually very short. Seconds? Dozens of seconds?

And of course, there's one more bar -- the one telling you if you are detached from your code enough to be able to accept feedback. I suspect that as soon as this bar goes red, you are in deep trouble -- because now you have to spend extraordinary amounts of energy and time to go back to a state in which you can actually discuss with your audience. This very energy and time you should use at coding instead.

So it is not just the test bar that we want to keep red as shortly as possible, it is also the attention bar and the detachment bar. I am starting realizing that I can't do so without writing very, very small tests, one step at a time.

Posted by Emmanuel at 05:02 PM