Police | Don't Repeat Yourself

“Don’t Repeat Yourself”: What it Means, and Why Not

Anyone who works with websites should have a general understanding of the virtues of doing it right in web development. This requires two things:

  1. Knowing what “doing it right” means.
  2. Knowing why “doing it right” matters.

Here, we’ll try to talk through a core programming principle that, if you understand it, will help you a ton with both pieces above: the principle of “Don’t Repeat Yourself” (DRY). We’ll start with a quick analogy.

A Website is a Factory

Henry FordA well-designed website is all set up to churn out the pages of your site, in the same way a car factory is all set up to churn out cars. That means most of the work is in getting the factory itself set up—then you can make however many cars (or webpages) you want for almost free.

But let’s play devil’s advocate. Building a car factory costs billions of dollars; why not take all that money, and those hundreds of workers, and just start building cars from the ground up? You could build a lot of cars by hand before the factory justified its cost.

Understanding DRY

Building cars by hand is the logic of bad web development, and it does indeed save time the first time you do something. This could be anything from copy-pasting useful bits of code into each file on your site, to coding your navigation menu in static HTML, to styling things inline rather than using a CSS stylesheet, to putting together individual pages by hand without using some form of template.

The problem with this “pre-industrial” approach is that doing things never gets any easier: every time you want to create a new page, add a new element to your navigation menu, or style a new paragraph, you’re back at square one.

Perhaps 60% of “doing it right” in web development boils down to: Don’t Repeat Yourself!

In other words, you end up repeating yourself a lot, and you eventually get bogged down. You should have a gleaming factory set to churn out cars, but instead you just have a bunch of guys building cars by hand. That’s no way to run a factory, and it’s no way to build a website. So perhaps 60% of “doing it right” in web development boils down to: Don’t Repeat Yourself!

Web development elements like cascading stylesheets (CSS) and PHP scripting “industrialize” web development: instead of doing exactly what you want every time, you build the machinery to do the type of thing you want to do, and then do it repeatedly using that machinery. It’s a little more time-consuming the first time around, but the advantage is that when you do it again, it’s not from scratch.

How to Use This

The first piece of advice is to stick to “Don’t Repeat Yourself” in your own work. If, in your do-it-yourself work, and you find yourself copy-pasting a block of code over and over again, something’s wrong. Do more research or find someone who can help you.

When Hiring Developers

If you’re non-technical, it’s really hard to know what code does and doesn’t conform to “Don’t Repeat Yourself”—since both kinds of code look the same on the surface. Our best advice would be simply to look for developers who have orderly minds: they’re very organized in their thinking, they like doing things right the first time, and they get visibly uncomfortable when you ask them to just do it “wrong for now.” Those are the people who can build you the factory you actually need for the long haul—not just the car you need for right now.

Thanks for reading!

Like what you've read? Subscribe!

When you sign up to get notified of our newest article every Thursday, you'll also get an awesome free ebook about content marketing. Sign up now for that double win!

Leave a Reply

Please use your real name instead of you company name or keyword spam.