My goal is include the structs, functions, etc. of another .jl file into the new.jl.
I have been using the include(“foo.jl”), it works but it doesn’t feel right. For example, my function docstrings do not appear in new.jl when the mouse is hovering over them, but they do in the source files I created. I see that when importing or ‘using’ julia packages, they are able to show docstrings of functions outside of the source file.
Can someone send me a best practices for this? I want to get this straight before I have dozens of files. I have read some things about making my code into modules or packages, but I don’t understand that as of now (but I’m trying).
Nevertheless, if you want to use modules, it’s as easy as enclosing the code of foo.jl in a module as follows:
module Foo # use any name you want
# here your code of foo.jl
end
But now, in the file where you include("foo.jl"), what you have defined is the module Foo, not its “contents” directly, so if for instance one of those contents is the function foo, calling foo() from “outside” won’t work. You must specify Foo.foo(), etc.
There are ways to export names from the modules, just as packages do (since actually, packages are essentially modules). But I’ll stop here, to keep it simple.