Workflow for codes with several .jl

So I’m used to the python framework where I create a folder and in there I have several scripts that all do several simple things. So I would expect that I could do something like this in Julia. Like
simple_modules.jl
simple_functions.jl
not_that_simple_functions.jl

And then have one main.jl that call all of them.

The way that I was doing it right now was just to do

push!(LOAD_PATH, ".")
simple_modules
simple_functions
not_that_simple_functions

So I’m not creating a Project.toml
I tried to look into some other files projects in github and it seems that they use include more than using?
I don’t really see why should I use include or using in this context. Also not sure if when creating a project I should include this little .jl in the Project.toml even though this files are part of the developing project.

I’ve read the guidance of Pkg.jl and the simple case that I’m writing here is not at all cover.

include is like copying/pasting the code into the script, so if your files contain the functions directly, you need to do, for instance:

include("simple_functions.jl")

result = simple_function1(input)

The first line makes the function available, the second line executes it.

If the file contains a module, then you need load the module. For instance, if we have mod.jl with:

module Mod
    export f
    f(x) = x + 1
end

you can do:

julia> include("./mod.jl")
Main.Mod

julia> using .Mod

julia> f(2)
3
1 Like

When you look at Packages in GitHub you will see the pattern

module Module


include("file1.jl")
include("file2.jl")
include("file3.jl")

end

used as a file organisation technique

e.g.

1 Like