News for hackers. Stuff that matters.
Re:“What if it changes?” by CraigJPerry on Monday May 23, 2022 @05:02AM (#31476729)
Do you know if there’s a name for this pattern? I admire it all the time in Peter Norvig’s code. It leads to very approachable code.
Re:“What if it changes?” by akavel on Monday May 23, 2022 @07:18AM (#31477576)
I don't know if there is an official name, but in my head I call it "helpers/components/mixins are better than frameworks." Or, "if one happens to want to write a framework, one ought to try hard to refactor it 'inside-out' to a set of composable components."

The most important (though not only) issue with frameworks is that you typically can't compose/mix more than one together - every framework is "exclusive" and takes control of the code flow. Whereas "components" can usually be easily mixed with each other, and leave control of the code flow to the programmer.

Re:“What if it changes?” by davejohnclark on Monday May 23, 2022 @07:30AM (#31477661)
I generally think of this as the same principle of "prefer composition over inheritence". Leave the top-level free to compose the behaviour it requires rather than inheriting the framework's behaviour, for exactly the reasons you describe.
Re:“What if it changes?” by DougBTX on Monday May 23, 2022 @08:48AM (#31478320)
This is frameworks vs libraries. In the first case the framework is calling the code with config and hooks to change behaviour. In the second case there are common library functions called from completely separate “application” code.
Re:“What if it changes?” by m12k on Monday May 23, 2022 @06:41AM (#31477307)
I don't know an official name for it. It seems like it's almost too basic - "subdivide into helper functions" - to make it into the Gang of Four or other design pattern collections. But in my head I'm calling it the "Recipe Pattern"
Re:“What if it changes?” by actually_a_dog on Monday May 23, 2022 @08:19AM (#31478045)
It sounds like a version of the strategy pattern to me.

https://en.wikipedia.org/wiki/Strategy_pattern