This is the conflation I mentioned. IMO it would make much more sense and simplify things to think of it as developing modules (hopefully organized into packages, assuming that suits you), which you would of course do with the help of the REPL, and perhaps (VS) Code or something else utilizing a language server, and then, after the modules are done, the script would be just a one-liner. I.e., if your code is all moduled-up, everything is easier, because when you change some code you just need to include("MainModule.jl")
again. Or use Revise, and then you don’t even have to do that.
Create a package skeleton simply by:
using PkgTemplates
generate()
The generate()
call will start an interactive process within the REPL where you can select various options, override defaults, etc.
Then put your code into the package’s src
directory, and include it from src/PackageName.jl
.
EDIT: forgot to say: after this you also need to do dev /path/to/PackageName
from the Pkg REPL (or call the equivalent Pkg
function, if that is your preference). You could also add
your package directory, instead of dev
-ing it, but dev
is more convenient for an actively and locally developed package because it makes Julia re-precompile the package when there are changes. I believe dev
is also preferable when using Revise.
Just be aware of (pre)compilation costs. Julia precompiles packages, which could help avoid the compilation time overhead when starting your script. Some use the PackageCompiler package so they would be able to distribute their program more conveniently. You might need to invest some effort into reducing startup costs, if that matters.
No. Each package contains some, main, module, named the same as the package. But this, main, module may contain other modules. What I prefer to do is have my src/PackageName.jl
look like this:
module PackageName
include("SubModule1.jl")
include("SubModule2.jl")
include("SubModule3.jl")
end
And there should probably, as a matter of style, be no other include
s anywhere in src
. Especially while you’re still a beginner. This is just my style, though, alternatively you could adopt some other style, or even use a third-party package like FromFile for organizing your package. Just be aware that FromFile seems to cause issues for IDEs.