I've recently participated in a number of after-the-fact code reviews. Developers are supposed to be writing tests first, and are supposed to ask for help when they're not sure how to do so. Here's what it looks like:
C = one unit of time spent coding T = one unit of time spent testing I = " " " " " in an inspection or review meeting R = " " " " " doing rework based on results of review x = " " " " " doing other work CCCC xxxx TTTTT xxx IIIII RRR II
We're obviously in TAD (test-after development) mode here. Pay attention to the right hand side, which roughly indicates: When could this code actually ship?
Note that there are multiple Rs because many people are involved in the review meeting. Also note that there is a little more time spent on testing, and yet the coverage never ends up good enough (rarely more than 75%). And finally, note the rework and re-inspection that must take place.
What the same model looks like with TDD:
TCTCTCTC xxxx IIII xxx RR I
So, a little less time building the right code in the first place, and also means a little less time in rework. It also means a little less time in review meetings, since the tests can help effectively describe whether or not the developer captured the requirements correctly.
With pairing and TDD:
TTCCTTCCTTCC xxxx xxx
I've doubled up the Ts and Cs because there are now two people involved. I'm not even going to claim that pairing developers will produce a better solution faster, even though I've seen this to be the case. Note that this is now the shortest line by far. (It will even accommodate some amount of formal review--much smaller now because it's already been actively reviewed at least once and preferably twice by the pairs building it--and still be shorter than the original process.)
I'm also not accounting for "ramp-up" time wasted. The intervening xxx's in the inspection-based flow means that minds have moved on to other things. When it comes time to review code, or rework it, developers must put their head back around something that they might have done days ago. Particularly without good tests, this can waste considerable time.
I'm in an environment now where test-first is only beginning to take roots. Every day I see ample evidence why test-after is simply a bad, bad idea.
February 2004 March 2004 May 2004 September 2004 October 2004 January 2005 February 2005 September 2005 October 2005 November 2005 December 2005 January 2006 February 2006 March 2006 June 2006 August 2006 January 2007 February 2007 March 2007 April 2007 September 2007 October 2007 November 2007 December 2007 January 2008 February 2008 March 2008 April 2008 May 2008 June 2008 July 2008 August 2008 September 2008 October 2008 November 2008 December 2008 January 2009 February 2009 March 2009