2 ms·
> I don't recall ever writing my own protocol, record, or struct. I'm honestly extremely surprised. Protocols seem sort of essential if you want two different
by geokon 2mo ago
> I don't recall ever writing my own protocol, record, or struct.
I'm honestly extremely surprised. Protocols seem sort of essential if you want two different "things" to exhibit the same behavior.
The whole set of immutable datastructures are fundamentally backed by them (well they use Java Interfaces but its fundamentally the same). Not entirely sure how youd implement them without Protocols
Theyre also sort of essential if you want plug-in backends for any part of your codebase.
Im curious what your go-to is currently? Do you just write multimethods and dispatch on the inferred input type?
- Jeaye 2mo agoI also rarely use multi-methods in Clojure. I just use maps and vectors and lists and keywords and strings and functions. Instead of multi-methods, I generally use a map of fns. When not writing open, extendable libraries, this is an even simpler choice which I find works well. Most of my Clojure work has been writing applications, so being able to extend in an open way is not a benefit. I'd prefer to keep everything centralized in one map. Also, as I described above in the blog post, protocols/interfaces aren't needed to implement Clojure's object model either. They're just one approach. They're the nominal typing approach, in contrast with something like the structural typing approach, documented in the blog post. For that, we use C++20 concepts for structural typing predicates.