# Best practice: put all using in the main \[package\].jl?

**URL:** <https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716>\
**Category:** General Usage\
**Tags:** package\
**Created:** [August 3, 2021, 3:40am UTC](https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716 "2021-08-03T03:40:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [August 3, 2021, 3:40am UTC](https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716/1 "2021-08-03T03:40:50Z")

</div>

I am developing a package named EOS.jl. The main file _EOS.jl_ mainly `include`s other source files.  
I am wondering what is the best practice for the `using` of other registered packages. Should I put all `using` at the beginning of EOS.jl (see below)?

```julia
module EOS
using DelimitedFiles, GLPK, JuMP, Cbc
using LinearAlgebra, FillArrays
using DataFrames, Bijections, TOML
using LightGraphs # used only in milp.jl

```

However, most packages are used exclusively in one source file. For example, the `LightGraphs` is used only in the _milp.jl_ source file. Shall I put `using LightGraphs` in EOS.jl or in `milp.jl`?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [August 3, 2021, 6:34am UTC](https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716/2 "2021-08-03T06:34:44Z")

</div>

Typically, people put all `using` and `include` statements in the main file, i.e. EOS.jl in your case.

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [August 3, 2021, 8:22am UTC](https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716/3 "2021-08-03T08:22:51Z")

</div>

`include` is rather simple command, you can think about it as a placeholder, where actual code appear during preprocessing step.

It means, that if you have three files

```julia
# main.jl
include("foo.jl")
include("bar")

# foo.jl
using A
using B

<some foo related stuff>

# bar.jl
using C
using D

<some bar related stuff>

```

then during preprocess stage, `main.jl` actually explode to

```julia
using A
using B

<some foo related stuff>
using C
using D

<some bar related stuff>

```

and only after that compiling starts (it’s not exact picture, but good enough as a zero approximation). So, as you can see, there is no “exclusive usage of package in a source file”, since all of them are just glued together. Because of this question where to put `using` declarations is only important from the readability point of view (i.e. how you read your source files - from the main file or file by file). As it was said in a previous comment, usually people put everything in top file (EOS.jl in your case), since it is easier to read.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 3, 2021, 8:38am UTC](https://discourse.julialang.org/t/best-practice-put-all-using-in-the-main-package-jl/65716/4 "2021-08-03T08:38:08Z")

</div>

Either way is fine, both have advantages. Putting these statements in the main file gives the reader of the code an overview of all namespace management, while putting them where they are used keeps things together.

Most packages do the first, but don’t worry too much about these things, just keep coding, you can always change these things trivially.
