DRY: Don’t Repeat Yourself.

Programmers talk about the virtues of DRY code, as opposed to WET (We Enjoy Typing! Write Everything Twice!). The virtue goes beyond funny acronyms: code that eliminates unnecessary repetition is easier for an outsider to read and understand. It’s also easier to extend functionality as the program grows.

Understanding vs Doing

Understanding the value of writing DRY code, and actually doing it are two different things. Although I long for simple and eloquent code, usually my first solutions are anything but DRY. And this may be a good thing.

When I was in high school I remember a math teacher getting frustrated with me for not writing enough steps in my solutions - “Show your work!” Some of the steps seemed so simple I couldn’t bring myself to write them down – I could already see several steps ahead, and at the time I felt embarrassed to show such elementary ‘extra’ work. Not only did I frustrate my teacher with this stubbornness, but I made things more difficult for myself: when things didn’t turn out as planned, it was harder to catch mistakes in the assumptions that I had left unwritten.

The (WET) road to DRY

When I try getting too far ahead of myself with coding I end up tangling things up. If I can allow myself to ‘write everything twice’ just to get initial tests passing, I usually have a much easier time simplifying from there. Starting out WET is only a problem if you never dry off.