# Opinions for exporting common names

**URL:** <https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995>\
**Category:** General Usage\
**Tags:** namespaces\
**Created:** [July 20, 2021, 4:10pm UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995 "2021-07-20T16:10:12Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [July 22, 2021, 8:52am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/21 "2021-07-22T08:52:39Z")

</div>

> [@DrChainsaw](#):
>
> Sorry for not letting this go, but I feel the dilemma is that `using Foo` would still be perfectly possible if only one just did not export e.g. `name` . E.g. typing `using Foo` followed by `using Foo: name` is less work than typing `using Foo: bar, baz,...` .

Even when `name` is exported, you can just write `using Foo; using Foo: name` to disambiguate the origin of `name`.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [July 22, 2021, 9:26am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/22 "2021-07-22T09:26:06Z")

</div>

> Even when `name` is exported, you can just write `using Foo; using Foo: name` to disambiguate the origin of `name` .

Wow, I had no idea it worked like that! I guess I should have tried @rdeits suggestion before complaining 🙂

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [July 22, 2021, 9:28am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/23 "2021-07-22T09:28:08Z")

</div>

> [@Tamas\_Papp](#):
>
> Personally I think 1 and 2 are fine options, depending on the API and whether it is intended for interactive use or package code. For the latter, `using` everything explicitly is fine and is a good habit.

For _package_ code it’s not only a good habit but a necessity if you take semantic versioning seriously. Assume you have the code

```julia
using Dep1
using Dep2

```

and declare compat

```julia
[compat]
Dep1 = "1"
Dep2 = "1"

```

Let’s assume this works fine without collisions for version 1.0 of both dependencies. Unfortunately `Dep2` then adds a new feature which exports a name that you are already using from `Dep1`. `Dep2` correctly bumps the minor version and releases “1.1”, which is within the compat you have declared, but your package breaks due to the conflict.

To avoid this scenario you either have to use explicit `using`s or defensively declare tilde compats (i.e. only allow patch upgrades), but the latter will likely drive both you and your users crazy.

(Of course you may take the likelihood of conflicts into consideration, e.g. if you’re only `using` stdlibs or you have control of the dependencies yourself. This scenario also doesn’t apply to a single `using`, although explicit `using` would still be a good habit.)

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [July 22, 2021, 9:34am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/24 "2021-07-22T09:34:34Z")

</div>

This was very much related to my original concern. My current mindset is that this is a normal oopsie/bug/breakage and should just be treated as such. Users can handle it by pinning versions of dependencies (assuming they can figure out what went wrong) and thanks to the disambiguation trick (haven’t tried it yet to see if it works though) quick fixes are trivial.

It is always good to have strategies to avoid such things and I suppose the explicit import strategy is one such strategy.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 22, 2021, 2:35pm UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/25 "2021-07-22T14:35:48Z")

</div>

> [@GunnarFarneback](#):
>
> a necessity if you take semantic versioning seriously.

Excellent point, perhaps this should be mentioned in the [namespaces section](https://docs.julialang.org/en/v1/manual/modules/#namespace-management) of the manual.

---

<div class="post-metadata">

**Author:** ![cscherrer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cscherrer/32/7631_2.png) [@cscherrer](https://discourse.julialang.org/u/cscherrer)\
**Post date:** [July 22, 2021, 5:16pm UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/26 "2021-07-22T17:16:27Z")

</div>

> [@DrChainsaw](#):
>
> > Even when `name` is exported, you can just write `using Foo; using Foo: name` to disambiguate the origin of `name` .
> 
> Wow, I had no idea it worked like that! I guess I should have tried @rdeits suggestion before complaining

🤯

I had no idea you could do this; I’ve often wished we could do `using Bar hiding name`.

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [July 22, 2021, 9:53pm UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/27 "2021-07-22T21:53:27Z")

</div>

> [@cscherrer](#):
>
> I’ve often wished we could do `using Bar hiding name` .

I think this could be a good feature. Something like:

```julia
using SomePackage except: Foo, Bar, f, g

```

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [July 22, 2021, 10:01pm UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/28 "2021-07-22T22:01:07Z")

</div>

Imo the IDE should just add explicit `: foo` statements when `foo` is used.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [July 23, 2021, 11:36am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/29 "2021-07-23T11:36:48Z")

</div>

I could swear that I have seen VS code doing this lately. Unfortunately it has in most cases been an annoyance when I mistype something, but if this is the reason I could certainly start loving that feature.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [July 23, 2021, 11:38am UTC](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995/30 "2021-07-23T11:38:36Z")

</div>

I have also yearned for this. To me it seems like `using Foo; using Foo: somecollidedname` is a working substitute, but I haven’t started exploring it yet.

[Previous page](https://discourse.julialang.org/t/opinions-for-exporting-common-names/64995.md?page=1)
