To include types and functions or to use modules?

If the only place that those units are used are within your (main)module, then you are probably fine without making it into a module, since now instead of one statement of include("unit.jl") you now have multiple statements to just accomplish the same task:

include("unit.jl")
using Unit

which is more convoluted, if it is not needed.

However, if you have a very cluttered namespace, then it might be of advantage to indeed place it into its own module and use the using syntax. Then when you call using, all of the functions that are not exported will now be hidden and tucked away. So it depends on whether you experience conflicts, but this also requires you to put more effort into determining what functions need export statements and how to manage.

So putting it into a module is a tradeoff that adds a bit of extra maintenance to your package work, which might be unnecessary if it is not needed due to namespace issues within the scopes you intend to use it for.

This question is somewhat similar to

2 Likes