Skip to content

Commit 6641a1e

Browse files
committed
Propose RingBuf -> VecDeque.
And various other adjustments.
1 parent 788dee0 commit 6641a1e

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

text/0000-rename-collections.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ The current collection names (and their longer versions) are:
2626

2727
The abbreviation rules do seem unclear. Sometimes the first word is abbreviated, sometimes the last. However there are also cases where the names are not abbreviated. `Bitv`, `BitvSet` and `DList` seem strange on first glance. Such inconsistencies are undesirable, as Rust should not give an impression as "the promising language that has strangely inconsistent naming conventions for its standard collections".
2828

29+
Also, it should be noted that traditionally *ring buffers* have fixed sizes, but Rust's `RingBuf` does not. So it is preferable to rename it to something clearer, in order to avoid incorrect assumptions and surprises.
30+
2931
# Detailed design
3032

3133
First some general naming rules should be established.
3234

33-
1. Prefer commonly used names.
34-
2. Prefer full names when full names and abbreviated names are almost equally elegant.
35+
1. At least maintain module level consistency when abbreviations are concerned.
36+
2. Prefer commonly used abbreviations.
37+
3. When in doubt, prefer full names to abbreviated ones.
38+
4. Don't be dogmatic.
3539

3640
And the new names:
3741

@@ -44,33 +48,32 @@ And the new names:
4448
* `DList` -> `LinkedList`
4549
* `HashMap`
4650
* `HashSet`
47-
* `RingBuf` -> `RingBuffer`
51+
* `RingBuf` -> `VecDeque`
4852
* `VecMap`
4953

5054
The following changes should be made:
5155

5256
- Rename `Bitv`, `BitvSet`, `DList` and `RingBuf`. Change affected codes accordingly.
5357
- If necessary, redefine the original names as aliases of the new names, and mark them as deprecated. After a transition period, remove the original names completely.
5458

55-
## Why prefer full names when full names and abbreviated ones are almost equally elegant?
59+
## Why prefer full names when in doubt?
5660

57-
The naming rules should apply not only to standard collections, but also to other codes. It is (comparatively) easier to maintain a higher level of naming consistency by preferring full names to abbreviated ones *when in doubt*. Because given a full name, there are possibly many abbreviated forms to choose from. Which should be chosen and why? It is hard to write down guideline for that.
61+
The naming rules should apply not only to standard collections, but also to other codes. It is (comparatively) easier to maintain a higher level of naming consistency by preferring full names to abbreviated ones *when in doubt*. Because given a full name, there are possibly many abbreviated forms to choose from. Which one should be chosen and why? It is hard to write down guidelines for that.
5862

59-
For example, a name `BinaryBuffer` have at least three convincing abbreviated forms: `BinBuffer`/`BinaryBuf`/`BinBuf`. Which one would be the most preferred? Hard to say. But it is clear that the full name `BinaryBuffer` is not a bad name.
63+
For example, the name `BinaryBuffer` has at least three convincing abbreviated forms: `BinBuffer`/`BinaryBuf`/`BinBuf`. Which one would be the most preferred? Hard to say. But it is clear that the full name `BinaryBuffer` is not a bad name.
6064

61-
However, if there *is* a convincing reason, one should not hesitate using abbreviated names. A series of names like `BinBuffer/OctBuffer/HexBuffer` is very natural. Also, few would think the full name of `Arc` is a good type name.
65+
However, if there *is* a convincing reason, one should not hesitate using abbreviated names. A series of names like `BinBuffer/OctBuffer/HexBuffer` is very natural. Also, few would think that `AtomicallyReferenceCounted`, the full name of `Arc`, is a good type name.
6266

6367
## Advantages of the new names:
6468

65-
- `Vec`: The name of the most frequently used Rust collection is left unchanged (and by extension `VecMap`), so the scope of the changes are greatly reduced. `Vec` is an exception to the rule because it is *the* collection in Rust.
69+
- `Vec`: The name of the most frequently used Rust collection is left unchanged (and by extension `VecMap`), so the scope of the changes are greatly reduced. `Vec` is an exception to the "prefer full names" rule because it is *the* collection in Rust.
6670
- `BitVec`: `Bitv` is a very unusual abbreviation of `BitVector`, but `BitVec` is a good one given `Vector` is shortened to `Vec`.
6771
- `BitSet`: Technically, `BitSet` is a synonym of `BitVec(tor)`, but it has `Set` in its name and can be interpreted as a set-like "view" into the underlying bit array/vector, so `BitSet` is a good name. No need to have an additional `v`.
6872
- `LinkedList`: `DList` doesn't say much about what it actually is. `LinkedList` is not too long (like `DoublyLinkedList`) and it being a doubly-linked list follows Java/C#'s traditions.
69-
- `RingBuffer`: `RingBuf` is a good name, but `RingBuffer` is good too. No reason to violate the rule here.
73+
- `VecDeque`: This name exposes some implementation details and signifies its "interface" just like `HashSet`, and it doesn't have the "fixed-size" connotation that `RingBuf` has. Also, `Deque` is commonly preferred to `DoubleEndedQueue`, it is clear that the former should be chosen.
7074

7175
# Drawbacks
7276

73-
- Preferring full names may result in people naming things with overly-long names that are hard to write and more importantly, read.
7477
- There will be breaking changes to standard collections that are already marked `stable`.
7578

7679
# Alternatives
@@ -83,17 +86,19 @@ And Rust's standard collections will have some strange names and no consistent n
8386

8487
And by extension, `Bitv` to `BitVector` and `VecMap` to `VectorMap`.
8588

86-
This means breaking changes at a much larger scale. Undesirable at this stage.
89+
This means breaking changes at a larger scale. Given that `Vec` is *the* collection of Rust, we can have an exception here.
8790

8891
## C. Rename `DList` to `DLinkedList`, not `LinkedList`:
8992

9093
It is clearer, but also inconsistent with the other names by having a single-lettered abbreviation of `Doubly`. As Java/C# also have doubly-linked `LinkedList`, it is not necessary to use the additional `D`.
9194

92-
## D. Instead of renaming `RingBuf` to `RingBuffer`, rename `BinaryHeap` to `BinHeap`.
95+
## D. Also rename `BinaryHeap` to `BinHeap`.
96+
97+
`BinHeap` can also mean `BinomialHeap`, so `BinaryHeap` is the better name here.
9398

94-
Or, reversing the second rule: prefer abbreviated names to full ones when in doubt.
99+
## E. Rename `RingBuf` to `RingBuffer`, or do not rename `RingBuf` at all.
95100

96-
This has the advantage of encouraging succinct names, but everyone has his/her own preferences of how to abbreviate things. Naming consistency will suffer. Whether this is a problem is also a quite subjective matter.
101+
Doing so would fail to stop people from making the incorrect assumption that Rust's `RingBuf`s have fixed sizes.
97102

98103
# Unresolved questions
99104

0 commit comments

Comments
 (0)