When DRY fails

  • DRY (Don’t Repeat Yourself) is about avoiding duplication of effort when writing the code. It also makes sure that when a bug is found it’s fixed across the board. Like many other principles, this one doesn’t work all the time.
  • If DRY fails, it’s a good practice to reconcile. The simplest way to reconcile is to write a test that reads data A and data B and fails with a diff if they are out of sync.
  • Try having a great test suite that’s ideally 100% coverage and 100% mutation tested that you can run on both pieces of code.
  • Reconciliation does not mean synchronizing, overwriting,  comparing or even being disciplined and manually changing both places.
  • Reconciliation means checking all the data regularly and reporting all discrepancies, including fine-grained discrepancies.

Full post here, 3 mins read