Stream: helpdesk (published)

Topic: ✔ reexport stdlib symbols


view this post on Zulip Michael Fiano (Jul 07 2022 at 19:48):

Is it considered bad practice to reexport a few symbols from a stdlib module from your module if the intent is to provide the full API in your module and not leak implementation details?

view this post on Zulip Sukera (Jul 07 2022 at 19:49):

is it exported from the stdlib already?

view this post on Zulip Michael Fiano (Jul 07 2022 at 19:49):

Yes, in this case, just LinearAlgebra.norm

view this post on Zulip Sukera (Jul 07 2022 at 19:59):

then I'd say it's fine, as long as you don't inadvertently create a naming conflict

view this post on Zulip Fredrik Ekre (Jul 07 2022 at 20:13):

Everyone does it, but I would recommend against it -- by exporting the name like that you take on responsibility for that function. For example, if you export LinearAlgebra.norm, then my code will work without loading LinearAlgebra myself. This is fine until LinearAlgebra.norm changes behavior and my code breaks.

view this post on Zulip Michael Fiano (Jul 07 2022 at 20:16):

That makes sense, and it is one of my pet peeves with Lisp. I don't even know why I am asking now that I realize Julia doesn't have any provisions for shadowing symbols, only bindings.

view this post on Zulip Michael Fiano (Jul 07 2022 at 20:17):

In Lisp I would just shadow the original symbol, but symbols are not interned into separate module lookup table namespaces like they are in Lisp.

view this post on Zulip Michael Fiano (Jul 07 2022 at 20:17):

So I will refrain from doing that.

view this post on Zulip Brenhin Keller (Jul 07 2022 at 22:41):

Fredrik Ekre said:

Everyone does it, but I would recommend against it -- by exporting the name like that you take on responsibility for that function. For example, if you export LinearAlgebra.norm, then my code will work without loading LinearAlgebra myself. This is fine until LinearAlgebra.norm changes behavior and my code breaks.

Hadn't thought about it much, but now that you mention it I think I only ever reexport from another package when I control both packages

view this post on Zulip Notification Bot (Jul 07 2022 at 23:20):

Michael Fiano has marked this topic as resolved.


Last updated: Nov 06 2024 at 04:40 UTC