# Including files within a single module

**URL:** <https://discourse.julialang.org/t/including-files-within-a-single-module/81729>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 26, 2022, 3:49pm UTC](https://discourse.julialang.org/t/including-files-within-a-single-module/81729 "2022-05-26T15:49:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niall](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niall/32/22517_2.png) [@Niall](https://discourse.julialang.org/u/Niall)\
**Post date:** [May 26, 2022, 3:49pm UTC](https://discourse.julialang.org/t/including-files-within-a-single-module/81729/1 "2022-05-26T15:49:50Z")

</div>

I’m wondering if there are any general views on the cleanest way to combine files within a module. I have at present three types: `Parent`, `Child1` and `Child2`. `Parent` is a synonym for `AbstractArray{Complex}`, and `Child1` and `Child2` are both `struct`s that derive from it. All three types are relatively complex with a whole bunch of associated methods, and all are used within a module called `MyModule`. In order to cut down the size of the file MyModule.jl, I decided to divide the three types into separate files, then recombine them into `MyModule`.

Now comes my question: Is it more common, or even better, practice to write the files Parent.jl, Child1.jl and Child2.jl as free-floating code that gets `included` into the middle of `MyModule`, or is it more common/better to package all three of them into individual modules that are then `using`-ed into `MyModule`?

Following this is the additional question of whether there is a standard practice like in C++ of `#define`-ing constants that avoid the issue of including a file twice into the same code. So like, what if `Parent` is used by both `Child1` and `Child2`, then both are included into `MyModule`. What is the standard practice for avoiding the `Parent` code being included twice into `MyModule`.

I have various thoughts on these matters, but I’m a relative beginner in Julia and would be glad to hear from more experienced people.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 26, 2022, 3:53pm UTC](https://discourse.julialang.org/t/including-files-within-a-single-module/81729/2 "2022-05-26T15:53:36Z")

</div>

> [@Niall](#):
>
> write the files Parent.jl, Child1.jl and Child2.jl as free-floating code that gets `included` into the middle of `MyModule`

This is more common and practical. There are exceptions, but mostly new modules are useful when they are self contained (provide some functionality) enough to become new (perhaps small) packages.
