# Canonical way on how to use something that is defined later in the code?

**URL:** <https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142>\
**Category:** General Usage\
**Created:** [June 21, 2022, 8:05pm UTC](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142 "2022-06-21T20:05:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [June 21, 2022, 8:05pm UTC](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142/1 "2022-06-21T20:05:00Z")

</div>

I have a package that is divided in several modules, says `Utils` and 'Algos`, each on his file:

`MyPackage.jl`:

```julia
include("Utils.jl")
include("Algos.jl")

```

Up to now `Algos` was using something defined in `Utils`, and there were no problems, but now also `Utils` needs to use some funcionality provided by `Algos`.

Which is the “canonical” way to deal for situations like this? In C++ there was a way to declare empty classes and then implement them later, maybe something similar?

---

<div class="post-metadata">

**Author:** ![acxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/acxz/32/16759_2.png) [@acxz](https://discourse.julialang.org/u/acxz)\
**Post date:** [June 21, 2022, 10:59pm UTC](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142/2 "2022-06-21T22:59:07Z")

</div>

Personally, I would try to separate the `Algos` functionality that is required by `Utils` and incorporate that into `Utils` itself, to prevent this kinda of circular dependency.

Another option is collapsing both files into one or separating shared functionality between both into a third file.

There may be a better way of handling this situation that I am not aware of however.

---

<div class="post-metadata">

**Author:** ![filchristou](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/filchristou/32/26760_2.png) [@filchristou](https://discourse.julialang.org/u/filchristou)\
**Post date:** [June 22, 2022, 5:21am UTC](https://discourse.julialang.org/t/canonical-way-on-how-to-use-something-that-is-defined-later-in-the-code/83142/3 "2022-06-22T05:21:38Z")

</div>

This problem was occurring also for me for a specific project. In the end I decided to put all the struct, type, enums definitions in a specific subfolder `./src/Types/`, which I included from the main file first. Then I could define all possible functions in the files to follow without problems.

```julia
# type, structs, enums, etc. definitions
./src/Types/regardingAtypes.jl
./src/Types/regardingBtypes.jl
./src/Types/regardingCtypes.jl
# funcionality
./src/AB.jl
./src/A.jl
./src/ABC.jl
# ...

```

```julia
# my main file
module MyModule
# include type definition
include("Types/regardingATypes.jl")
include("Types/regardingBTypes.jl")
include("Types/regardingCTypes.jl")
# functionality
include("AB.jl")
include("A.jl")
include("ABC.jl")
# ...
end

```

Ofc as long as you don’t have this issue [handle mutually-circular type declarations · Issue #269 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/269).
