
Multiple Dispatch in Julia - wikunia
https://opensourc.es/blog/basics-multiple-dispatch/
======
ssivark
You might also enjoy Stefan Karpinski’s talk at JuliaCon 2019 about how
multiple dispatch helps make the language more expressive (than OOP, for Eg).
_The unreasonable effectiveness of multiple dispatch_
[https://youtu.be/kc9HwsxE1OY](https://youtu.be/kc9HwsxE1OY)

It seems like such an elegant idea, I’m somewhat surprised no one seems to
have run with it earlier.

~~~
kkylin
I don't think Julia is (or has ever claimed to be) the first system to make
extensive use of multiple dispatch. But it seems to be first one to have
gotten attention, if not widespread adoption, from the broader community
beyond its first intended audience, i.e., scientific computing.

Others mention CLOS, which I don't know too much about. MIT Scheme also
supports multiple dispatch ([https://www.gnu.org/software/mit-
scheme/documentation/stable...](https://www.gnu.org/software/mit-
scheme/documentation/stable/mit-scheme-sos/Generic-Procedures.html#Generic-
Procedures)). IIRC this is widely used in ScmUtils, the software library used
in SICM ([https://mitpress.mit.edu/books/structure-and-
interpretation-...](https://mitpress.mit.edu/books/structure-and-
interpretation-classical-mechanics-second-edition)).

~~~
ssivark
Julia’s definitely not the first, but I don’t see too many examples where they
took the idea seriously enough as a design principle to build the language
around it (that’s what I meant by _“run with it”_ ). I’ve seen Dylan often
credited as one of the inspirations for Julia. While many other languages
might support multiple dispatch, my impression is that they’re somewhat
“patched on”, thereby limiting the benefits.

~~~
kkylin
Absolutely. I guess I was trying to say (not very clearly) that ScmUtils was
the only other example I know of that "ran with it." Though SICM is relatively
well known at this point, I suspect ScmUtils is not very widely used.

------
eigenspace
Multiple dispatch is such a nice feature that whenever I use other languages,
I always reach for it and am immediately disappointed when I realize it's not
there, or if it it is, it's not widely used enough to be useful.

------
xiaodai
The problem with multiple dispatch is that by looking at

`fn(a, b, c)`

you really don't know which code it is running unless you know the types of
`a`, `b`, and `c` which can't be exhaustively enumerated at the point of the
writing the code or reading the code given that someone could use `fn` with
totally different types.

This makes Julia readable, but as the code base grows, it can become unwieldly
as well.

You really need `@which fn(a,b,c)` with known `a`, `b`, and `c` to see which
function it is running.

~~~
johnmyleswhite
Isn't this a problem in any system that allows function names to be
overloaded? Don't you have the same issues if (a) your system has single
dispatch and classes that can be extended outside the module in which they're
originally defined?

~~~
wikunia
I agree and would say that normally dispatch comes in handy for things like
`+`, `length` and of course your own functions where the meaning is the same
but the implementation must be different depending on the type.

