Unresolved tension and TDD

A standard creative writing technique for avoiding writer’s block the next day is to stop in mid-sentence, ideally with your protagonist in peril. When you stop writing at

“The demo ended, and the lights were turned up. The project leader turned to the customer. The customer frowned for a moment, and said …”

you’re leaving yourself a no-friction starting point for the next morning. And your subconcious, which hates unresolved tension, is going to help by churning away all night thinking about what the customer is going to say, and how the project leader is going to recover. You might go to sleep with a good definite idea of what happens next, and wake up with better ideas.

The same technique works when doing Test-Driven Development. Instead of stopping for the day with tests passing, leave yourself a failing test. Ideally a test for next bit of code you plan to write. Your subconcious, taunted by the image of the JUnit red bar, is going to grind away on the problem until you sit down at the keyboard the next morning. Then, instead of spending time puzzling over what to do next (the coding equivalent of starting a new chapter), you have a very definite task before you: “Get to green”. And you have the benefit of whatever ideas your subconcious came up.

Once you’ve resolved the conflict by making the failing test pass, you have momentum to move on to the next test.

This technique works even when you realize on the way home that you screwed up the test. It’s just a different form of unresolved conflict.

Comments are closed.