# To include types and functions or to use modules?

**URL:** <https://discourse.julialang.org/t/to-include-types-and-functions-or-to-use-modules/9502>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 5, 2018, 10:47am UTC](https://discourse.julialang.org/t/to-include-types-and-functions-or-to-use-modules/9502 "2018-03-05T10:47:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 5, 2018, 10:47am UTC](https://discourse.julialang.org/t/to-include-types-and-functions-or-to-use-modules/9502/1 "2018-03-05T10:47:28Z")

</div>

Say I have a package that neatly separates into a few “units” (i.e. chunks of more or less independent code). The units do depend on some overarching constants and functions, as well as each other’s outputs (so unit 2 receives unit 1’s output).

Now, I can either:

1. keep each unit in its own `.jl` file, and `include("unit1.jl")`, inside the main module, OR
2. keep each unit in its own `.jl` file, make that a module of its own, `include("Unit1.jl")`, and `using Unit1`, inside the main module.

In terms of namespace there is no overlap (that I can’t deal with), in fact, I sometimes need to `import ..SomeType`.

**Are there any advantages to keeping each of the “units” as their own (sub)modules or should I just keep them as is (a bunch of types and functions in the same (main)module)?**

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [March 5, 2018, 2:55pm UTC](https://discourse.julialang.org/t/to-include-types-and-functions-or-to-use-modules/9502/2 "2018-03-05T14:55:08Z")

</div>

If the only place that those units are used are within your (main)module, then you are probably fine without making it into a module, since now instead of one statement of `include("unit.jl")` you now have multiple statements to just accomplish the same task:

```julia
include("unit.jl")
using Unit

```

which is more convoluted, if it is not needed.

However, if you have a very cluttered namespace, then it might be of advantage to indeed place it into its own module and use the `using` syntax. Then when you call `using`, all of the functions that are not `export`ed will now be hidden and tucked away. So it depends on whether you experience conflicts, but this also requires you to put more effort into determining what functions need `export` statements and how to manage.

So putting it into a module is a tradeoff that adds a bit of extra maintenance to your package work, which might be unnecessary if it is not needed due to namespace issues within the scopes you intend to use it for.

This question is somewhat similar to

> [@Package size and scope?](https://discourse.julialang.org/t/package-size-and-scope/7309):
>
> Hi All – Recently started developing packages. Was wondering how everyone feels about package size and scope. Do you feel like there is a minimum or maximum size/scope a package should be? As a Developer: Do you include just a few things in a package (and do them well)? Or do you put in everything but the kitchen sink? As a User: Do you include a package with 10 functions to just use 1 of them? Or do you not want to be bothered with a la carte packages? For context, (and a tad less b…

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 5, 2018, 3:00pm UTC](https://discourse.julialang.org/t/to-include-types-and-functions-or-to-use-modules/9502/3 "2018-03-05T15:00:08Z")

</div>

Thanks. I was partly worried I was missing out on some speed up I could get from putting them into modules. But the code is a lot more straight forward now, with all the “units” in the same module. Thankfully, my namespace is fiiiiiiine…!
