Organizing structs and modules

There are quite a few related discussions on discourse, such as Large programs: structuring modules & include such that to increase performance and readability.

My (personal) suggestion is: unless the project is quite large, don’t use sub-modules at all. It just leads to exactly the kinds of issues that you are running into (how do I organize everything so that A depends on B but not the other way around? How do I make all types visible everywhere they need to be seen?).

Tastes differ on this question, though.

If you want sub-modules, you need one master module (probably Orchard in your case). Then orchard.jl includes the other modules (don’t include the same file multiple times). And if you need to see Seed in Fruit you do

module Orchard

module Seed
 ...
end
using .Seed

module Fruit
  using ..Seed
  ...
end
using .Fruit

end

Hope this helps.

7 Likes