# Where to put export statements (Sub-Module Pattern) in distributed code?

**URL:** <https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871>\
**Category:** New to Julia\
**Tags:** question, design-pattern, code-organization\
**Created:** [February 13, 2025, 4:27pm UTC](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871 "2025-02-13T16:27:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gwr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gwr/32/33632_2.png) [@gwr](https://discourse.julialang.org/u/gwr)\
**Post date:** [February 13, 2025, 4:27pm UTC](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871/1 "2025-02-13T16:27:20Z")

</div>

I am working through Tom Kwong’s book _"Hands-On Design Patterns and Best Practices with Julia_." In Chapter 7 on Maintainability Patterns, Tom talks about organizing code (_sub-module pattern_) and gives an example where a module simply includes functions from a file, in which the code is not organized within a sub-module. E.g.,

```julia
# funcs.jl

export func1, func2

function func1()
   # body of func1
end

function func2()
    # body of func2
end

```

That code is then included in the main package, like the following minimal example.

```julia
# MyPackage.jl
module MyPackage
    include("funcs.jl") # code for func1 and func2
end # module

```

It may not be a big issue, but I would not have “hidden” export statements within some file. Instead I would have chosen to make the exports remain explicit within the module that exports them? E.g.,

```julia
# MyPackage.jl
module MyPackage
    export func1, func2 # contained in funcs.jl file
    include("funcs.jl")
end # module

```

What is best practice in this regard?

---

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [February 13, 2025, 5:39pm UTC](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871/2 "2025-02-13T17:39:28Z")

</div>

I don’t know what the best practice is, but I prefer to adopt the second approach. I found it clearer.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 13, 2025, 7:26pm UTC](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871/3 "2025-02-13T19:26:42Z")

</div>

Second approach seems typical because exports are fundamentally a characteristic of the module, not the objects assigned to the exported variables. That said, there could be justifications for doing it the first way, and as long as all the right lines get evaluated into the module’s scope, it’ll work the same.
