Repeat yourself, do more than one thing, and rewrite everything (2018)
I've said it before and I'll say it again - I should encapsulate it as a law.<p>BeetleB's Law of DRY: Every article that complains about DRY will be a strawman argument.<p>The DRY acronym came from <i>The Pragmatic Programmer</i>, and almost every instance of DRY people complain about is <i>not at all</i> what is advocated in the book. There are different ways of interpreting what he wrote, but my version is: "If you have two separate requirements that are very similar, keep them separate in code. If your duplicated code is <i>one</i> requirement, then DRY it into one location in your code."<p>So this:<p>> Following “Don’t Repeat Yourself” might lead you to a function with four boolean flags, and a matrix of behaviours to carefully navigate when changing the code.<p>Is not DRY. In fact, having boolean arguments is almost a guarantee that you've violated DRY.<p>Another way to know you've violated DRY: If one requirement changes, do I need to add if conditions to the DRY'd function to ensure some <i>other</i> requirement doesn't break? If yes, you're in violation.<p>Never tie in multiple requirements into one function. Or rather, do it but don't call it an application of DRY.