Chapter 4. Polymorphism with multimethods
This chapter covers
- What polymorphism means
- What method dispatch is
- Clojure multimethods and how they work
Many years ago, when I was learning the Java programming language, I read a book by Bruce Eckel called Thinking in Java. Although I thought it was a great book and learned a lot from it, over the years I’ve realized that the title of the book is a specific instance of a common curse. It’s a curse that afflicts a majority of program-mers—if programmers know only a specific language, they soon begin to think only in terms of what’s possible (expressible) in that language.
In our industry, this is manifested in several ways. The most common is that, on average, a programmer fluent in several languages is a better programmer than a programmer who knows only one language. This correlation is because each language has slightly (sometimes very) different concepts and models that programs are expressed in (for instance, objects in Java/C++, prototypes in JavaScript, functions in Haskell, and so on). The corollary to this observation is that a programmer familiar with many different languages is often an even better programmer than the programmer who’s familiar with several similar ones.