# Using "Module.jl" as alias to include("Module.jl"); using .Module

**URL:** <https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610>\
**Category:** Internals & Design\
**Created:** [December 30, 2020, 12:29pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610 "2020-12-30T12:29:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 30, 2020, 12:29pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610/1 "2020-12-30T12:29:43Z")

</div>

Wouldn’t it be handy if `using` and `import` had methods (or `@using` and `@import` macros) that include and load the module at once?

```julia
using "MyModule.jl" 

```

as an alias to

```julia
include("MyModule.jl")
using .MyModule

```

and

```julia
using "./MyModule.jl": myfunc
import "./MyModule.jl"
import "./MyModule.jl": myfunc

```

etc?

(maybe a macro `@using "./MyModule.jl": myfunc`, etc).

Of course those should throw an error if `MyModule` is not found in `MyModule.jl`.

Probably a good answer to this is “that simply is not worth the effort”. Fair enough 🙂

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [December 30, 2020, 12:54pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610/2 "2020-12-30T12:54:21Z")

</div>

There is already an issue with a suggestion like this, see

> <https://github.com/JuliaLang/julia/issues/4600>
>
> When I do
> 
> \`\`\` julia
> \# Main.jl
> module Main
> using .Foo
> end
> \`\`\`
> 
> and there's a f…ile called \`Foo.jl\` in the same directory as \`Main.jl\` it should be loaded. I suspect that relative \`using\` should also \_not\_ look in the global require places – i.e. \`Pkg.dir()\` and then \`LOAD\_PATH\`. The same applies to \`import\`.

and

> [@\[ANN\] PatModules.jl: a better module system for Julia](https://discourse.julialang.org/t/ann-patmodules-jl-a-better-module-system-for-julia/52226/63):
>
> The issue is not double inclusion, but the inclusion order. This can cause a lot mental burden and should be handled by the compiler since the compiler knows which module depends on which, e.g when you have include("B.jl") include("A.jl") where module B depends on A, manual include will result in undefined error, but if we implement issue 4600, then we can just write something like (the syntax is not decided yet) using .B from "B.jl" using .A from "A.jl" or using .A from "A.jl" using .B fr…

---

<div class="post-metadata">

**Author:** ![zgornel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zgornel/32/217487_2.png) [@zgornel](https://discourse.julialang.org/u/zgornel)\
**Post date:** [December 30, 2020, 1:22pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610/3 "2020-12-30T13:22:53Z")

</div>

The `include` syntax does have its semantic advantages over `using` and `import` which are more module related (with all namespace implied functionality). Sometimes being more verbose is simpler and clearer rather than hiding functionality behind seemingly arbitrarily cumbersome one-liners. This seems like package material though 🙂

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [December 30, 2020, 2:17pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610/4 "2020-12-30T14:17:14Z")

</div>

If I need this for a self-contained project, I just modify the `LOAD_PATH` or the environmental variable `JULIA_LOAD_PATH`.

```julia
push!(LOAD_PATH,pwd())
using MyModule

```

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [December 30, 2020, 7:00pm UTC](https://discourse.julialang.org/t/using-module-jl-as-alias-to-include-module-jl-using-module/52610/5 "2020-12-30T19:00:40Z")

</div>

> [@mkitti](#):
>
> If I need this for a self-contained project, I just modify the `LOAD_PATH` or the environmental variable `JULIA_LOAD_PATH` .

Yup. I also do this for notebooks that other people will use. Telling 'em to

```julia
include "mstuff.jl"

```

which contains a `push!` to their `LOAD_PATH` and several lines of `using` and/or `include` is a lot simpler than asking them to manage their `LOAD_PATH` on their own or add dependencies they may never have heard of. My coauthors and students appreciate this.
