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

library-level docs for collections #17802

Merged
merged 2 commits into from
Oct 7, 2014
Merged

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Oct 5, 2014

Adds a high-level discussion of "what collection should you use for what", as well as some general discussion of correct/efficient usage of the capacity, iterator, and entry APIs.

Still building docs to confirm this renders right and the examples are good, but the content can be reviewed now.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 5, 2014

CC @aturon @steveklabnik

//! For optimal performance, collections will generally avoid *shrinking* themselves.
//! If you believe that a collection will not soon contain any *more* elements, or
//! just really need the memory, the `shrink_to_fit` method prompts the collection
//! to *shrink* the backing array to the minimum size capable of holding its elements.
Copy link
Member

Choose a reason for hiding this comment

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

Is this emphasis needed? (There's a lot of *...* emphasis in this text?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, wow yeah. Good call.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@huon Issues addressed.

//! ### Use the `Set` variant of any of these `Map`s when:
//! * You just want to remember which keys you've seen.
//! * There is no meaningful value to associate with your keys.
//! * You just want a set.
Copy link
Member

Choose a reason for hiding this comment

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

"Use a set when you want a set" isn't a particularly helpful guideine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's a bit borderline, but it seemed... symmetric? My general pattern here is a gradient from "descriptive for newbies" to "what experts know", where "what experts know" is generally generic types like "it's the map" or "it's the set".

@steveklabnik
Copy link
Member

Thank you, this is super great :)

Are the changes to lib.rs needed?

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@steveklabnik I'm not sure what you're referring to about changes to lib.rs?

@steveklabnik
Copy link
Member

Sorry, btree/mod.rs

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@steveklabnik Yeah the examples won't work without it. It's just something that doing this revealed wasn't done. Figured I might as well toss it in.

@@ -15,6 +15,8 @@ pub use self::map::MoveEntries;
pub use self::map::Keys;
pub use self::map::Values;
pub use self::map::Entry;
pub use self::map::Occupied;
Copy link
Member

Choose a reason for hiding this comment

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

BTW, you can reexport multiple things at once pub use self::map::{Occupied, Vacant};.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Want me to change that? I was just following the pattern I saw elsewhere.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

Built and rendered.

Doesn't show up in the std re-export, which seems like a shame?

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

Found a few errors or just weird statements. Also tossed in something about adapters and rev.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

Also I just remembered that I wrote this old thing back in the day when I first started poking at collections reform. I had always intended it to be paired with something like the contents of this PR, but I believe it was decided that it didn't have a good "place" in the docs. Anyone have any ideas?

//! # When Should You Use Which Collection?
//!
//! ### Use a `Vec` when:
//! * You just want to store some items temporarily, to be processed or sent elsewhere later.
Copy link
Member

Choose a reason for hiding this comment

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

The first bullet, about temporary storage -- I'm curious what the justification is? I don't see how it argues for Vec over other collections, personally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushing onto a Vec is surely the most efficient way to collect up a bunch of values, no? Similarly Vecs should iterate the fastest for extracting the values when you want them.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I see what you have in mind. I think the "temporarily" bit threw me off -- the idea here seems to be that you just have a pile of items, where you don't care about the order or any notion of key, or equality, or priority. And yes, that argues for Vec :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not super thrilled about the current wording myself. If you have any suggestions I'm all-ears. :)

Copy link
Member

Choose a reason for hiding this comment

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

"You just want want an expanding sequence of items" (somewhat redundant with the next bullet, but maybe they can/should be merged)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like "great temp storage" and "great sequence" are distinct. Particularly the fact that order is significant in only one.

Copy link
Member

Choose a reason for hiding this comment

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

I think "temporary storage" has a clearer/more specific meaning for you than it does for me. Would be interested to see how others feel about this? (Honestly, we could probably just drop this bullet without losing much.)

@aturon
Copy link
Member

aturon commented Oct 6, 2014

@gankro Thanks for taking this on! This is great. A few scattered thoughts:

  • Are you still planning on including some kind of table with asymptotics for the main operations, as you see with the Scala and Qt docs? I think that'd be a useful addition to the informal list you gave.
  • I wanted a bit of an even-higher-level overview. Something like, collections include sequences, maps, and sets -- and for each case listing the concrete data structure names together with a very brief description of the algorithm meant for those who are familiar with data structures.
  • There's a nice overview of iterators here, but of course iter lives in a separate module (partly due to the organization of the std facade, where iter lives in libcore.) We should think a bit about the best way to distribute the documentation.

Anyway, nice work!

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@aturon

  • I'd like to wait for more API stabilization before tackling perf tables.
  • Super high-level seems doable. I'll poke at it.
  • I tried to talk about iterators only in the context of using collections, as iterators are a much more general tool, but incredibly important to using collections "right". Hopefully that makes this documentation appropriate.

@aturon
Copy link
Member

aturon commented Oct 6, 2014

@gankro Ok, those all seem like super-reasonable responses. Thanks!

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@aturon new commit addresses many of your concerns. Anything outstanding?

@aturon
Copy link
Member

aturon commented Oct 6, 2014

@gankro I'm happy to land what you've got now; always room for incremental improvements later on.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 6, 2014

@aturon squashed

@aturon
Copy link
Member

aturon commented Oct 6, 2014

@steveklabnik @huonw I'm happy with this -- are both of you?

@steveklabnik
Copy link
Member

I'm fine with it.

@huonw
Copy link
Member

huonw commented Oct 7, 2014

Maybe there could be a link in the std::collections doc comment to this page, or else people probably won't see it.

It seems fine to me other than that.

@Gankra
Copy link
Contributor Author

Gankra commented Oct 7, 2014

After some IRC discussion, I went with moving this to std::collections, and having collections direct the reader there.

bors added a commit that referenced this pull request Oct 7, 2014
Adds a high-level discussion of "what collection should you use for what", as well as some general discussion of correct/efficient usage of the capacity, iterator, and entry APIs.

Still building docs to confirm this renders right and the examples are good, but the content can be reviewed now.
@bors bors closed this Oct 7, 2014
@bors bors merged commit 1d6eda3 into rust-lang:master Oct 7, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 13, 2024
…r=Veykril

fix: Surpress type mismatches in calls with mismatched arg counts

These tend to get very noisy, hiding the actual problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants