Missing reference with multiple include files

I am writing some code in VSCode, and I am not sure how what it the best way to split the code in multiple files. As indicated in the Julia documentation, a typical way is to have a single file that includes in the correct order a list of source files:

module X
include("a.jl")
include("b.jl")
include("c.jl")
end

My problem is that many definitions present in a.jl are actually used in b.jl and c.jl: as a result, the linter in VSCode shows a lot of “Missing reference” errors which really annoy me and which make almost useless the linter itself (in the sense that a typo creating a genuine “missing reference” error is easily missed).

What is the way of solving this issue? Including a.jl in b.jl and in c.jl would be a workaround but this would also force Julia to load the file multiple times, which clearly is not a good thing…

Yeah, you definitely don’t want this. It’s worse than a performance issue: Every time you include("a.jl") you will be creating new functions and types with the same names, which is confusing and error-prone. Each file should be included exactly once, period.

Sorry I don’t have an easy answer for the linter question–I just figured I could save you some headache if you decided to go down the road of including files multiple times.

1 Like

Yes, I fully agree. On the other hand putting everything in a gigantic single file is also not good: in this case it is OK for Julia, but quite bad for humans.