|
|
|
|
|
by garybernhardt
6057 days ago
|
|
The thing preventing infinite implementation is a combination of (1) the rules of simple design and (2) the definition of "simple". I write about those in the follow-up to this post: http://blog.extracheese.org/2009/11/the_limits_of_tdd.html I've said this several times across several forums since publishing this post, but my goal was to write a very brief example of "doing the simplest thing". It's not about doing the entire TDD process on a real-life software problem, because that post would be so long that no one would read it! :) I don't think TDD can't be adequately demystified in any short example. |
|
Not having done any TDD, I'm feeling the same way as most of the responders here so far, and I think the problem is that Fibonacci is too trivial.
Although, I can come up with something even more trivial - suppose you wanted to TDD a "Hello World" program. Would you start your first test by verifying that the first letter of the output is 'H', and implement as your simplest implementation something that prints only 'H'?
I'm not sure how the design process works under TDD, so, here's a couple of questions.
Suppose you already have some implementation that represents a tic-tac-toe board and you need to determine whether a winning position exists on the board.
Do you begin by working on the X_Wins() method, or do you start looking at a smaller method, say, Count_Xs_in_Row(row)?
If the latter, do you do the same thing for this method as for Fibonacci? (first iteration: return 0. second iteration: return 1 if the first cell is X, else 0. 3rd iteration: return 2 if X, else 1 if Y, else 0. Iteration 3: Truth table. Iteration 4: refactored into a counter with incremented for each X found.)
If the former, well, basically the same question. Do you begin by checking for one row of X's, then eventually expand to checking all 6 row/column combinations, then refactor out the method? (I initially thought this would require many more iterations... but it seems 7 test cases are enough)
Well, in any case, Tic-tac-toe would be quite a bit longer, but it would probably be much better for introducing TDD. Explanations aren't necessarily required - just seeing all the different iterations of the code would be fairly instructive.
Perhaps use Etherpad for their timeline capabilities?