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).
Are you talking about VS Code? You might want to mention that in the title.
I do see the docstrings (see screenshot), although I had to wait some seconds for VS Code to load them.
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
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() from “outside” won’t work. You must specify
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.
I see the discrepancy now. Thank you for your help, your examples reminded me of something different that I’m doing.
I am using the below code to include, because I move across several PCs during my development.
I changed it back to a fixed string, and the docstrings came back.