August 12, 2022

Don't Repeat Yourself and its Relation to Code and Knowledge

  —A look at DRY in relation to SPOT and OAOO

I got interested in the relationship between Don’t Repeat Yourself (DRY), code structure and knowledge. In my view, DRY is domain based (i.e., system-wide), but leads into structure (i.e., the prevention of code duplication).

The goal of DRY is to retain knowlege in a meaningful way. Meaningful in the sense it is

  • singluar (consists of one “thing”),
  • unambiguous (can be understood),
  • authoritiative (is a resource for containing knowledge) and
  • has representation (has an appropriate structure).

Importantly, it is authoritative not definitive (but it might be).

Definitive might look like a better word, but it implies complete knowledge. Authoritative is better because it implies the development of a shared resource to store, reflect upon and revise that knowledge. So DRY things provide a focal point for revision as you inch towards a definitive definition of that thing.

This means DRY fuses two concepts together: the collection of knowledge and its representation. Breaking it into its base forms you get:

  • Single Point of Truth (SPOT) is about a singular, unambiguous and authoritative source of knowledge. It applies to the domain the knowledge is generated from.

  • Once And Only Once (OAOO) is about representation. It applies structure to knowledge. Since OAOO comes into existence via refactoring it is also the process by which incremental improvement occurs.

Importantly, SPOT helps identify and organize information. OAOO is a structural activity that incrementally improves (but does not change) the implementation.

So how is it useful to include notions of SPOT and OAOO in DRY?

I’ve been reading a lot about how DRY might be bad (or overused) in tests and was wondering how this was possible. Most arguments have insisted that DRY can hide valuable information in tests. I haven’t seen other arguments against DRY so understanding DRY more deeply seem important to understanding when it’s wrong to apply it.

I’m not sure if my breakdown of DRY is accurate but it resonates. I’m not sure if I’ve quite put my finger on a formula for when it’s overused in tests.

comments powered by Disqus