Should I put using statements in files to be included?

I’m currently developing a module, and I’m splitting the code into various files that will be then included into the main file that declares the module. At the moment, I’m putting all using statements in every single file, using the packages that a file needs. Is this wrong? This shouldn’t add any overhead, and it’s useful to test a single file by simply running it in the REPL (which is a handy shortcut on VSCode). On the other hand, there’s a lot of repetition: for example, basically every single file has using LinearAlgebra on top. Is there some kind of convention about this? Should I put using statements all on top of the main file before including the other files?

No, you don’t need to do this.

My advice: Just let everything share the same namespace. It should be

module MyModule
    using LinearAlgebra 

    include("file1.jl") # No using statements in here
    include("file2.jl") # No using statements in here either
end
4 Likes