Include inside and outside of module

In Julia, the following code is ideomatic:

module A
include("A.jl")
end

while

module A end
A.include("A.jl")

is not. I 100% agree that the first option is more idiomatic, aesthetic, readable and should be preferred.

My question is, are there any technical advantages of the idiomatic way? Will the compiler or Revise perform better, or something like this?

The reason I ask is that I would like to mirror a module structure from protobuf, which supports “open modules”. The most faithful translation to Julia would be

module A end
module B end
A.incluce("A1.jl")
B.include("B.jl") # depends on what is in A1.jl
A.include("A2.jl") # depends on what is in B.jl

I wonder if there are technical issues with this.

There’s the normal include([mapexpr::Function,] path::AbstractString) and the less idiomatic one Base.include([mapexpr::Function,] m::Module, path::AbstractString).

In your case, A.include is essentially Base.include under the hood. The normal include calls Base.IncludeInto under the hood, which in turn calls Base.include internally. So if I didn’t get things wrong, I wouldn’t really expect a performance difference there.