Do Repeat Yourself

Don’t. Repeat. Yourself.

“DRY”.

It’s the easiest to learn axiom in programming. It’s a rule that’s easy to obey.

“Those two lines of code look the same.”

“I better extract a method.”

“Look ma! I’m DRY!”

And it feels good. There was a measuring stick. It is legible. So what gets measured gets improved.

But it’s not an improvement. There’s so much indirection, nothing is discernable. It turns out that much duplication is incidental.

In the world of habits, we applaud repeated efforts. In the world of code, we chastise repeated patterns.

My friend Michael would say “this code is so dry it chafes”. I think that’s a good analogy.

So write some wet code. Let it repeat itself. Channel that wet code into a river. Paddle a boat down it. Either that, or walk through the dessert.


Published: 2023-07-10

← Home