# The location of Julia functions

**URL:** <https://discourse.julialang.org/t/the-location-of-julia-functions/136296>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 19, 2026, 6:47pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296 "2026-03-19T18:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [March 19, 2026, 6:47pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/1 "2026-03-19T18:47:57Z")

</div>

I have dozens of helper functions in my program.

First of all, why do I have to put them at the beginning of the program?

Is there a way I can put them in a separate jl file for all these functions?

Thanks.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [March 19, 2026, 7:05pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/2 "2026-03-19T19:05:59Z")

</div>

You don’t have to put them at the beginning. The function definition just needs to be executed to define the function before you call it. Segregate your code into as many .jl files as seems fit and `include` them [Essentials · The Julia Language](https://docs.julialang.org/en/v1/base/base/#include)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [March 19, 2026, 7:12pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/3 "2026-03-19T19:12:24Z")

</div>

Or, even better, [create a package](https://modernjuliaworkflows.org/writing/#local_packages) to contain them!

---

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [March 19, 2026, 7:26pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/4 "2026-03-19T19:26:28Z")

</div>

Many thanks. I’m able to use a line of include to put all my functions in a separate file. This is so much cleaner.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [March 19, 2026, 10:56pm UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/5 "2026-03-19T22:56:13Z")

</div>

Quick addition about a different, but slightly related point: the order of definitions does matter for structs/types. You cannot define a type after it is “mentioned” for the first time (at least for dispatch or as field for other structs, which are very common scenarios).

e.g. this will work (as long as you don’t call `foo` before defining `bar`):

```julia
foo(x) = bar(x)
bar(x) = 2x

```

but this will error

```julia
foo(x::MyType) = 2 * x.value

struct MyType
    value::Int
end

```

Of course you can still put earlier definitions into other files though.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [March 20, 2026, 2:13am UTC](https://discourse.julialang.org/t/the-location-of-julia-functions/136296/6 "2026-03-20T02:13:47Z")

</div>

> [@Sevi](#):
>
> You cannot define a type after it is “mentioned”

More specifically, argument annotations access the value of the name at definition-time, just as an assignment `x = MyType` does when executed. The `foo(x)` before `bar(x)` example worked because function bodies execute at compile/call-time instead of definition-time. However, it’s worth noting that some expressions inside function bodies do “execute” at definition-time, like variable scope declarations, macro calls, and nested function definitions:

```julia-auto
julia> function foo()
         x = Faz # executed at runtime, so defining Faz can wait
         function bar(x::Baz) end # bar is defined when foo is defined
       end
ERROR: UndefVarError: `Baz` not defined in `Main`

```
