What is the recommended way to include
all the files for your project?
I have seen many examples that use a similar structure: an ordered list of include
statements in a single top-level file (the file that defines a Module
, or the "main" file in an application).
This also seemed to be the conclusion in the following thread: https://discourse.julialang.org/t/best-practices-for-structuring-larger-projects/2652?u=nhdaly
However, Lint.jl
seems to be very unhappy with this sort of project structure, complaining about the persistent use of undeclared symbol
s.
Consider the following example:
# --- src/lib1.jl ---
struct MyStruct
x::Int32
end
# --- src/lib2.jl ---
foo() = MyStruct(3) # Lint.jl says: E321 MyStruct: use of undeclared symbol
# --- src/MyPackage.jl ---
module MyPackage
include("lib1.jl")
include("lib2.jl")
foo()
end
Of course, this code will work correctly, because MyStruct
will be available before lib2.jl
is compiled. But Lint.jl
cannot know that. Even when using the Atom-integrated linter
, it shows the same error.
So is it preferable to have lib2.jl include("lib1.jl")
instead of all the includes in the top file? Or is it best to put them in both places, as you might for C++
headers? I haven't seen a definitive recommendation for this anywhere, and I'd love if someone could provide one! :)
EDIT: changed file names to reflect a more typical julia directory structure.