# Best practices (for package code), e.g. no "using"

**URL:** <https://discourse.julialang.org/t/best-practices-for-package-code-e-g-no-using/113233>\
**Category:** General Usage\
**Created:** [April 19, 2024, 12:12pm UTC](https://discourse.julialang.org/t/best-practices-for-package-code-e-g-no-using/113233 "2024-04-19T12:12:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [April 19, 2024, 12:12pm UTC](https://discourse.julialang.org/t/best-practices-for-package-code-e-g-no-using/113233/1 "2024-04-19T12:12:21Z")

</div>

E.g. `using` is “considered harmful” for package code. There’s disagreement on recommending against it in the Julia docs, but it can for sure go into some style-guide, and maybe is already there. `eval` should neither be used there, more examples?

Julia currently supports all the same code in packages as elsewhere, but for Julia 2.0 (or had it be planned from the start), it could have only allowed a subset. At least a subset can be easier on the compiler, i.e. not needing it at runtime, what e.g. `eval` forces. Ideally package code could be compiled with StaticCompiler.jl but we are far away from that, so it can’t be that limiting, at least yet.

Some things are not about that, rather API issues, e.g. `using` is ok for the REPL, we might want or need such extra keywords there, and only there.

This newly opened issue just got me thinking what we really need, or might want to do without, rather than add more options, go with fewer(?):

> <https://github.com/JuliaLang/julia/issues/54147>
>
> Just a suggestion from reading lots of posts about usages of julia and how thing…s are getting out of hand when dealing with large projects. I suggest adding a new import statement as:
> \`\`\`julia
> OtherModule = moduleimport("otherfile.jl") # as opposed to normal including it would first wrap the file in a module and the load the namespace 
> \# Syntax like "moduleimport("otherfile.jl") as Othermodule" could work too
> 
> \# Now the stuff from the "otherfile.jl" is not verbatim included but wrapped in a module same as python does
> 
> Othermodule.function1(x)
> Othermodule.function2(x)
> 
> \# It is obvious for people from other languages, and perhaps could be helpful for lspless codebrowsing.
> 
> \`\`\`
> Now, instead of this being a package or a macro, wouldn't this kind of syntax be a good practice for long-term for large project development where people don't wanna wanna wrap every file in a module manually:
> \`\`\`julia
> module Othermodule
> include("otherfile.jl") # people either have to add module...end inside
> end
> using .Othermodule: function1, function2
> \`\`\`
> 
> vs having one-liner import at the top of the file (same like python)
> \`\`\`julia
> using Package1, Package2
> moduleimport("otherfile.jl"): function1, function2
> moduleimport("otherfile2.jl"): function3 as f3, function4 as f4
> \`\`\`
> 
> The precise syntax is not of importance, but this is rather an idea how to promote a workflow that suits large codebases better. I wish if such syntax existed in core julia then lsp and other code solution could have a much easier time of discerning what is what and where is it coming form without relying on lsp too much.
> 
> This might be a simple macro or what not, but the purpose here is to promote such style of development in general without relying on 3rd party packages. This might touch upon issues like #4600 https://github.com/JuliaLang/julia/issues/39235 https://github.com/JuliaLang/julia/pull/42080 or merging \`import\` and \`using\` keywords. Feel free to delete this issue in case this is a dup or something like that.

Also this very old issue (we’ve done fine without so far):

> <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\`.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [April 19, 2024, 12:54pm UTC](https://discourse.julialang.org/t/best-practices-for-package-code-e-g-no-using/113233/2 "2024-04-19T12:54:14Z")

</div>

> [@Palli](#):
>
> (we’ve done fine without so far):

I don’t agree

I find it enormously difficult to read Julia code in a foreign package without cloning locally so I can be constantly `grep`ping

I wouldn’t call that “fine”
