-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 doc aliases for python and Java collections #81989
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
eb5e2e4
to
62df50d
Compare
62df50d
to
cd04c59
Compare
@@ -137,6 +137,7 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; | |||
/// *stat += random_stat_buff(); | |||
/// ``` | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
#[doc(alias = "map")] |
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.
Given that you're adding map
to BTreeMap
, do you want to add set
to BTreeSet
? Either way they should show up in the results though, so not really necessary.
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.
library/alloc/src/vec/mod.rs
Outdated
@@ -1486,6 +1488,7 @@ impl<T, A: Allocator> Vec<T, A> { | |||
/// ``` | |||
#[inline] | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
#[doc(alias = "append")] |
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 think this makes sense to add, but it is unfortunate that it will pollute results for Vec::append
.
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.
Do you know if the alias or Vec::append
will be shown first in the results?
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.
Also could potentially be worth adding a line to Vec::append
's docs like:
Not to be confused with
Vec::push
.Vec::append
is different from.append
in Python.
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.
Do you know if the alias or
Vec::append
will be shown first in the results?
Aliases should always be shown last in the search results, I'd say, if they are not already.
Vec::append
is different from.append
in Python.
I like the idea, but I think adding references to other languages in the documentation for the Rust function is going a bit too far. Instead, I'd go for #82000, allowing a comment
field for each alias too, where this comment can be written. Then, the search can show it however is best, i.e. something like:
#[doc(alias = "append", lang = "Python", comment =
"Not to be confused with `Vec::push`. `Vec::append` is different from `.append` in Python."
)]
What do you think? I can add it to the RFC.
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.
Sure, seems reasonable. I'll drop append
from 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.
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 seems really strange, why do you say that? That puts them behind very unrelated things because of fuzzy search.
Ah, yeah, there are too many results [*]. What about before the fuzzy ones? i.e.:
- Exact matches (non-aliases)
- Exact matches (aliases)
- Fuzzy search (any, assuming it sorts by some "similarity" index)
If we get #82000, then we could even do:
- Exact matches (non-aliases)
- Exact matches (Rust aliases)
- Exact matches (non-Rust aliases)
- Fuzzy search (any, assuming it sorts by some "similarity" index)
[*] Why is matching all that for free
? Is it due to substrings (e.g. fREm
-> fREe
) or Hamming distance or something like that? I think for words < 4 in size, it should not match if at least 3 characters match. But anyway, this is off-topic... :-) The general point is that the search results seem like they could be improved (i.e. instead of working around it with the aliases).
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.
Ah, yeah, there are too many results [*]. What about before the fuzzy ones? i.e.:
I like this. Can you open an issue for it? I think it makes a lot of sense.
[*] Why is matching all that for free? Is it due to substrings (e.g. fREm -> fREe) or Hamming distance or something like that? I think for words < 4 in size, it should not match if at least 3 characters match. But anyway, this is off-topic...
Can you open an issue for that too? 😆
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.
cd04c59
to
1a79e76
Compare
This comment has been minimized.
This comment has been minimized.
dd41345
to
0188363
Compare
Hm, it seems not bad necessarily but I'm a bit worried about eventually everything in std gaining 3-4 different aliases, some conflicting, depending on perspective. It seems like we should at least put a comment next to each one for origin language -- I wonder if aliasing as "python dict" would be a bad idea. cc @rust-lang/libs, curious on thoughts. |
See also #82000. |
Yeah I feel like adding all the equivalents of everything in popular other langues quickly gets out of hand. I think I'd prefer to only add those where the word is common enough that it's often used as a regular noun/verb, like "memcpy it to some newly malloc'd buffer" or "put the pairs in a map". So for this specific PR, I'd say I also think we should be extra careful with names for things that already have another related meaning in Rust. For example, depending on the languages someone might already be familiar with, the difference between an array and Vec could be pretty confusing. Adding an alias like |
I agree with @m-ou-se and would strongly opposed adding specific aliases like Using abstractions like "map" and "set" as aliases seems fine to me. Nobody owns those words. I'd say "dict" is somewhat border line since it's very strongly associated with one ecosystem in particular. Ecosystems use lots of different names for their map types. "associative array" (PHP) and "hash" (Ruby) come to mind. If we add "dict," should we also add those? On the other hand, at least "associative array" and "dict" are fairly abstract words on their own. So I'm torn on those in particular. |
0188363
to
6591010
Compare
I removed |
|
I think
Well... yes, there are differences between
I'm not seeing myself how Anyway, I believe adding Clicking "Try on DuckDuckGo" is not very useful, it will point the user to an array (nope, that's not what the user wanted) and |
This comment has been minimized.
This comment has been minimized.
`append` sounds strange because Rust already has append and it does something different. The reason I added it is one of my friends knew from python that it added a single element to the end of an array. When they started learning Rust, rather than looking for pop(), they wrote something like ```rust my_vec.append(&mut vec![x]); ``` which is clearly not ideal. Hopefully this would have pointed them in the right direction.
6591010
to
a8c8025
Compare
Add more links between hash and btree collections - Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept See also rust-lang#81989 (comment).
We discussed the We didn't reach a clear conclusion about which kind of aliases we should and shouldn't have, but we did feel like adding more aliases like this is not the way to go. If someone doesn't know about e.g. Similarly for We didn't make any final decision, but we do want some kind of clear guideline/policy that we can all agree on before accepting more aliases. Feel free to open an issue on https://github.com/rust-lang/libs-team or ping us on Zulip if you (anyone) want to work on this. (Edit: For anyone interested, some more details/thoughts on aliases here: #81988 (comment)) |
That makes sense to me. I'm not planning to put time into making a long-term policy. |
Add more links between hash and btree collections - Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept See also rust-lang/rust#81989 (comment).
No description provided.