Does TDD shun reuse?

Jul 9, 2003 00:05 · 224 words · 2 minute read

Mike Hogan asks whether Test Driven Development discourages component reuse. He gave a simple, clear example where he made a “grep” routine more flexible by delegating some of the function to other interfaces. My response:

Reusability is not really orthogonal to function, but comes as part of the function. Because we’ve all been taught in school that changing software is really expensive, the tendency has been to generalize software where it’s not required. If you never plug a new logger or regex provider into that code, the extra effort (and obfuscation) that comes in the ReusableGrep is just not worth it.

If it’s a customer requirement that the grep routine supports those plug points (and you’re delivering an API to them), then that should indeed be tested for and written. If someone is really doing test driven development, they will write those tests.

Or, if in the course of meeting customer requirements, you find that you’ve created a Log4JGrep and a JDK14Grep, then you’ll create the pluggable form through the course of normal refactoring.

I’m echoing some of what Rod said in his post, but I do think that the simplicity aspect is one of the critical parts of being agile. The point is that you don’t add additional layers for the sake of reusability until there is a customer need that requires it.