-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial note about Map/Set equality algorithm needs updating #3473
Comments
Eh... I think it's fine to describe the way Maps compare keys as "using SameValueZero" even though mechanically the algorithms are written to canonicalize and then use SameValue. There's not actually a difference. |
But either way people are confused:
OTOH if the algorithm uses SameValueZero, we ease all these mental burdens for free. |
At the cost of not using the same operation when adding/deleting vs querying, yes, but that's confusing in a different way. Thoughts on adding a NOTE above the various |
If I shall ask: how is adding/deleting vs querying different if we need to canonicalize every input anyway? |
I'm afraid I don't understand the question; can you rephrase? If you're asking why we need to canonicalize when adding, it's because otherwise we'd have to canonicalize when iterating over the contents of the data structure, and it's conceptually cleaner to do it on input rather than output. |
I'm asking about this:
I was supposing that the keys are canonicalized at the input boundary, so I'm not sure why these methods would not all be able to use SameValueZero. |
If the keys are canonicalized at the input boundary then there is no reason to use SameValueZero. SameValueZero is just SameValue plus special handling for -0, but if you canonicalize then -0 can't be an input. |
Yes, but our point is that although SameValueZero and SameValue are operationally equivalent in this case, using the former in the algorithm lowers a lot of cognitive burden for readers, because if you use SameValue, then explaining it as either SameValueZero or SameValue in prose doesn't make much sense. |
After #3337, Map/Set key equality no longer uses SameValueZero. The editorial note in several places need updating:
FWIW, I am much in favor of sticking to SameValueZero in the algorithms, because it helps readers understand better what's going on even without realizing that keys are canonicalized, but in the current form it seems to present more confusions. See also mdn/content#36698.
The text was updated successfully, but these errors were encountered: