For motivation, watch Youtube: Scott Meyers – The Most Important Design Guideline
We don’t want to annoy millions of people for the next 30 years, so let us go through the standard library and eradicate any naming inconsistencies before 1.0.
“The only thing better than two naming conventions is one naming convention.”
I’m not too familiar with the standard library, but here are my two cents:
1. "The number of items in some set or sequence of items"
Length, abbreviated len, is widely used in the meaning of “number of items in some collection of items”. This is not the case with
Iterator trait has a method
size_hint which hints at the possible “number of items in the collection of items which the iterator iterates over”. The trait method
size_hint should be renamed to either
len_hint (I don’t understand the logic in Rust abbreviations, so I can’t argue whether “length” should be abbreviated in this case or not).
2. "The first or last item in some sequence of items"
std::slice::SliceExt trait has methods named
last which refer to the first and last items respectively. Whereas
std::collections::VecDeque (and possibly others?) have methods
back to refer to the first and last items in those collections. These two competing conventions are both fine, but we should pick just one of them. Somewhat unrelated,
std::iter::IteratorExt trait also has a method named
last but it has O(n) complexity. I think that’s pretty dangerous for performance, because the common assumption is that methods named like
back are O(1). Thus,
std::iter::IteratorExt::last should probably be renamed to something like