2 ms·
The term "DRY" as commonly used conflates distinct situations and objectives that should be handled differently in most cases. There is the "single source of t
by jandrewrogers 2y ago
The term "DRY" as commonly used conflates distinct situations and objectives that should be handled differently in most cases.
There is the "single source of truth" problem where you need to compute something exactly the same way at all points in the software that need to compute that thing. In these cases you really want a single library implementation so that the meaning of that computation does not accidentally diverge over time since there is a single implementation to maintain.
There is the "reuse behaviors in unrelated contexts" problem where you want to create implementations of common useful behaviors that can be abstracted over many use cases, often in the context of data structures and algorithms. In these cases you really want generics and metaprogramming to codegen a context-specific implementation rather than sharing a single implementation with a spaghetti mess of conditionals.
DRY works best when it fits neatly and exclusively into one of these two categories. Cases that fit in neither category, such as the practice of decomposing every non-trivial function into a bunch of micro-functions that call each other, are virtually always a maintenance nightmare for no obvious benefit. Cases that fit into both categories, such as expansive metaprogramming libraries, become difficult to maintain by virtue of the combinatorial explosion of possible implementations that might be generated across the allowable parameter space -- the cognitive overhead grows exponentially for what is often a linear increase in value.
- a1369209993 2y ago> such as the practice of decomposing every non-trivial function into a bunch of micro-functions that call each other, That has approximately nothing to do with DRY. At best it might technically be a violation of DRY if (and only if) some of those micro-functions are identical, but the correct way to fix that is to recompose them into the non-trivial (and non-repeated) functions they're more usefully expressed as. And more often it's just a totally independent refucktoring that makes the codbase worse entirely orthogonally to 'DRY-ness'.
- skydhash 2y agoCommon Lisp works well for the second case. But it seems that some programmers are uncomfortable with the notion of code generating code. And as you said, it does require discipline as you need to focus the language's power. Other languages don't let you solve the boilerplate problem so readily. Instead you have a mess of utility functions or a huge class tree.