# Organizing structures in a package

**URL:** https://discourse.julialang.org/t/organizing-structures-in-a-package/83979
**Category:** Package Management
**Tags:** code-organization
**Created:** [July 9, 2022, 5:59am UTC](https://discourse.julialang.org/t/organizing-structures-in-a-package/83979 "2022-07-09T05:59:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)
#### Post date: [July 9, 2022, 5:59am UTC](https://discourse.julialang.org/t/organizing-structures-in-a-package/83979/1 "2022-07-09T05:59:05Z")

</div>

If I’m developing a package where `file1.jl` contains a struct called `struct1` and `file2.jl` has a struct called `struct2` as well as a function that took those two structs as input, what would be the best way to organize this?

Currently in the main module for the package I just include the first file before the second. Is that confusing? Should I move `include("file1.jl")` to the second file? Am I thinking too hard about this? 😮‍💨 From an organizational standpoint it makes sense to have the structs in separate files.

Also sorry if this is like blatantly obvious in the documentation. I still new to package development in general.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [July 9, 2022, 8:18am UTC](https://discourse.julialang.org/t/organizing-structures-in-a-package/83979/2 "2022-07-09T08:18:03Z")

</div>

The way you’re doing it now seems fine to me.

> [@RobertGregg](#):
>
> Currently in the main module for the package I just include the first file before the second. Is that confusing? Should I move `include("file1.jl")` to the second file? Am I thinking too hard about this? 😮‍💨 From an organizational standpoint it makes sense to have the structs in separate files.

I don’t think it’s confusing to include `file1.jl` and `file2.jl` from the main top-level source file. It does make sense to have the structs and associated functions/methods grouped in separate files. In that case, the convention is to name the source files after the struct names (e.g. something like `my_struct.jl` for a struct named `MyStruct`).

As for the function that works on both your types, you could leave it in `file2.jl`; this is especially appropriate if there is a dissymmetry in the relationships between your function and both files, and there is a reason to “favor” the function definition being more closely tied to `struct2` than `struct1`. But you can also move the function to a third `feature.jl` file, which would be more symmetric. Alternately, you could move it to the main, top-level source file, right after both includes.

---

<div class="post-metadata">

### Author: ![RobertGregg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robertgregg/32/22105_2.png) [@RobertGregg](https://discourse.julialang.org/u/RobertGregg)
#### Post date: [July 9, 2022, 3:47pm UTC](https://discourse.julialang.org/t/organizing-structures-in-a-package/83979/3 "2022-07-09T15:47:26Z")

</div>

Thank you for the reply. Moving the function to a third file is actually a pretty good idea for this case.
