# Developing a module the Julian way such that its functions are visible during development

**URL:** <https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497>\
**Category:** General Usage\
**Tags:** development, module\
**Created:** [October 9, 2022, 7:59pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497 "2022-10-09T19:59:25Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 9, 2022, 7:59pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/1 "2022-10-09T19:59:25Z")

</div>

I’m writing a Julia package that contains one module. The module includes many source files and functions. I want to develop new functions in the module without having to export every required function within the module so that they are visible to the new functions. In other words, I’d like the module functions to be in the namespace so I don’t have to qualify them or export each one as I develop. What’s the Julian way to do this?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 9, 2022, 9:24pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/2 "2022-10-09T21:24:54Z")

</div>

I would get rid of the module when developing. Then, once I’m happy with the framework, protect everything with a module, and export public interface.

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 9, 2022, 9:34pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/3 "2022-10-09T21:34:46Z")

</div>

And this applies even when developing a Julia package? All the tutorials suggest creating a module called YourPackageName and then including files within the module. So you’re suggesting omitting the module from the package until some public interface is converged. Then wrap all includes with the module. Are there any side effects to this approach?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 9, 2022, 9:37pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/4 "2022-10-09T21:37:35Z")

</div>

Actually, I personally never do this. It does make certain preliminary design decisions easier, but I always develop my packages as you outlined it. I don’t really see any disadvantage to it. But since you asked: one option is to expose everything initially.

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 9, 2022, 9:45pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/5 "2022-10-09T21:45:15Z")

</div>

Ok, I’ll try this mode of development and see if there are gotchas. Maybe some other Julia developers have something idiomatic? In general, I find the module/package/project system confusing right now, especially with respect to establishing a rapid development paradigm. Is there some reference to suggest best practices?

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [October 9, 2022, 9:57pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/6 "2022-10-09T21:57:25Z")

</div>

So do I get it right, that you want to have a module imported using `using` but develop new functions for it in a separate script? That’s why you want all the functions from the module available?

I find that editing the files and functions in the module as the best way to develop.  
So what I do:  
Create a folder for the module and the basic files.  
Create an environment in a separate folder, `dev` the module into this environment.  
Open in the editor files from the module - write functions etc. While in the other folder I have a file where I run the code. Everything is kept up to date, because I have `Revise` package installed that reloads a module every time the code changes.

So I am not sure if this is what you mean by rapid development, but everything works with almost no lag.

---

<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:** [October 9, 2022, 10:22pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/7 "2022-10-09T22:22:27Z")

</div>

> [@prittjam](#):
>
> so that they are visible to the new functions.

The functions within the module all “see” each other. You mean testing them in the REPL?

I usually do `MyModule.myfunction(...)` to use them while testing. A minor annoyance IMO.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 9, 2022, 10:46pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/8 "2022-10-09T22:46:32Z")

</div>

In the upcoming Julia 1.9 release you can change the contextual module in the REPL:

```julia
$ cat src/TestPackage.jl
module TestPackage

function hello()
    println("hello, world")
end

end # module

$ julia-master -q
julia> using REPL, TestPackage

julia> hello()
ERROR: UndefVarError: hello not defined

julia> REPL.activate(TestPackage)

(TestPackage) julia> hello()
hello, world

```

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 10, 2022, 8:27am UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/9 "2022-10-10T08:27:32Z")

</div>

That’s nirvana. When is it expected to drop?

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 10, 2022, 12:00pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/10 "2022-10-10T12:00:32Z")

</div>

Until Julia 1.9 arrives, I will adopt this method. I find it awkward since I have to prefix my development code that relies on module dependencies that are not exported with the module name. This is the case even if the function I am developing is intended to be within the namespace of the module since I’m testing code snippets of the function in the REPL, which is not in the namespace of the module. I believe the context change will be a big benefit for this style of development, which I’m used to in Python and MATLAB.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 10, 2022, 12:49pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/11 "2022-10-10T12:49:36Z")

</div>

feature freeze is tomorrow. we won’t know exactly when the release will be (since it depends on what bugs are found) but it should be in the 1-6 month timeframe.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [October 10, 2022, 1:02pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/12 "2022-10-10T13:02:47Z")

</div>

> [@lmiq](#):
>
> I usually do `MyModule.myfunction(...)` to use them while testing. A minor annoyance IMO.

I usually also do `MM = MyModule; MM.myfunction(...)` to still reduce the annoyance.

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 10, 2022, 1:27pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/13 "2022-10-10T13:27:20Z")

</div>

Does Revise.jl invalidate the alias MM somehow?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [October 10, 2022, 3:45pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/14 "2022-10-10T15:45:46Z")

</div>

Or

```julia
using MyModule
myfunction = MyModule.myfunction

```

?

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [October 10, 2022, 6:22pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/15 "2022-10-10T18:22:02Z")

</div>

> [@prittjam](#):
>
> Does Revise.jl invalidate the alias MM somehow?

No, it doesn’t

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [October 10, 2022, 6:27pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/16 "2022-10-10T18:27:16Z")

</div>

> [@PetrKryslUCSD](#):
>
> `myfunction = MyModule.myfunction`

Well, sometimes I also do it this way. You can also (temporarily) export `myfunction` . Just if `MyModule_Has_A_LongName` and I wish to have an access to all it’s functions, I’m saving a couple of keystrokes by aliasing to a short form.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 10, 2022, 6:36pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/17 "2022-10-10T18:36:01Z")

</div>

I use this pretty frequently

```julia
function exportall(mod)
    for n in names(mod, all = true)
        if Base.isidentifier(n) && n ∉ (Symbol(mod), :eval)
            @eval mod export $n
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![prittjam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/prittjam/32/21267_2.png) [@prittjam](https://discourse.julialang.org/u/prittjam)\
**Post date:** [October 10, 2022, 9:17pm UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/18 "2022-10-10T21:17:02Z")

</div>

Using your code snippet in combination with the suggestions of @mkoculak allows me to develop in the REPL (using Revise.jl) with nearly a seamless experience–something similar to MATLAB and python. I look forward to the context-aware v.1.9 to replicate this without brute force exporting all functions during development. Thanks for the responses. I’m happy with my dev environment now.

---

<div class="post-metadata">

**Author:** ![Deduction42](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deduction42/32/9206_2.png) [@Deduction42](https://discourse.julialang.org/u/Deduction42)\
**Post date:** [October 15, 2022, 12:13am UTC](https://discourse.julialang.org/t/developing-a-module-the-julian-way-such-that-its-functions-are-visible-during-development/88497/19 "2022-10-15T00:13:26Z")

</div>

My trick is that I tend to put my entire module body in a file named “\_\_assembly.jl” and then put the include statement in my module

```julia
module MyModule
    include(joinpath(@ __DIR__ , "__assembly.jl"))
    export <<all my exported functions here>>
end

```

When developing, I simply run “\_\_assembly.jl”, otherwise, I run “MyModule.jl”
