July 2005 Archives

On the Value of Duplication

| 2 Comments

Laurent has some thoughts on the value of duplication. They are laudably contrarian.

However, I can't quite bring myself to think duplication is often a good thing. Certainly, for a manager who needs to get a quick assessment of whether a given chunk of code is good enough, it can be expedient to compare it to another chunk that is known to be good.

This approach of looking for duplication will work if the aim is very short term. Humans are good at pattern recognition. We can assume that there are other practices in place to make sure the code works properly (testing for one). If it looks okay and works okay, it probably is okay.

I see a couple of problems here.

For one, why is a manager having to judge whether a given chunk is okay? I know that every manager who has been in the trenches is tempted to go back, even if only vicariously. However, the best people to judge code are programmers who work in the same area. And nobody likes to look bad in front of their peers.

For another, it only applies if the two code chunks really should look alike. Sometimes that will be true: if we are employed it is often because we have experience solving the same type of problem. But new code jury-rigged to fit into a template of the old code, that might be a positively bad thing. Looking at it would not be enough to tell if that was the case.