- Title: [[The Unreasonable Effectiveness of Multiple Dispatch - JuliaCon 2019]] - Type: #source/video - Author: Stefan Karpinski - Reference: [JuliaCon 2019 | The Unreasonable Effectiveness of Multiple Dispatch | Stefan Karpinski - YouTube](https://www.youtube.com/watch?v=kc9HwsxE1OY) - Published at: - Reviewed at: 2023-06-05 - Links: --- Multiple dispatch is a key feature of [[Julia]]. In practice, there's been a large amount of code re-use in the ecosystem. Multiple dispatch was a design decision to enable expressing generic algorithms. Two Kinds of code re-use 1) Generic algorithms (applied to many different types) 2) Common types can be widely shared across packages (similar to traits / type classes) ## Part I - generic algorithms Superficially, looks like function overloading (C++ / Java). - **No dispatch** e.g. a function `f(x1, ... xn`) calls that function - **Single dispatch** e.g. a method, uses the type of the first argument e.g. `x1.f(x2, ... xn)` - **Multiple dispatch** matches all argument types In a single dispatch language, you could hack double dispatch and have the first method match on the second argument. ## Part II - Common Types Add methods to existing types (similar to [[Kotlin]] extension methods). You don't want to inherit the base type because you now have a new type and your new methods only apply to this new type (and inheriting is potentially brittle). You also can't necessarily add multiple extensions. This gets to the heart of [[The Expression Problem]].