3 ms·
You would use higher-order functions particularly when you cannot determine the scope of your input ahead of time. For instance when you provide something that
by choeger 5y ago
You would use higher-order functions particularly when you cannot determine the scope of your input ahead of time. For instance when you provide something that searches an unstructured database of documents (e.g., mongo).
In such a scenario, you could apply defunctionalization. But you'd need to re-apply this technique whenever a new filter comes up or one becomes obsolete. Then you would have to make sure that both your client and server have the same version of the API.
If you design a functional system instead, say by allowing filters in a domain-specific language, ala jq, you write your filter function once and never need to touch the API, because it is "complete".
Which alternative do you prefer?
- cratermoon 5y ago> Which alternative do you prefer? It depends. How hard it is to write the generalized functional system and how many filters do I need to support initially? How much do filters really change? The "but what if you need to change something" objection comes up quite a lot. In practice it is often better to apply the knowledge and requirements I have and evolve the system as my understanding changes than to try to anticipate all possible scenarios up front. In the latter case, if I put a lot of effort into something and I make the wrong call I either don't have as many changes as I thought, so it's wasted effort, or changes happen in ways I didn't anticipate, so my solution activity works against me.