4 ms·
Also, plain old data interfaces are very desirable. They decrease coupling. Get the data off the interface and restructure it (renaming, preprocessing...) in a
by jstimpfle 11y ago
Also, plain old data interfaces are very desirable. They decrease coupling. Get the data off the interface and restructure it (renaming, preprocessing...) in a suitable way before implementing the actual functionality. This decrease in coupling makes representation changes in the interface more practiceable.
Of course sometimes stateful (procedural) interfaces are a must, but it's surprising how many painful OOP classes can be replaced with a "const struct foo" interface with a clear meaning to the data in it.
- eru 11y agoHigher order functions are one tool to help transform procedural interfaces into data interfaces---after all that's the whole point of treating functions as data.
- jstimpfle 11y agoWhat exactly is "the whole point of treating functions as data"? Of course you can declare everything is data. You don't need higher order functions for that. But real data is simple and introspectable. Computation is not.
- eru 11y agoYes, even pure functions are not introspectable. All you can really do with a function is call it on a value and get a return value. (For the sake of simplicity, I am ignoring side effects here.) Let me try to rephrase with an example. Eg you might have an API for a file that allows you to open a file, manipulate it, and then close it. That's a very procedural interface. As an alternative, think of an interface like the following: withOpenFile(filename, manipulator) that opens a the file, calls the manipulator function on the contents, and automatically closes it. Or compare map, filter and reduce vs manually iterating over a collection of items. I did really like your grandfather comment (https://news.ycombinator.com/item?id=11099224 https://news.ycombinator.com/item?id=11099224). I hope I've cleared up my point?
- jstimpfle 11y agoThanks :-)
- anonyfox 11y agonitpick: in Javascript you can actually call functionName.toString() and get the implementation. AFAIK angular did this trick to implement their dependency injection mechanism.
- eru 11y agoYeah, but that's evil. And even with the source code, the only decidable properties of Turing complete systems are trivial. (Eg you can't even tell in general whether a given function will eventually return or loop forever from the source.)
- jstimpfle 11y agoThat doesn't show the actual values in the closure. Which are subject to change anyway.