-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
ArrayList: embrace the word "reserve" #22137
base: master
Are you sure you want to change the base?
Conversation
Follows the convention that a single word used to describe a function variant is desired if possible.
Matches the same word used for the corresponding append functions.
This word is shorter and has a more accurate definition.
I like the change. |
Would it make sense to always push "Reserved" to the end of the name? and also not abolish "ensure"? |
I also like the idea of calling the function that may no-op try list.ensureReserved(gpa, 1);
try list.ensureReserved(gpa, 1); I think it plays well with the usage of 'ensure' in |
But |
Whoops, didn't read the actual diff. I don't see how In my mind, 'reserved' space is talking about only the unused elements, so maybe I would just need to adjust how I view it. This means the semantics of |
I find the naming introduced in this PR less clear. To me, a call like |
Renames "AssumeCapacity" to "Reserved", following the convention that a single word used to describe a function variant is desired if possible. Similarly, renames "ensure" to "reserve", so that the same word appears on both ends of those fundamentally connected functions.
⬇️
I generally like this, since I think it's a slimmer and more coherent API but I can think of one reason not to do this, which is that "ensure unused capacity" succeeds in communicating that a secondary call is a no-op while "reserve unused" incorrectly implies that there is an additional reservation counter.
⬇️
I think this naming convention shines when combined with more complicated stuff, for example, the
ArrayHashMap
methodputAssumeCapacityNoClobber
would becomeputReservedNew
.