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

Rename push/pop_back to push/pop, add to MutableSeq #15611

Merged
merged 11 commits into from
Jul 24, 2014
Merged

Conversation

brson
Copy link
Contributor

@brson brson commented Jul 11, 2014

This fixes naming conventions for push/pop from either end of a structure by partially implementing @erickt's suggestion from #10852 (comment), namely:

  • push/pop from the 'back' are called push and pop.
  • push/pop from the 'front' are called push_front and pop_front.
  • push/pop are declared on the MutableSeq trait.
  • Implement MutableSeq for Vec, DList, and RingBuf.
  • Add MutableSeq to the prelude.

I did not make any further refactorings because there is some more extensive thought that needs to be put into the collections traits. This is an easy first step that should close #10852.

I left the push_back and pop_back methods on DList and RingBuf deprecated. Because MutableSeq is in the prelude it shouldn't break many, but it is a breaking change.

@brson
Copy link
Contributor Author

brson commented Jul 11, 2014

cc @aturon @alexcrichton @kballard

@brson
Copy link
Contributor Author

brson commented Jul 11, 2014

Hm, probably need to move around some docs here.

@@ -63,7 +63,7 @@
#[doc(no_inline)] pub use clone::Clone;
#[doc(no_inline)] pub use cmp::{PartialEq, PartialOrd, Eq, Ord};
#[doc(no_inline)] pub use cmp::{Ordering, Less, Equal, Greater, Equiv};
#[doc(no_inline)] pub use collections::{Collection, Mutable, Map, MutableMap};
#[doc(no_inline)] pub use collections::{Collection, Mutable, Map, MutableMap, MutableSeq};
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update the Vim syntax file to include MutableSeq?

@alexcrichton
Copy link
Member

Overall I'm not certain if we want these methods to be in a trait or not (yet another prelude trait), but I'm ok with as-is for now. Thinking about a question such as this would require more thought to the design of the collection traits in general.

This is definitely a step forward, and I'm a fan of it. 👍

@lilyball
Copy link
Contributor

Oh yes I forgot to say, I'm generally in favor of this as well 👍 though I agree with @alexcrichton that at some point we do need to give some thought to the design of the collection traits and make sure that what we have is appropriate.

@aturon
Copy link
Member

aturon commented Jul 11, 2014

I'm late to the party, but yes, this moves us in the right direction. We should consider adding insert and remove to MutableSeq (from @erickt's proposal) as part of a separate pass over the collections trait. 👍

One issue, though: I'm not sure this closes #10852, since that issue was at least partly about renaming shift/unshift. Since there seemed to be agreement that we want to do that, we should make sure to keep it on the list somewhere.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

@aturon Oh good point about shift/unshift. I guess those need to be push_front / pop_front and Vec needs to implement Deque?

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

I added a commit that makes push_back / pop_back default methods, which addresses most of @kballard's concerns. I'll review why the imports in the macros were needed and see if I can get rid of them.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

Guh, if Vec implements Deque then we have to deal with the inconsistency between Deque::front and ImmutableVector::head, etc.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

I'm not going to deal with that. There will be temporary redundancy.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

#15626 covers the front/back vs head/last issue.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

To deprecate shift/unshift on Vec we should probably put Deque in the prelude.

@brson
Copy link
Contributor Author

brson commented Jul 12, 2014

Added another commit that implements Deque on Vec, deprecates shift/unshift, and adds Deque to the prelude.

@lilyball
Copy link
Contributor

@brson As dcb mentioned on IRC a few minutes ago, implementing Deque for Vec actually seems pretty weird, because Deque will be expected (by the average programmer) to have an efficient push_front()/pop_front() implementation and Vec does not qualify.

@danburkert
Copy link
Contributor

I suggest not implementing Deque for Vec. The Deque docs do not say that the implementation must be efficient, but that will be a common assumption. In #10852 @nikomatsakis suggested removing shift and unshift in favor of using insert and remove.

@danburkert
Copy link
Contributor

@kballard beat me to it :)

@brson
Copy link
Contributor Author

brson commented Jul 14, 2014

Ok. I will just deprecate shift and unshift and not implement Deque.

@brson
Copy link
Contributor Author

brson commented Jul 14, 2014

All comments addressed. Vec does not implement Deque. shift/unshift are deprecated. And the imports are removed from the vec! macro.

#[link(name = "dl")]
#[link(name = "m")]
#[link(name = "stdc++")]
extern {}
Copy link
Member

Choose a reason for hiding this comment

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

This seems to have snuck in by accident.

@alexcrichton
Copy link
Member

I feel like MutableSeq is better named Queue, but I also feel that the collections traits all need better names, so I don't want that to block the renaming of the methods as well as the deprecation of shift/unshift.

r=me with the stray file removed.

@alexcrichton
Copy link
Member

As in, I don't want to bikeshed the name of a trait at this time that is rarely spoken compared to the methods.

A later PR can handle the collections traits as a whole.

bors added a commit that referenced this pull request Jul 23, 2014
This fixes naming conventions for `push`/`pop` from either end of a structure by partially implementing @erickt's suggestion from #10852 (comment), namely:

* push/pop from the 'back' are called `push` and `pop`.
* push/pop from the 'front' are called `push_front` and `pop_front`.
* `push`/`pop` are declared on the `MutableSeq` trait.
* Implement `MutableSeq` for `Vec`, `DList`, and `RingBuf`.
* Add `MutableSeq` to the prelude.

I did not make any further refactorings because there is some more extensive thought that needs to be put into the collections traits. This is an easy first step that should close #10852.

I left the `push_back` and `pop_back` methods on `DList` and `RingBuf` deprecated. Because `MutableSeq` is in the prelude it shouldn't break many, but it is a breaking change.
@bors bors closed this Jul 24, 2014
@bors bors merged commit 71a75cc into rust-lang:master Jul 24, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 18, 2023
Prefer stable paths over unstable ones in import path calculation

Fixes rust-lang/rust-analyzer#15610
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.

RFC: rename push/pop/unshift/shift to push_{front,back}/pop_{front,back}
6 participants