Live data from Hacker News

Multiple Dispatch in Julia

opensourc.es

11–16 of 16 posts

Re: Multiple Dispatch in Julia

#11
post #2

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 It seems like such an elegant idea, I’m somewhat surprised no one seems to have run with it earlier.

The power of multiple dispatch is an eye opener for me personally when I first learned about Julia.

It's hard to get back to OOP once you're used to multiple dispatch. It's so natural and gets rid of the the question of "which class should I write this method in"?

Re: Multiple Dispatch in Julia

#12
post #6
post #4

Earlier quoted context omitted.

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-…

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.

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.

Re: Multiple Dispatch in Julia

#13
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.

Re: Multiple Dispatch in Julia

#14
post #13

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 rea…

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?

Re: Multiple Dispatch in Julia

#15
post #13

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 rea…

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?

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.

Re: Multiple Dispatch in Julia

#16
post #13

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 rea…

It exists! `@which fn(a,b,c)` will do exactly that. There's also `@less fn(a,b,c)` if you want to take quick look at the source code for the relevant method, or `@edit fn(a,b,c)` to open the relevant source file in an editor.
Post reply on HN