I’ve been listening to Corey Haines talking about his exploration of Kent Beck’s 4 Rules of Simple Design, and he has brought up an exceptionally important point about the Don’t Repeat Yourself (DRY) principle. DRY isn’t about running an automatic repetition detection tool on your code base, and making sure it finds nothing. But rather it’s about not repeating the knowledge in the code. There’s incidental, and there’s essential repetition. Chasing the incidental repetition is a road to hell: things that look the same today will most certainly change differently in the future.
Just as almost everything else in software, the essential DRY can be traced back to a paper from the 1970-s. This time, it’s Parnas’es “On the criteria to be used in decomposing systems into modules”. Encapsulating a design decision into a module, suggested by Parnas, is pretty much equivalent to not repeating knowledge in the code.