-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Rename some of the standard collections for consistency and clarity #580
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
Conversation
I fully support the idea of unobfuscating the type/function names in the Rust library. Every single engineer I've introduced to Rust has pointed out poor naming in the library as a flaw ( |
Note that the "I don't want to type long names" argument has been defeated with code completion decades ago. Every decent editor has it (some with non-semantic completion engines, but still), including non-IDE ones like Vim, Emacs & Sublime Text. "I don't want to type long names" is an issue of tooling that either exists or can be easily built; the libraries shouldn't suffer for it. Let's not forget that code is read far more often than it is written. |
I would also argue for all the names to be "full". Vector, DoublyLinkedList, etc. But I also just really don't care at all. |
Here's some data: I just polled 5 engineers I work with. The question was "What do you think a collection class named 'DList' stands for?" I got the following responses:
Only one engineer thought of doubly linked list, and they had to think about it for a minute or so (making the name an obvious mental speed-bump). I asked them how confident they were that was what "DList" stood for, and they said they were 80% confident. This is the reason why people are complaining about the bad names. The names should be self-evident and the user shouldn't have to remember what abbreviation the author of the type went with. A "doubly linked list" could be mapped to many abbreviated names. I'll note I work with very smart people. |
I strongly believe that As for the other names, I am not so sure about them. However, I prefer renaming For |
@theemathas note that BTree is an actual data structure called a BTree, same with BTreeMap. |
I once asked if we should expand all the names, I would be for expanding all of the names, but I am not sure the core team would be behind it. |
The main problem with expending all names is it is a large scale breaking change. The main problem with not doing so is, well, if the referenced reddit comments and the comments here are any indication, then many do not like abbreviated names, and for good reasons. No matter what abbreviation rules to use, there will be some inconsistencies. (Particularly, there is no abbreviation for The reason I propose to rename If in this case, breaking the world is acceptable, then I am for expending all the names too. AFAIK, those prefer shorter names can always do aliasing, and it is easy to provide a deprecation period because of aliasing support, as we are not changing the collection methods here, only the names. |
BinaryHeap
to BinHeap
A quick and dirty search reveals that, strings (Personally, I think it is fine to still have abbreviations in function names even if the types get renamed. The important thing is that the full names appear at least once in the function signatures, and they will.) |
@theemathas, according to Wikipedia:
So it seems that |
I'd prefer:
and, because Ring Buffers always are fixed size when the term is used elsewhere
I also prefer that |
I don't think so, since the |
@Valloric While I'd like to see some of these names changed as well, the argument that short names are bad b/c some developers who don't use the language throw a hissy fit and call Rust names over them is lame. Developers are petty assholes, they're going to find something to complain about regardless. @bluss Rust's RingBuf isn't fixed-size. Surprised me too. |
FWIW, |
@jfager that was my point and why it should be renamed. |
How about you ask them what |
@CloudiDust Thanks for the RFC! I definitely understand the original motivation about the seeming inconsistency among collections names. I think that the RFC and discussion is making clear that we need to have a more formal, rather than folklore, guideline about abbreviations in names. @Valloric It would be more helpful to discuss the relative merits of various strategies here, rather than focusing on the names that your fellow developers call Rust's libraries. (FWIW, I'm also quite surprised that In general, I would ask everyone to consider that as with so many other things, there are tradeoffs here. Many of us have various habits/cultural backgrounds that makes one choice seem "obvious" but I hope that we can examine these biases and lay out some rationale. In particular, ease of writing/typing the names is not the only, or even primary benefit of short names, as far as I'm concerned. Here's how I personally see the tradeoffs. Long names can make it somewhat easier for a newcomer to "guess" the meaning of snippets of code. The Short names, on the other hand, make it more feasible to work "at scale" with things like generics and method chaining. To exaggerate -- but only slightly: AtomicallyReferenceCounted<MutuallyExclusive<DoublyLinkedList<Integer>>>
// versus
Arc<Mutex<DList<int>>> Iterator chaining offers similar examples. To me, the readability benefits of the shorter names here are enormous; I find it's much easier to see at a glance the structure of the stack of types because each name is short and easy to parse, and the names don't obscure the structure. The recent choice to introduce the use standard_library::synchronization::multiple_producer_single_consumer;
// versus
use std::sync::mpsc; In my experience, the willingness to abbreviate often makes it feasible for us to incorporate more information into names, and makes it easier to parse that information at a glance. People sometimes argue that longer names are easier to remember, but I think that's wrong and/or missing the point. For one, as @Valloric argues, full length names are tolerable in part because most people use auto-complete, which obviates much of the need for memorization. But a deeper point is that there is no way to provide useful, rigid guidelines on exactly what types should be called even if abbreviations were ruled out entirely. I mentioned one example above -- how do you decide how much to say about the implementation in a type? But there are also synonyms and other wording choices. At the end of the day, when you program against an API, you learn its names. (And it's possible to argue that short names like So I think there are reasonable arguments on both sides. And while some people complain about Rust's historical choices here, I've also heard plenty of people express appreciation for its avoidance of naming verbosity. (One final point keeping in mind is that this choice of short names has long been a part of Rust, to the point that it affects keywords -- |
I'm going to speak up for short names here. @aturon did a great job giving a robust, factual defense, I'm going to give a more personal one: I think that it's important not to pick long, "enterprise"-style names for everything. Now, this doesn't mean we should use super-short abbreviations everywhere: Rust certainly has a history of very short abbreviations that we have generally moved away from. But we've been moving towards "mid-length names". Memorable names with punch. Obviously these is not a hard-and-fast rule that one can follow, but I think it's important, and it's part of Rust's character. I would be very loathe to lose it. Also, speaking personally, while I find overly short names can be very opaque I find very long names equally hard to read. There's too much there and the "pattern recognition" part of my brain shuts off and the "actually read text" mode kicks in, which is much slower. (Ok, I am not a neuroscientist, and I am making things up about biology, but I think you know what I mean.) As far as I'm concerned the best of all worlds is when we can pick a short, one-word name that highlights the most interesting aspect of a type. Sometimes this even involves creating semi-arbitrary distinctions (e.g., I don't expect everyone to have the same tastes as I do. I'm sure other people find longer names easier to read, for whatever reason. But I don't want readers to get the impression that this is a universal taste. |
Consistency is great but longgg names are even worse, so what about abbreviating the least important parts when the full name has 3+ compound names. |
Thank you for providing a detailed rationale! I of course agree that names that are too long and unwieldy are bad, and some abbreviations are fine. For instance, I think
Nobody is suggesting that. I am suggesting What I've noticed in Rust type and function names is a very frequent pattern of unnecessary abbreviations that do little more than confuse people. Similar with To sum up, "I don't know what this name stands for" is not the primary concern (although it's a big one), it's "I want to use a DoublyLinkedList, now what name did they pick in the library? DLList? DList? DLinkedList? Crap, I have to go look and check." Every time you shorten the name from what you'd pronounce it as, you're saying that the pros of the shorter name outweigh the cons. I'm sorry, but you can't convince me that In other words, readability is so massively valuable in any codebase beyond Hello World that any changes that negatively impact it need to have something seriously great going for it. Erring on the side of code readability is almost always the right choice. |
To preempt questions like "whey is this abbreviation fine and that other one isn't:"
Etc. |
For the |
I'm a big fan of short names for the pervasive things: There's no real value in keeping long descriptive names for these. It's the Standard Library(tm), you're expected to get familiar with them either way. Yes it somewhat hurts grep, but that's an argument for better tooling, not a worse library. Link a name guide right above the search box and everyone lives happily ever after. |
@lifthrasiir, I think we are in agreement? (There was a "not" in my sentence.) And yes, I now think |
Great. I would prefer just Deque though, but you all want to reserve that for a trait. I don't think that reservation is worth it. |
And various other adjustments.
I think a change from |
@tbu- but it's not really a ring buffer, is it? |
@soulseekah It's a growable |
@tbu- right, a dynamically expandable circular buffer, but I think when talking about a plain circular buffer it's expected to be of a fixed size. So And by "alongside" I mean adding fixed-size functionality to But I agree that |
No, a dynamically growable ring buffer addresses all the use cases of a fixed-size ring buffer, just like a |
@tbu- Only if you can grow it manually and explicitly, but |
That's akin to the other collections in Rust.
Please try to keep the discussion a discussion, saying that your discussion partner's arguments make no sense does not belong there. |
@tbu- I'm not saying it's not impossible to make the dynamically growable one behave just like a fixed-size one, it's what people are doing in their own implementations, wrapping around |
It's relatively easy to make a fixed-size hash map, vector, ring buffer out of a dynamically sized one, the other way around however, is impossible to do. There's multiple things you can do when running out of storage capacity, dropping old elements, returning an error when trying to insert new ones, dropping elements based on some metrics, panicking, but you can only select one when you implement a static sized collection. Making a dynamically sized collection allows for implementing any of these strategies yourself based on the original collection. But all that is actually not part of the naming discussion, this is part of a design choice the Rust collections have made, namely "grow on missing capacity". |
That makes sense. Thanks for the discussion. |
fwiw mio has a constant-sized ringbuf implemented here https://github.com/carllerche/mio/blob/master/src/buf/ring.rs |
What about Also note that "Buf"/"Buffer" implies a queue, not a deque. |
Thanks, @CloudiDust, for your continuing work to push for clarity and consistency. This RFC nicely cleans up a few of the collection names (which somehow escaped collections reform) while maintaining Rust's overall approach to naming. The RFC has been merged. Kudos! |
@theemathas, sorry I missed and didn't reply earlier. I think Also, at least for me, it is not the As you pointed out, @aturon, thanks for the merge. |
This commit implements RFC 580 by renaming: * DList -> LinkedList * Bitv -> BitVec * BitvSet -> BitSet * RingBuf -> VecDeque More details are in [the RFC](rust-lang/rfcs#580) [breaking-change]
This commit implements RFC 580 by renaming: * DList -> LinkedList * Bitv -> BitVec * BitvSet -> BitSet * RingBuf -> VecDeque More details are in [the RFC](rust-lang/rfcs#580) [breaking-change]
RingBuf was renamed as per rust-lang/rfcs#580
This comment in /r/programming is the motivation of this RFC.
Rendered View.