# Is it OK to re-export something from a different package?

**URL:** https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922
**Category:** General Usage
**Created:** [February 22, 2022, 5:16pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922 "2022-02-22T17:16:15Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [February 22, 2022, 5:16pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/1 "2022-02-22T17:16:16Z")

</div>

As the title say, i am wandering if it is OK to reexport a method from a different package. I currently have :

```julia
module MyPackage

using OtherPackage

struct mytype end
OtherPackage.function(x::mytype) = 1

end

```

The fact is that `MyPackage` provides new methods to this function, on types that are defined in `MyPackage` (so no type piracy), but the generic is only exported if I do :

```julia
using MyPackage
# Cannot use `function`
using OtherPackage
# Now i can 

```

Would it me OK to `export OtherPackage.function`, so that i could do:

```julia
using MyPackage
# `function` is available

```

?

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [February 22, 2022, 5:38pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/2 "2022-02-22T17:38:12Z")

</div>

If I’m understanding you correctly, in this case you could. It is also natural to just tell your users they must load both packages.

---

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [February 22, 2022, 5:47pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/3 "2022-02-22T17:47:19Z")

</div>

Thanks. Do you know if there is a ‘standard’, or a good practice regarding the choice between re-exporting and telling people to load both packages ?

---

<div class="post-metadata">

### Author: ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)
#### Post date: [February 22, 2022, 5:51pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/4 "2022-02-22T17:51:59Z")

</div>

I would say that it depends on the relationship between your package and the other package. If your package builds “on top of” the other package but a user wouldn’t particularly need to be aware of the underlying package then re-export. If your package is an addition that a user would be using while also using the underlying package directly then advise they load both.

---

<div class="post-metadata">

### Author: ![lrnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lrnv/32/19373_2.png) [@lrnv](https://discourse.julialang.org/u/lrnv)
#### Post date: [February 22, 2022, 5:52pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/5 "2022-02-22T17:52:57Z")

</div>

> [@Jordan\_Cluts](#):
>
> I would say that it depends on the relationship between your package and the other package. If your package builds “on top of” the other package but a user wouldn’t particularly need to be aware of the underlying package then re-export. If your package is an addition that a user would be using while also using the underlying package directly then advise they load both.

Seems fair, thanks.

---

<div class="post-metadata">

### Author: ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)
#### Post date: [June 15, 2023, 3:41pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/6 "2023-06-15T15:41:27Z")

</div>

What is the exact syntax for re-exporting a function from another package?

This is not working for me.

**EDIT:** Sorry, this was a git and a `dev` vs. `add` issue. The code below is now working as intended.

```julia
module MyPackage
using AlgebraOfGraphics
export draw

struct MyType
    data::SomeOtherType
    plot::Layer # type from AoG
end
export MyType

function f()
    # computations
    return MyType(data, plot)
end
export f

end # module 

```

```julia
julia> using MyPackage

julia> results = f();

julia> draw(results.plot)

```

I did get an unexpected error when I wrote `export AlgebraOfGraphics.draw` instead of `export draw` though. I would have thought either would work?

```julia
julia> using MyPackage
[Info: Precompiling MyPackage [d29f79e6-4313-439e-a1e0-c6c95527bf41]
ERROR: LoadError: syntax: "module" at <file_path>.jl:1 expected "end", got "."

```

---

<div class="post-metadata">

### Author: ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)
#### Post date: [June 25, 2023, 3:59am UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/7 "2023-06-25T03:59:17Z")

</div>

If you have package B and C which extend a method from package A, is it okay if both B and C export the extended function from A? Any best practices to be aware of?

---

<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, 10:12am UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/8 "2025-02-20T10:12:45Z")

</div>

Hello,

I’m in a similare situation, where this time `OtherPackage` is `LinearAlgebra`. In my package QuantumToolbox.jl I apply several methods of the LinearAlgebra.jl functions to my types.

What should I do? I it a good idea to reexport LinearAlgebra?

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [February 20, 2025, 10:23am UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/9 "2025-02-20T10:23:36Z")

</div>

For those checking this thread in the future, the Reexport.jl package is useful when you need to reexport modules of your main package:

> **[GitHub - simonster/Reexport.jl: Julia macro for re-exporting one module from...](https://github.com/simonster/Reexport.jl)**
>
> Julia macro for re-exporting one module from another

In that case you can do

```julia
module MyPackage

using Reexport

@reexport DepPackage1
@reexport DepPackage2
...

end

```

Here is a [real example](https://github.com/JuliaEarth/GeoStats.jl/blob/master/src/GeoStats.jl).

---

<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, 12:10pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/10 "2025-02-20T12:10:09Z")

</div>

Thanks.

I was currently aware of Reexport.jl. My question was more related to the choice or not to re-export the LinearAlgebra package.

I see that many people just re-export their dependencies belonging to the same ecosystem. So I was wondering if re-exporting a Base library like LinearAlgebra was something to avoid or not.

---

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [February 20, 2025, 12:54pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/11 "2025-02-20T12:54:29Z")

</div>

I don’t think anything “bad” would happen, but, personally, I would definitely frown upon in. If you don’t “own” it, it seems to me you shouldn’t export it. (“Own” can mean “in my org”, so re-exporting from a base package is fine).

But then, I’m fairly conservative when it comes to exports, anyway. I might even lean towards considering it a bad idea altogether (it pushes people towards “star imports”, i.e., unqualified `using`, which took the Python community years to root out after finding out that it was a really bad idea). Maybe now that we have `public`, packages shouldn’t declare exports at all anymore. But in any case, I think of `export` as “`public` plus convenience in the REPL for throwaway code”. If you think in terms of `public`, it feels even weirder to declare something `public` that you don’t own. So, the same should apply to `export`. But I don’t think there’s a “correct” answer here. This is completely opinion based, so at best, you’ll get a community majority opinion poll on how people feel about exports, which will probably be divided between the types of people that I might call “users” and “developers” 😉

In your case, is there any concrete benefit to users not having to do an explicit `using LinerAlgebra`? I believe the mantra “explicit is better than implicit” holds.

---

<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, 1:11pm UTC](https://discourse.julialang.org/t/is-it-ok-to-re-export-something-from-a-different-package/76922/12 "2025-02-20T13:11:30Z")

</div>

Thanks for the detailed reply.

In my case I declare many methods like

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

```

and many more.

This implies that, if the user needs to compute the trace, the LinearAlgbebra package has to be imported. That’s why we decided to use Reexport.jl.

It is also fine for me to import LiearAlgebra every time I import my package. But of course avoiding it is simpler for the new user.
