# Packages, modules, and files

**URL:** <https://discourse.julialang.org/t/packages-modules-and-files/7652>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [December 9, 2017, 2:39pm UTC](https://discourse.julialang.org/t/packages-modules-and-files/7652 "2017-12-09T14:39:57Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [December 9, 2017, 2:39pm UTC](https://discourse.julialang.org/t/packages-modules-and-files/7652/1 "2017-12-09T14:39:57Z")

</div>

The exact connection between packages, modules, and source files is unclear to me, even after reading the `Pkg3` Julep and the relevant chapters of the documentation. Please note that this is not a criticism of either the current state or what will replace it with `Pkg3`, I am just trying to understand how things work.

My understanding of the status quo is the following:

1. A package is a collection of files and metadata. The have names like `Foo.jl`.

2. A module is a piece of source code, eg `module Foo ... end`.

3. `using Foo` and `import Foo` try to locate a `Foo.jl` in `LOAD_PATH`, specifically a `Foo/src/Foo.jl` inside a package, or just a `Foo.jl` for a module that is just a source file.

While in theory modules, source files, and packages could more or less be orthogonal, in practice `using` (and `import`) will not find `Foo` unless it is in a `Foo.jl` somewhere, using the above mechanism. The only other option is to `include` its source file. Looking at the [source for loading](https://github.com/JuliaLang/julia/blob/f8d3fbb1343696439e5f1a62f1c43848306d1c36/base/loading.jl#L90-L99), within a few function calls syntax that started with modules (eg `using`) quickly involves package structures.

It is not possible to have a module `Bar` that has a source file `src/Foo.jl` that has a `module Baz ... end` (ie it is of course possible, but Julia will just ignore it). Even if 2 of the 3 names match; all 3 of them have to match for the module to be loadable with `import/using`.

Similarly, a differently named (extra) file with module in a package structure is just ignored, unless `include`d explicitly. `Foo/src/Foo.jl` may define `module Bar ... end`. In this case `using Bar` fails, and `using Foo` gives a warning about not being able to load the package. If there happens to be a module `Foo`, `Bar` is just loaded with it silently.

`Pkg3` seems to hook into `using`, and offer installation of the missing package.

So, in practice, loading a module with `using Foo` and `import Foo` work only if

1. it is in a package that is in `LOAD_PATH` with the name `Foo/src/Foo.jl`,

2. it is in a standalone source file in `LOAD_PATH` with the name `Foo.jl`,

3. it was in a piece of code that is already evaluated (eg with `include`), in which case `using Foo` and `import Foo` are no-ops.

Is this correct?

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [December 9, 2017, 8:19pm UTC](https://discourse.julialang.org/t/packages-modules-and-files/7652/2 "2017-12-09T20:19:49Z")

</div>

> [@Tamas\_Papp](#):
>
> Looking at the source for loading, within a few function calls syntax that started with modules (eg using) quickly involves package structures.

Why is package structure such a bad thing?

There are minimal ways to inform load hierarchies

---

<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:** [December 10, 2017, 10:42am UTC](https://discourse.julialang.org/t/packages-modules-and-files/7652/4 "2017-12-10T10:42:43Z")

</div>

Interesting, but I don’t see what it has to do with my question.

> [@djsegal](#):
>
> Why is package structure such a bad thing?

I am not saying it is. Again, my question is about understanding the implicit assumptions in the current setup, not about solving an actual issue, or a problem that I identified with it.
