I was having coffee this morning with colleague Ken Collier and we were talking about Test-driven development (TDD) and the trials and tribulations of trying to implement TDD in a development environment. I left Ken and went out for a leisurely bike ride down from the Ponderosa pines in Flagstaff to the Scrub Oak and Juniper 1,500 feet lower and 15 miles out of town (then back up-ugh).
As I was pedaling down hill thinking back on our discussion, it occurred to me that a developer doing TDD was like a triathlete–attempting to master three different, but integrated sports (running, cycling, swimming) (testing, coding, refactoring). There are several great analogies here. Many developers who are great coders, are like excellent cyclists who can’t swim–they have great trouble competing in the TDD triathlon. If you are an expert cyclists, you have trouble going back and being a novice swimmer. Moving from novice to intermediate to expert in any field takes determination and patience. I once made it from a novice to intermediate telemark skier, but couldn’t devote the time or energy to becoming an expert, so reverted to my downhill skis where I enjoyed the expert slopes once again. It’s hard to become an expert in one sport, much less three.
If a developer hasn’t done much unit testing or refactoring it’s difficult for them not to revert to their highly refined skill area–coding. They are uncomfortable with writing test code and refactoring, so they tend to spend too little time improving.
However, high-quality software development is its own triathlon–it is not a single sport endeavor.
Another analogy between an agile and a sporting triathlon is that the skills are both independent and synergistic. If I’m a great cyclist, but a lousy swimmer or runner, what do I gain by working on getting better at swimming and running? Swimming strengthens muscles that are complementary to cycling/running, and running…muscles that are complementary to cycling/swimming. By striving for mastery of all 3 sports athletes benefit from comprehensive fitness and strength. Specific example – cycling tends to overwork quadriceps and under-work hamstring muscles. Running tends to strengthen hamstrings and calf muscles. Swimming involves more of the upper-body than either cycling or running. Furthermore all 3 sports boost cardiovascular fitness in different and complementary ways.
With TDD I would argue that a great programmer who invests in mastering test-first and refactoring skills will ultimately achieve multiple benefits from this 3-way focus. They get 1) a boost in confidence that the code works under all situations; 2) the ability to make fearless code changes without worrying about what might break; 3) confidence that the design is good and getting better with every refactoring; 4) the pleasure of solving a problem through very small simple changes rather than complex, sweeping ones; 5) comfort in knowledge that the solution doesn’t have to be complete and perfect the first time.
Finally I would add that anybody can go out for a bike-ride, a swim, or a jog; but only athletes who spend time training and honing their skills develop the ability to successfully compete in triathlon events. Similarly, someone can write some code, write a few xUnit tests, and make some ad hoc improvements to the code; but only skilled programmers who are dedicated to their craft can write healthy, durable xUnit tests; followed by well designed code, which is improved by intentional refactoring.
Thinking of TDD as a triathlon and then considering how you would approach building and integrating the individual TDD skills as if it was a sporting triathlon could help you become an outstanding TDD triathlete.
Note: Significant contributions to this blog were made by Ken Collier.