-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add guidance for using qualified names in packages #53428
Conversation
Can/should we merge this into #42080? |
If we think that would help get either of them merged faster then sure. @KristofferC, do you want to merge this branch into yours? Or should we just keep them as separate PRs? |
doc/src/manual/modules.md
Outdated
brings *only* the module name into scope. Users would need to use `NiceStuff.DOG`, `NiceStuff.Dog`, and `NiceStuff.nice` to access its contents. Usually, `import ModuleName` is used in contexts when the user wants to keep the namespace clean. | ||
As we will see in the next section `import .NiceStuff` is equivalent to `using .NiceStuff: NiceStuff`. | ||
brings *only* the module name into scope. Users would need to use `NiceStuff.DOG`, `NiceStuff.Dog`, and `NiceStuff.nice` to access its contents. | ||
As we will see in the next section `import .NiceStuff` is equivalent to `using .NiceStuff: NiceStuff`. Usually, `import ModuleName` or `using ModuleName: ModuleName` is used in contexts when the user wants to keep the namespace clean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the sudden switch from NiceStuff
to ModuleName
? I am fine with either name, but shouldn't it be used consistently, i.e. either everything with NiceStuff
or else everything with ModuleName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That wasn't really my choice, I was just modifying the existing docs with its existing name scheme. See: https://docs.julialang.org/en/v1/manual/modules/#Standalone-using-and-import
FWIW I think maybe the that could be overhauled, but I also don't think it's necessary.
doc/src/manual/modules.md
Outdated
@@ -168,6 +168,23 @@ Importantly, the module name `NiceStuff` will *not* be in the namespace. If you | |||
julia> using .NiceStuff: nice, DOG, NiceStuff | |||
``` | |||
|
|||
!!! note | |||
Qualifying the names being used as in `using NiceStuff: NiceStuff, nice` is recommended over plain | |||
`using Foo` for released packages, and other code which is meant to be re-used in the future with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A third name, Foo
... Let's stick with one, e.g. NiceStuff
perhaps?
`using Foo` for released packages, and other code which is meant to be re-used in the future with | |
`using NiceStuff` for released packages, and other code which is meant to be re-used in the future with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, yeah this naming conflict should be avoided. I think for the purposes of this !!! note
though, maybe it'd be better to use a new set of names Foo
and Bar
because we want to talk about conflicts, and we also want this !!! note
section to be readable standalone.
doc/src/manual/modules.md
Outdated
updated dependencies or future versions of julia. | ||
|
||
The reason for this is if another dependency starts to export one of the | ||
same names as `Foo` the code will error due to an ambiguity in which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same names as `Foo` the code will error due to an ambiguity in which | |
same names as `NiceStuff` the code will error due to an ambiguity in which |
doc/src/manual/modules.md
Outdated
with the future releases of Foo 1.x and Bar 2.y which both export a | ||
function `baz`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I didn't already know what this is about, I am not sure I would understand. I think the point you are trying to make is: suppose you are doing using Foo, Bar
, and it works. But then Foo
1.1 exports a new symbol baz
, while Bar
already exports a different baz
. Then suddenly using Foo, Bar
fails.
4983382
to
e464600
Compare
Co-authored-by: Max Horn <max@quendi.de>
@fingolfin I've changed the I don't have a super strong opinion here, so let me know what you think of this change. |
doc/src/manual/modules.md
Outdated
brings *only* the module name into scope. Users would need to use `NiceStuff.DOG`, `NiceStuff.Dog`, and `NiceStuff.nice` to access its contents. Usually, `import ModuleName` is used in contexts when the user wants to keep the namespace clean. | ||
As we will see in the next section `import .NiceStuff` is equivalent to `using .NiceStuff: NiceStuff`. | ||
brings *only* the module name into scope. Users would need to use `NiceStuff.DOG`, `NiceStuff.Dog`, and `NiceStuff.nice` to access its contents. | ||
As we will see in the next section `import .NiceStuff` is equivalent to `using .NiceStuff: NiceStuff`. Usually, `import ModuleName` or `using ModuleName: ModuleName` is used in contexts when the user wants to keep the namespace clean. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when the user wants to keep the namespace clean.
There's nothing that says what it means for a namespace to be "clean," nor how changing how you load a package affects cleanliness. Since the exported names of a module aren't resolved until they're referenced, using
doesn't "pollute" the enclosing namespace in the same way that constructs from other languages do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really material to this PR. I was just moving around existing text and adding that there's the option to do using ModuleName: ModuleName
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting it be added, I'm challenging the wording used, as the motivation as written isn't particularly useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again though, that's not something new in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the "clean" bit is not nice -- but it was already there before. It seems unfair to hold this PR hostage over the author not "improving even more things".
Perhaps I am misunderstanding what you'd wish to have changed, @ararslan, in that case I'd appreciate if you could clarify what changes you are requesting exactly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ararslan If this is the only part of the diff that you have concerns about, then we can revert it from the PR and make this change in a separate PR, just in the interest of getting this PR in?
cc: @MasonProtter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…hat there's the option to do `using ModuleName: ModuleName` as well" I'll create a separate PR that contains only this small change.
The review comments have been addressed
I've been giving some more thought as to whether this PR should be merged into #42080 (as opposed to merging this PR directly into My guess is that if someone has concerns or objections to #42080, then they'll probably have those same concerns/objections to this PR. So it probably makes sense to merge this PR into #42080, so that the main discussion can occur in #42080 (which is where the majority of the discussion has been happening thus far). Also, I don't want to give the impression that merging this PR into Therefore, I propose that we change the target branch (base branch) of this PR (from I'll wait a little bit, and then if there are no objections to that plan, I'll perform those steps. cc: @KristofferC @mbauman |
Alright, hearing no objections, I'll merge this PR into #42080 (instead of into |
I've merged this PR into #42080. |
Note: this PR was merged into #42080. It was NOT merged into
master
.Note: the base branch (target branch) of this PR is
kc/warn_using
(#42080), NOTmaster
.This is additive to #42080 which adds advice to the docstring of
using
.The wording here is a tweaked version of @IanButterworth's suggestion here: #42080 (comment)