Is it a common thing for Julia users to encapsulate functionality into own modules with the module keyword?
I've been looking at modules and they seem to use include more than actually using the module keyword for parts of code.
What is the better way?
Julia has 3 levels of "Places you can put code"
include
'd filesI use to be a big fan of submodules, given I come from python.
But submodules in julia are not so good.
From my experience, code written with them tends to be annoying both from a developer, and from a user perspective.
It just don't work out cleanly.
I have ripped the submodules out of at least one of my packages, and switched to plain include
s.
Python needs submodules, to help deal with its namespace -- "Namespaces are great, lets do more of those". But because of multiple dispatch, julia does not run out of function names -- you can reuse the same name, with a different type signature, and that is fine (Good even)
In general submodules grant you separation and decoupling of each submodule from each other. But in that case, why are you not using entirely separate packages? (with a common dependency)
say you had:
- module A
- module B (i.e A.B)
- type C
One would normally do using A.B
but by mistake you can do using B
since B is probably in a file called B.jl
in your LOAD_PATH.
If you do this, then you want to access type C
.
If you had done using A.B
you would end up with a type A.B.C
, when you entered the statement B.C()
.
But if you had mistakenly done using B
, then B.C()
gives you the type B.C
.
And this type is not compatible, with functions that (because they do the right using
) expect as A.B.C
.
It just gets a bit messy.
Also reload("A.B")
does not work.
(however reload
often doesn't work great)
Base
is one of the only major chuncks of julia code that uses submodules (that I aware of). And even Base
is pushed a lot of those into seperate (stdlib) packages for julia 0.7.
The short is, if you are thinking about using a submodule, check that it isn't a habit you are bringing over from another language. And consider if you don't just want to release another separate package.