3 ms·
why not just program to protocols? For complex data structures I typically just hide details behind a protocol and deal with the set of interface functions. Y
by geokon 2y ago
why not just program to protocols?
For complex data structures I typically just hide details behind a protocol and deal with the set of interface functions.
You can then freely mess with the internals and not worry about details
- mrkeen 2y agoI don't know enough about protocols. Will the compiler stop you if you misuse them?
- serpix 2y agoThe compiler will not know if a protocol is not passed to a function expecting a protocol. Whereas a static typing language will not compile. Similarly nothing prevents invoking missing functions of a protocol, you will only know during runtime.
- geokon 2y agoWell you're typically not thinking of a compilation step with Clojure.. so I found the original question a bit not-applicable The goal isn't to introduce .. a compilation step? but to have the program blow up in the spot where there is an type mismatch. If you don't use a protocol you may not blow up, you may generate a nil, and you may blow up much further down the line (or not at all) In the rare instances where dynamic types cause problems, they're virtually always something convoluted like that. The protocol design pattern describes the interface and protects you from hard to debug situations
- harperlee 2y agoIn my experience (mainly when trying to understand the implementation of core.logic), the problem with protocols is that the code inspection tools choke on them.