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

Clarify getting a key that does not exist from a map #179

Open
domenic opened this issue Dec 6, 2017 · 5 comments
Open

Clarify getting a key that does not exist from a map #179

domenic opened this issue Dec 6, 2017 · 5 comments

Comments

@domenic
Copy link
Member

domenic commented Dec 6, 2017

Contrast lists:

An indexing syntax can be used by providing a zero-based index into a list inside square brackets. The index cannot be out-of-bounds, except when used with exists.

with maps:

To get the value of an entry in an ordered map given a key is to retrieve the value of any existing entry if the map contains an entry with the given key, or to return nothing otherwise. We can also use the indexing syntax explained above.

I think we should say "must not" and disallow out-of-bounds keys in both cases, requiring you to test with "exists" first.

An alternative is to define "nothing" to mean some special no-value, but the web has enough of those already (null, undefined, some specs use "failure") so I'd rather not do that.

Thoughts? Happy to whip up a PR if people agree. /cc @mkruisselbrink; this came up in w3c/FileAPI#92 (comment)

@annevk
Copy link
Member

annevk commented Dec 7, 2017

I've been using nothing in whatwg/xhr#176. It is somewhat awkward to do an exists test first.

Is it really bad to have some special values that make things more convenient? E.g., the reason I like failure a lot is that you then don't have to try/catch things. Just branch on the return value and carry on.

@domenic
Copy link
Member Author

domenic commented Dec 7, 2017

I think having null, undefined, failure, and nothing is way too many... That example you gave seems straightforward to replace with an exists tests, unless I'm missing something? It doesn't even use the returned value.

@annevk
Copy link
Member

annevk commented Dec 7, 2017

Way too many? What else do you want to get rid of? Agreed that we can probably drop "nothing" though. I misremembered.

@domenic
Copy link
Member Author

domenic commented Dec 7, 2017

I'm not sure we can get rid of the others, although we can limit undefined to just the cases where we need to directly interface with JS (and, as such, not make it an Infra concept). But having 2 in Infra/3 in the platform already feels like too many, thus not wanting to add another :)

@annevk
Copy link
Member

annevk commented Jan 4, 2018

Note that we also have "argument not given" which is arguably also a special value.

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

No branches or pull requests

2 participants