April 26, 2017

...Learn TDD with Codemanship

20 Dev Metrics - 10. Duplication

Number 10 in my series 20 Dev Metrics is another contributor to higher cost of changing code, Duplication.

When we repeat code, we multiply the cost of changing any of that common logic. We also potentially multiply instances of the same bug. (It's not like in your school exams, where repeating an error you already made doesn't cost you any more marks. Repeated bugs hurt just as much.)

For this reason, we seek to minimise code duplication - except when it makes the code easier to understand.

Thankfully, we don't have to go trawling through our projects, comparing every block of code to every other block of code. There are tools that can do this for us, like conQAT and Simian.

The most interesting about duplicate code is the hints it can give us about generalisations and abstractions that would improve our designs, and so we find that when refactoring code, it's a good thread to pull on.

Posted 5 months, 5 days ago on April 26, 2017