# The order of multiple dispatch

**URL:** https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979
**Category:** New to Julia
**Tags:** first-steps
**Created:** [June 24, 2020, 1:25pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979 "2020-06-24T13:25:12Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 1:25pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/1 "2020-06-24T13:25:12Z")

</div>

Hi, I am learning Julialang on Mac and Windwos.  
I have a question about the order of multiple dispatch.

function dfunc(args::Int64)  
println(“Int64”)  
end

function dfunc(args::Any)  
println(“Any”)  
end

julia\> dfunc(255)  
Int64

julia\> dfunc(“Test”)  
Any

Yes,These functions work as expected.  
However, is the order in which they are evaluated clearly defined?  
My question is whether we don’t need to worry about Int64 being evaluated by **Any**.

I look forward to your kind advice.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [June 24, 2020, 1:29pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/2 "2020-06-24T13:29:57Z")

</div>

> [@mitsuruk](#):
>
> However, is the order in which they are evaluated clearly defined?

The order doesn’t matter. The method with the most specific signature that matches the argument types will be used.

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 1:37pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/3 "2020-06-24T13:37:07Z")

</div>

Dear kristoffer,

Thank you very much your advice.  
I understood that multiple dispatch is managed by signature.

If you know the location of the relevant Julia source code, could you let me know?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [June 24, 2020, 2:00pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/4 "2020-06-24T14:00:08Z")

</div>

> [@mitsuruk](#):
>
> If you know the location of the relevant Julia source code, could you let me know?

Dispatch is handled by a pretty low-level part of the Julia implementation; reading through the dispatch code is not something likely to be helpful for someone just starting to learn Julia.

(There are plenty of other parts of Julia that are implemented _in_ Julia with very readable code that it is informative to read. e.g. the complex-number implementation.)

---

<div class="post-metadata">

### Author: ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)
#### Post date: [June 24, 2020, 2:02pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/5 "2020-06-24T14:02:43Z")

</div>

Here is the relevant section of the manual: [Methods · The Julia Language](https://docs.julialang.org/en/v1/manual/methods/#Defining-Methods-1)

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 2:04pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/6 "2020-06-24T14:04:29Z")

</div>

Dear Steven,

Thank you a lot of advice.

I try to read suggestions source code.

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 2:06pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/7 "2020-06-24T14:06:54Z")

</div>

Dear klaff,

Thank you very much for your message.  
I try to understand the docs.

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 2:42pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/8 "2020-06-24T14:42:30Z")

</div>

Dear Steven,

I found “defining and adding methods” in method.c.  
I will try to understand signeture system from here.

Thanks a lot.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [June 24, 2020, 3:23pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/9 "2020-06-24T15:23:11Z")

</div>

Are you planning on learning Julia by reading the C source? That’s impressive and/or borderline crazy😁

I’ve never read any of the C source, and never will. If you are going on a real deep dive, I’m sure it will be a fascinating read, but are you confident that this is the right order? Why not start with the documentation instead?

[https://docs.julialang.org/en/v1/manual/methods/#Methods-1](https://docs.julialang.org/en/v1/manual/methods/#Methods-1)

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 3:46pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/10 "2020-06-24T15:46:05Z")

</div>

Dear DNF,

Thank you for your advices.

Creating languages for myself and playing bass guitar are two of my hobbies.  
C is an easy language for me to understand, as I’ve been using it for work since the 8-bit days.  
I’ll make an effort to read a lot of documentation as you suggest.

Thanks.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [June 24, 2020, 4:53pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/11 "2020-06-24T16:53:56Z")

</div>

I ❤ this. If you have any questions about the source code, feel free to ask on the JuliaLang Slack #internals channel, although you can also ask here but Slack may be more immediate and interactive.

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [June 24, 2020, 5:05pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/12 "2020-06-24T17:05:46Z")

</div>

Nice! If you’re interested in how method specificity is defined, look at the functions with `morespecific` in their names in src/subtype.c.

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 8:38pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/13 "2020-06-24T20:38:30Z")

</div>

Dear Karpinski,

Thank you very much for good information.  
I will check Slack.

Thanks.

---

<div class="post-metadata">

### Author: ![mitsuruk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mitsuruk/32/15907_2.png) [@mitsuruk](https://discourse.julialang.org/u/mitsuruk)
#### Post date: [June 24, 2020, 8:40pm UTC](https://discourse.julialang.org/t/the-order-of-multiple-dispatch/41979/14 "2020-06-24T20:40:19Z")

</div>

Dear bezanson,

I will check src/subtype.c

Thanks a lot.
