Wednesday, August 26, 2009

TDD Clinic: C++

My last session for Monday was a workshop on applying TDD (Test Driven Development) to C++ code given by James Grenning and Bas Vodde. Most of the session was spent working with actual code, doing pair programming. We needed to implement a circular buffer; I suggested to my team that we use a std::deque, but James considered that cheating and would not allow it.
;)

Working through the exercise was very instructive on the dynamics of TDD. As you can imagine, given the short time frame of the session, the exercise was not overly complex. However, the way the exercise was constructed lead us to cause (and find) a couple of regressions as we were implementing the circular buffer. One important thing I learned about TDD is that when you write code to pass a test, you really must write a minimal implementation, something that will just barely pass the test. Then, you write another test, and you implement something to barely pass that test, and so on. Only that way can you make sure that the test suite your end up with has maximum coverage.

At some point during the exercise, James Grenning mentioned a book by Michael Feathers that could prove useful for our department (if we don't already have it, I don't know): "Working Effectively with Legacy Code". I should also say that Michael Feathers said in another session (I'll post about it later) that "legacy code is code without [automated regression] tests".

1 comment:

  1. We have that book "Working Effectively with Legacy Code" in our CoreTech library.

    http://wss.cae.ca/montreal/departments/ProdAndTech/Architecture/Lists/Library

    ReplyDelete