Proper way of organizing code into subpackages

Tips: include()

  • Do not use include() to “include” a package into your project.
  • Actually, include() loads code from a file. I don’t think Python has such a low level command. In C/C++, it probably corresponds to what the linker does (Of course it also loads the code in memory).
  • include() was meant to load code stored in subfiles (not submodules) - allowing you to break your solution up into multiple files.
  • Only include() files that are directly part of your current package/project.
  • Do not include() files from other “software modules” (projects).

Tips: module

  • module MyMod is not a “software module” as you likely think of it. It is simply a global namespace.
  • You can have more than one module per file, and can have multiple files per module (because they are namespaces - not "software modules)).

Tips: Package

  • A package is probably what you should think of when you intend on developing a “software module”.

Tips: import MyPkg/using MyPkg

  • Yes, import or using is the thing to do if you import a separate package.
  • When you import MyPkg (or using MyPkg), Julia first checks if it is already loaded.
  • If not already loaded, Julia checks in its package “locations” (Project.toml+LOAD_PATH folders), and loads it.
  • import MyPkg (or using MyPkg) then returns a reference to the package’s associated module (i.e. namespace).
16 Likes