3 ms·
Whatever we call it, e.g "OO", inversion of control, dependency injection, polymorphism, function pointers, ... This can all be summarized in one question: "ca
by Ace17 10y ago
Whatever we call it, e.g "OO", inversion of control, dependency injection, polymorphism, function pointers, ...
This can all be summarized in one question: "can old code call new code?".
This is required to build a proper modular architecture (and BTW this paradigm is used by lots of C projects like the Linux kernel, VLC, ffmpeg, GPAC).
This doesn't go against the fundamental principles of FP ; as long as the type system of your language doesn't need to know "all" types (i.e including the ones you're going to your project later).
- jdmichal 10y agoThis is why I have generally moved to contract-oriented programming with dependency injection. In C# and Java this manifests as interfaces. In Rust they would be traits. I believe Haskell type classes would serve the same function. So, you can call new code from old code fine, as long as your new code implements the contract. This was really based on the realization that the Liskov substitution principle effectively mandates that every object type is an implicit contract. Not breaking that implicit contract in polymorphic code is what LSP is about. So then the question becomes, why not just use the construct that directly corresponds to a contract instead? That way you can reserve polymorphic constructs for actual identity (IS-A) relationships and cleanly maintain SOLID principles. EDIT: Reading a bit further down to romaniv's comment [0], I think this is possibly what Kay discusses as the ADT approach. I've never heard of that before, but based on the Wikipedia article it seems to fit the bill? [0] https://news.ycombinator.com/item?id=13931826 https://news.ycombinator.com/item?id=13931826