# Correct using of Reexport

**URL:** https://discourse.julialang.org/t/correct-using-of-reexport/125835
**Category:** General Usage
**Tags:** dependencies, import, reexport
**Created:** [February 12, 2025, 4:27pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835 "2025-02-12T16:27:45Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 12, 2025, 4:27pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/1 "2025-02-12T16:27:45Z")

</div>

Hello,

I’m developing the QuantumToolbox.jl package, to simulate quantum systems in Julia. This package mainly uses linear algebra operations on sparse and dense arrays. Thus, I have those two packages as dependencies.

Moreover, I was using Reexport.jl to re-export those package when I do `using QuantumToolbox`. In this case they are already imported.

I was wondering if this is a good procedure. I saw that the functions are exported as `QuantumTollbox.eigen` instead of `LinearAlgebra.eigen` for example.

Is this still a good way to proceed?

I’m almost releasing the stable channel, and I would like to set these dependencies definitely.

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [February 13, 2025, 5:34am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/2 "2025-02-13T05:34:34Z")

</div>

Could you provide a specific example? Assuming your code looks like the following, the eigen function being exported can be called directly without a module prefix.

```julia
module test
using Reexport
@reexport using LinearAlgebra
end
using .test
methods(eigen)

```

The above example is how I usually use reexport.

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 13, 2025, 9:15am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/3 "2025-02-13T09:15:40Z")

</div>

Yes exactly this example.

But I was wondering if this is a good way to structure the package, or maybe just using Reexport only when there are different packages under the same ecosystem, like DifferentialEquations.jl

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [February 13, 2025, 9:33am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/4 "2025-02-13T09:33:15Z")

</div>

I see what you mean. `@reexport` is best used to export submodules within your module, or if your module depends on another module you wrote (same ecosystem).

The base libraries and some common packages are best not exported from your modules, imagine the redundancy of this operation if everyone exported linear algebra libraries from their modules. Unless you are quite sure that packages written by others will certainly not export the same packages as yours again. However, this is not absolute, I think its just a matter of code style.

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 17, 2025, 8:30am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/5 "2025-02-17T08:30:04Z")

</div>

Thank you for your reply.

What happens if also other packages export the same Base libraries?

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [February 17, 2025, 11:27am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/6 "2025-02-17T11:27:03Z")

</div>

Nothing happens, it just amounts to `LinearAlgebra` being `using` twice. That’s why I say it’s just a matter of style. You might want to hear from others in the community.

One advantage of not exporting is that users can explicitly see which base libraries they are using in the top-level script.

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 17, 2025, 5:58pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/7 "2025-02-17T17:58:58Z")

</div>

Could you be more specific for the last sentence?

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [February 18, 2025, 2:31am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/8 "2025-02-18T02:31:58Z")

</div>

Taking your package as an example, the user may write the following code:

```julia
using QuantumToolbox
eigen(...)

```

If one can use eigen, is it QuantumTollbox.eigen or LinearAlgebra.eigen? If it’s the former, that means your package overloads the eigen method. If the latter, it means that your package reexports eigen.

However, as long as you make it clear in your documentation which packages are reexported, it’s fine.

```julia
using QuantumToolbox, LinearAlgebra
eigen(...) # OK, I'm sure I am using LinearAlgebra.eigen here.

```

---

<div class="post-metadata">

### Author: ![liuyxpp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuyxpp/32/9870_2.png) [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)
#### Post date: [February 18, 2025, 9:28am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/9 "2025-02-18T09:28:37Z")

</div>

Am I missing something here? If QuantumToolbox implements an `eigen` function, depending on the arguments, either `eigen` in QuantumToolbox or LinearAlgebra can run due to multiple dispatch.

Edit: the above refers to the following quote specially

> [@karei](#):
>
> `eigen(...) # OK, I'm sure I am using LinearAlgebra.eigen here.`

The comment seems not accurate: the line can call `eigen` method defined in QuantumToolbox.

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 18, 2025, 12:26pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/10 "2025-02-18T12:26:18Z")

</div>

We are just overloading many LinearAlgebra functions like `LinearAlgebra.eigen(::SomeCustomOperator) = ...`

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 19, 2025, 7:25am UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/11 "2025-02-19T07:25:04Z")

</div>

I still don’t understand exactly why we should avoid reexporting those libraries.

Our main use is to extend LinearAlgebra methods to our types like

```julia
LinearAlgebra.tr(A::QuantumObject) = ...

```

and others.

Could you make an example were this is actually a problem?

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [February 20, 2025, 4:00pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/12 "2025-02-20T16:00:16Z")

</div>

I’m sorry that I didn’t get back to you in time. I also saw another similar [post](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922). In general, I have an open mind on this issue, and although I personally tend to only use reexport in the same ecosystem, I am not at all opposed to you using reexport in any situation. as I said at the beginning, “ I think its just a matter of code style. ”

We had a long debate in this post, and I took the position of “export only packages from the same ecosystem”. And in the end? As you can see, this argument is not infallible, and there is no reason why it must be done. All I did was explain some of my points to your follow up question.

> [@liuyxpp](#):
>
> Am I missing something here? If QuantumToolbox implements an `eigen` function, depending on the arguments, either `eigen` in QuantumToolbox or LinearAlgebra can run due to multiple dispatch.

> [@albertomercurio](#):
>
> I still don’t understand exactly why we should avoid reexporting those libraries.

Good luck with your package development.

---

<div class="post-metadata">

### Author: ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)
#### Post date: [February 20, 2025, 4:58pm UTC](https://discourse.julialang.org/t/correct-using-of-reexport/125835/13 "2025-02-20T16:58:35Z")

</div>

Thank you. I will decide with the other maintainers what to do.
