Skip to content
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

Merged
merged 15 commits into from
Jun 3, 2024

Conversation

MasonProtter
Copy link
Contributor

@MasonProtter MasonProtter commented Feb 22, 2024

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), NOT master.


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)

@MasonProtter MasonProtter added the domain:docs This change adds or pertains to documentation label Feb 22, 2024
@DilumAluthge
Copy link
Member

Can/should we merge this into #42080?

@MasonProtter
Copy link
Contributor Author

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?

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@@ -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
Copy link
Contributor

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?

Suggested change
`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

Copy link
Contributor Author

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 Show resolved Hide resolved
Comment on lines 182 to 183
with the future releases of Foo 1.x and Bar 2.y which both export a
function `baz`).
Copy link
Contributor

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.

@MasonProtter
Copy link
Contributor Author

@fingolfin I've changed the !!! note section to only talk about Foo and Bar. You might be right that it's better to just stick with NiceStuff here but I think that's not ideal because it'd be good if this note was understandable on its own, but the NiceStuff example has some baggage associated with it like being defined inside Main and so we'd need to write using .NiceStuff instead of using NiceStuff.

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 Show resolved Hide resolved
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.
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in the interest of moving this PR forward, I have removed this specific small change from this PR in 862a546 and moved it to a new PR (#54575).

…hat there's the option to do `using ModuleName: ModuleName` as well"


I'll create a separate PR that contains only this small change.
@DilumAluthge
Copy link
Member

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 master).

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 master would be doing a kind of "end run" around the PR review happening in #42080.

Therefore, I propose that we change the target branch (base branch) of this PR (from master to kc/warn_using) and then merge this PR into #42080.

I'll wait a little bit, and then if there are no objections to that plan, I'll perform those steps.

cc: @KristofferC @mbauman

@DilumAluthge
Copy link
Member

Alright, hearing no objections, I'll merge this PR into #42080 (instead of into master).

@DilumAluthge DilumAluthge changed the base branch from master to kc/warn_using June 2, 2024 23:07
@DilumAluthge DilumAluthge merged commit 5a497c8 into JuliaLang:kc/warn_using Jun 3, 2024
7 checks passed
@DilumAluthge
Copy link
Member

I've merged this PR into #42080.

@MasonProtter MasonProtter deleted the patch-16 branch June 3, 2024 22:06
mbauman added a commit that referenced this pull request Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants