Proper namespacing and importing local files

The reason why in Julia “where the function comes from” is not much significant is that the same function can have methods defined in more than one module/package, because of multiple dispatch. You should ask then “where this method comes from”, meaning a specialization of a function for a specific set of types of arguments. That is not really possible, and goes very against the nature of multiple dispatch.

Thus it is much more common that packages are structured in the flat way (includes in proper order only, few modules), as you have observed. You should never “include” a file more than once in a code, thus splitting the code in many modules does not really help the part of the include order (you should not include a file in the main module and then include it again in a submodule that depends on that file).

You can use multiple modules and there is a package, https://github.com/Roger-luo/FromFile.jl, which helps structuring the code in the sense you are thinking.

When a package becomes too large to be structured as a single block, and, more importantly, when a block assumes a set of functionalities that are useful per se, what is natural in Julia is to split the package into more packages, and let the package manager take care of the dependency tree.

(You will find some enormously heated discussions about this theme here in the forums, with more than lengthy discussions of the pros and cons of the way Julia approaches the modularity of codes in this regards)

5 Likes