Don’t Don’t Repeat Yourself

Andrew Pritchard
The Startup
Published in
17 min readSep 4, 2020

--

Summary

  • “Don’t repeat yourself” (DRY) is a widely accepted programming principle, but it has several limitations
  • An alternative derivation of DRY is presented, that aims to alleviate some of these limitations
  • Programs are made up of functions, and to make functions maximally reusable they should:
    - Have the most lenient preconditions
    - Have the most strict postconditions
    - Perform the smallest amount of non-trivial work

If you think this article is too long, you can skip to Should I refactor my code? below

Introduction

An example of an abstraction

In software engineering, “clean code” is a sought after ideal. Code that is “clean” is easy to read, understand and maintain. Unfortunately, what clean code looks like is often disputed. Some commonly accepted software engineering best practices have lost sight of their original goals, or do not represent a complete picture. I believe Don’t Repeat Yourself (DRY) may be one of these principles.

DRY is a widespread and generally well accepted best practice in software engineering. The main stated advantage to DRY is that code does not need to be modified in multiple locations. If code has been de-duplicated, then bug-fixes and new features only need to be added once. In addition, code only needs to be tested once…

--

--

Andrew Pritchard
The Startup

The stories I write are a part of a learning journey through life, logic and programming. Share this journey with me.