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.
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.
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.
Now you can annotate values with the dataset they originate from, and implement arithmetic for that layer as unioning the data sources.
What& #39;s really interesting is that they implement all of this by building off a DSL they& #39;ve written for doing generic dispatch. They use Lisp, but the ideas are applicable within any language.
They& #39;re not using a toy language to show off the idea: it& #39;s just normal code.
They& #39;re not using a toy language to show off the idea: it& #39;s just normal code.