Clean code is like clean garbage – it’s only clean if it doesn’t exist. In other words, the only clean code is no code. Let’s start with an acknowledgment that a perfectly clean (empty) codebase is useless. With that in mind, our pursuit of clean code will necessarily consist of tradeoffs. We’ll trade usefulness for cleanliness, complexity for speed, ownership for ease of development, and abstractions for reusability.
DRY (don’t repeat yourself) code is often held aloft as an ideal in the quest for clean code. Before we jump in too deep, let me shamelessly plug my new computer science learning platform Qvault, check it out if you like CS and like to write code. With that over with, let’s explore why I think DRY can be a good heuristic, but far from an absolute.
Don’t repeat yourself is a principle aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy. Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.