Don’t Repeat Yourself


“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system”.


DRY on wikipedia makes for good light introduction. Go ahead, read it.

While the DRY on c2 provides reasoning and qualification on where duplication is not a DRY violation. Go ahead, read that too.


When in doubt, I like to apply “two is a coincidence, three is a pattern”. Especially when the code has not been proven correct yet.

Avoid redundant naming / qualifications.

While the concept is simple, it takes some experience to see how ruthlessly it can be applied.

For example, in combination with higher-order functions you can take WET

while True:

and DRY it as

def forever(fn):
  while True: