Opinions for exporting common names

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

1 Like

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 :slight_smile:

1 Like

For package code itā€™s not only a good habit but a necessity if you take semantic versioning seriously. Assume you have the code

using Dep1
using Dep2

and declare compat

[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 usings 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.)

2 Likes

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.

Excellent point, perhaps this should be mentioned in the namespaces section of the manual.

:exploding_head:

I had no idea you could do this; Iā€™ve often wished we could do using Bar hiding name.

1 Like

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

using SomePackage except: Foo, Bar, f, g
3 Likes

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

1 Like

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.

2 Likes

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.