5 ms·
Indeed. Also, there's a lot of different approaches to polymorphism in Clojure, all of which are valid in context. Protocols are fast but quite limited. Pers
by moomin 13y ago
Indeed. Also, there's a lot of different approaches to polymorphism in Clojure, all of which are valid in context. Protocols are fast but quite limited.
Personally, I find it better to start with the freedom of multimethods for several reasons: 1) Protocols push you down OO roads 2) It could be a premature optimization 3) Multimethods are brilliant for discovering the most elegant design.
The last point bears expanding on: multimethods don't bundle methods together, allow hierarchies not based on Java's inheritance, can dispatch on arbitrary strategies. Going protocol too early tends to lead to too many concrete types and not enough straight-forward data manipulation.
Which is not to say that protocols aren't brilliant. It's just that it looks like the first tool you should reach for and it's probably the last. Note the article is from 2010, when protocols were the new shiny.