2 ms·
The examples in the introduction are a touch contrived, because if you don't need polymorphism, you shouldn't really be using protocols. In the examples provide
by weavejester 13y ago
The examples in the introduction are a touch contrived, because if you don't need polymorphism, you shouldn't really be using protocols. In the examples provided, it would be more idiomatic to use normal functions.
- moomin 13y agoIndeed. 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.