March 25, 2017

Practical Application of DRY

  —A look at how to properly employ the "Don't Repeat Yourself" principle.

In The Wrong Abstraction, Sandi Metz says the cost of code duplication is less than the cost of using the wrong abstraction. I had to watch her Rails 2014 talk to fully understand her point. She discusses the cost of duplication around the 13:58 mark.

I watched the entire talk.  The ideas are presented so well that it's simply brilliant.

The main take-away with respect to the cost of code duplication verse the wrong abstraction is that it's also an argument for delaying the application of DRY until you fully understand the algorithm.

What makes her presentation compelling is the insight she provides on knowing when to apply DRY. It's the first time I've seen someone provide a practical example of why delaying the application of this principle is important.

In addition to the insight provided on applying DRY the talk contains a great deal of practical advice.

The presentation provides a useful tool for explaining the evolution of code through the ebb and flow of complexity during development. The presentation is directed at individuals attempting a refactor. The Wrong Abstraction includes the notion of a team working on the code.

I plan on using the presentation as a vehicle to help my team understand the challenges they are facing in their own struggles with complexity. Having the tools to discuss this challenge goes a long way towards understanding and finding solutions to it.

The Wrong Abstraction introduces the notion of the sunk cost associated with using the wrong abstraction and makes an argument that developers need to recognize this accept that sometimes the best way out of that challenge is to take a back step by reintroducing duplication. It is the step back which provides the opportunity to revisit the abstraction and improve it.
comments powered by Disqus