-
Notifications
You must be signed in to change notification settings - Fork 16
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
Method name bikeshedding #60
Comments
There was a previous conversation (see #29) about naming for the original design of this proposal. |
In Dart this is called |
I don't like
|
Both current names LGTM - definitely better than was before since they perfectly describe their logic. |
+1 to prefixing with |
I might be inclined to suggest I suppose this would also allow us to rearrange |
I suspect some may interpret |
You can look at it that way, but you can also look at as the |
Just to throw out an extreme alternative, |
How about something as simple as This was suggested in a comment from the original thread here. I think there is a good reason the proposal itself is called |
The API no longer has the "update" aspect. Only lazy initialisation. Making the name "upsert" less applicable than at the start. |
As a data point, rust's Option type (not Map) has I like |
rbuckton suggested getOrAdd/getOrCreate for these |
"create" sounds like it's going to |
Within at least the Agoric codebase, there is precedent for a |
Since existing methods are |
@PowerKiKi . I second getOrSet for the same reasons to mention. I feel it more consistent and a tiny shorter too. |
C++ simply calls this operation |
I might make a complete tool out of myself here, but why not just make it an overload for export class Map<K, V> {
get(key: K): V | undefined;
get(key: K, fallback: V | (() => V)): V;
}
|
There's a few problems with that suggestion, the most significant of which is that a method named |
@bakkot I think the use case which this proposal caters to is an almost perfect analogy for lazy accessors - and it's typically the Of course, that's still addressing only the one problem you mention explicitly; I don't know which other problems there might be. And I've said my piece about it and I promise I'm not gonna argue my point further - I'll just end by noting that I feel that in general, reusing existing vocabulary of an API where possible feels like it's more accessible / less confusing to people who are unfamiliar with it, especially if English isn't their first language - so personally I'd be much more in favour of e.g. I love the simplicity of |
I'm thinking that Does anyone object to these names strongly enough that I should bring this issue for discussion at an upcoming TC39 plenary? I'd prefer to not have to use committee time to resolve naming the methods if I can avoid it. |
My personal preference is still If a majority are happy with |
I guess I don't feel too worried about the return type of |
That is a good point, I'm also ok with |
Let's do a quick check. Everyone please 👍 this comment if you are happy with |
Everyone please 👍 this comment if you are happy with (You can also 👍 both, or neither.) |
Please vote (or raise objections to one of the options) by end of day Friday. Next week, I'll do one of: close this issue, create a pull request to change the names, or add an item to the next TC39 agenda, depending upon the results here. |
Consequently, the name
|
@bthall16 that's a really great explanation. I could feel in my gut that I preferred "insert" and you've put it into words much better than I could. |
I think @bthall16 made a very good case for keeping |
The proposal would add two new methods to Map:
getOrInsert(key, default)
- Return value corresponding to the key if present, otherwise insert the specified default value and return that.getOrInsertComputed(key, callback)
- Return value corresponding to the key if present, otherwise call the callback function to determine the default value to insert and return.Those names are placeholders, I'm opening this issue so we can bikeshed the final names to be used.
The text was updated successfully, but these errors were encountered: