Skip to content
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

rename hooks #13

Open
bmeck opened this issue Jul 24, 2019 · 14 comments
Open

rename hooks #13

bmeck opened this issue Jul 24, 2019 · 14 comments

Comments

@bmeck
Copy link
Member

bmeck commented Jul 24, 2019

The names toKey / toValue might be confusing if we ad an identity/equality hook in the future.

Calling these coerceKey and coerceValue likely is acceptable.

@ljharb
Copy link
Member

ljharb commented Jul 24, 2019

toString and toValue coerce already, so I'd say it wouldn't be confusing and that the precedent is very clear; however, coerceKey and coerceValue, or mapKey and mapValue, would both be acceptable to me.

@bmeck
Copy link
Member Author

bmeck commented Jul 25, 2019

landed as coerce* for now.

@bmeck bmeck closed this as completed Jul 25, 2019
@hax
Copy link
Member

hax commented Aug 27, 2019

coerce seems not very friendly to non-English speakers. I'd prefer toXXX or mapXXX if possible.

@ljharb
Copy link
Member

ljharb commented Aug 27, 2019

They’re all English words, including map and to - why is coerce (a common PLT term) unfriendly?

@hax
Copy link
Member

hax commented Aug 27, 2019

@ljharb
As my knowledge "coerce" is not a common word in simple english (assume <5000 vocabulary), for example, "coerce" is not in the CET4/CET6 vocabulary (which already include about 8000 words).

Though "coerce" is a common PLT term, it seems it's very rarely been used in API name. At least not in JS.

@ljharb
Copy link
Member

ljharb commented Aug 27, 2019

"Type coercion" is a pretty well-known concept, isn't it? String(3) is coercing a number to a string, for example.

@hax
Copy link
Member

hax commented Aug 28, 2019

@ljharb Yes it may be a pretty well-known concept, but it doesn't mean the programmers have to know the English word "coercion" for this concept.

I can only tell what most Chinese programmers do. Obviously we communicate with each other mainly in Chinese 😛 , with some technical terms in English. Whether a concept mostly expressed in English word or Chinese translation depends.

As my experience, we rarely use English words "coerce", "coercion", instead we use more general word "转换"(convert) "转型"(type conversion) in the context. Note there is no 1:1 term mapping in this case, for example "casting" could also be translated to "转型".

There may be several factors. As my previous comment, "coerce" is not in the CET vocabulary, which means most Chinese people with bachelor degree (except those major in English) or below have never learn the word "coerce" in school. Use myself as a example, even I know the word "coerce" I just found that I never really sure how to pronounce it 😝 , which prove that I never use it in daily communication before... On the other hand, if a word is used as a keyword or in the API name, the programmers have to learn it and say it in daily communication. Unfortunately "coerce" is not that case, at least not before this proposal.

@hax
Copy link
Member

hax commented Aug 28, 2019

The other factor, the concept of "coerce" may be not as clear as we thought.

See "What is the difference between casting and coercing?" on stackoverflow.

The top ranked answer say:

coercion is implicit, cast is explicit

As such explanation, String(3) is "casting" not "coercing" 😂 .

The interesting part of it is, the question has tag "C#", and ECMA-335 CLI standard already have official explanation of them, but the top ranked answers still deviate from it.

@bmeck bmeck reopened this Aug 30, 2019
@bmeck
Copy link
Member Author

bmeck commented Aug 30, 2019

I think agreeing on a name is fine, @hax & @bakkot could you discuss things since coerce and to seem to be problematic. I don't think I have high stakes in naming personally, but think if terms are seen as confusing we should reopen discussion. We could do normalize, map, etc. the options are many or there could be agreement on one of the existing ideas if we can kick off discussion.

@bakkot
Copy link

bakkot commented Aug 30, 2019

While I'm still not a fan of toKey, if coerce is going to cause more confusion it would not be terrible to end up with toKey. I'd still prefer another name, but wouldn't block over it if we can't find a mutually agreeable one.

In the spirit of suggesting names, how do you all feel about asKey?

@hax
Copy link
Member

hax commented Sep 2, 2019

I feel toXXX is like coerce and asXXX is like cast, so I'm not sure how asXXX is better than toXXX.

The names toKey / toValue might be confusing if we ad an identity/equality hook in the future

Could somebody first help me to understand the problem of toKey? Thank you.

@bakkot
Copy link

bakkot commented Sep 2, 2019

Could somebody first help me to understand the problem of toKey? Thank you.

My problem with it is that there are other things that such an operation might plausibly do which we might someday want to introduce into the language.

For example, the first time I saw this proposal I assumed it would work like a combination of the __eq__ and __hash__ methods in Python (or the equals and hashCode methods in Java, or the Hash and Pred type parameters for unordered maps in C++, or the comparer argument for dictionaries in C#): that is, the map would still store the original object (for example when iterating over the collection), but it would use the toKey method to determine how to insert objects into the map for the purposes of determining collisions. I believe this is a much more common capability in other languages than the one in this proposal (and, indeed, one we've discussed adding to JS before), so coming from another language it's what I'd expect to find. But that's not what it does.

I would ideally like to find a name which makes it clear that this operation is not that one: that this is about transforming the user-exposed representation of the data in the map, not just the value used by the underlying data store. I don't think toKey does a good job of that. (Though it may be that there is no unambiguous name.)

@hax
Copy link
Member

hax commented Sep 3, 2019

Ok, I understand your concern now, but I doubt changing name from toValue to asValue or coerceValue could really solve it (or even worse: they may think it as coerceValueForCompare 😂 )

@bmeck
Copy link
Member Author

bmeck commented Feb 26, 2021

@bakkot / @hax is there a clear conclusion to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants