One of the coolest ideas from "Software Design for Flexibility" is what the authors call "annotation layers".

Essentially, the idea is that you can augment data with additional layers of context, and then write variants of your functions that operate on those layers instead.
The most trivial example would be layering units onto a number, and then implementing arithmetic operations for the unit layer to combine the units together according to the standard rules.

Now units propagate through your calculations, and aid in debugging and display.
They give other examples of layers though, and one that I thought was fascinating was a "support" layer, that tracks the provenance of data.

Now you can annotate values with the dataset they originate from, and implement arithmetic for that layer as unioning the data sources.
What's really interesting is that they implement all of this by building off a DSL they've written for doing generic dispatch. They use Lisp, but the ideas are applicable within any language.

They're not using a toy language to show off the idea: it's just normal code.
Units show up in languages like F# or Frink, but I've never seen such a clean design for implementing them at the library level before; and never in a way that's generic enough as to be useful for other sorts of annotations, like type signatures, dataflow, or security levels.
Anyway, this book is amazing, and layers only take up a small portion of what's an entirely thought-provoking work.

I think they're onto something with what they're calling "additive programming", and I can't wait for some of their ideas to start showing up in real code.
You can follow @wilton_quinn.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: