whatwg / webidl

Web IDL Standard
https://webidl.spec.whatwg.org/
Other
405 stars 162 forks source link

Disambiguate / explain maplike vs record #303

Open scheib opened 7 years ago

scheib commented 7 years ago

It is hard to understand, simply reading the spec, what the differences in maplike and record are. But more importantly, when and why to use one or the other.

domenic commented 7 years ago

Hmm. It's hard to understand how you could get them confused. Record is a type, whereas maplike is a "macro" that generates a number of members inside an interface.

domenic commented 7 years ago

I just re-reviewed the introductory sections of each concept and they seem to be pretty distinct. E.g. maplike explains that it's something you apply to interfaces and causes them to get certain methods, whereas record explains that it's a type that represents string-keyed mappings and is represented in JS by a plain object. What concretely is missing that might emphasize these things better? What concrete phrases make them seem similar, despite the differences the rest of the surrounding paragraphs are clear about calling out?

scheib commented 7 years ago

You don't have to service my context, but I'm coming to the spec as essentially reference to explain what I'm trying to read in existing IDL. In an draft I saw a return value of e.g. maplike<unsigned short, DataView> and someone requested it be changed to record instead. Ok, but why? What are these? Off to the webidl spec to try to understand.

Only, no. I try to read maplike and I see

Ok, off to record

After reading those two, I see lots of spec text, it's trying to say something, but I have little to no understanding of what the difference is. Both are mapping K->V. Preparing this response I guess I see that record can have duplicate keys. I'm still missing the succinct high level point that makes them different. I really have no idea how to interact with a record, how are contents of the ordered associative arrays mapping instances referred to?

I think I more understand maplike, and really don't understand what record is.

domenic commented 7 years ago

They're just... different things. One is a type, and one can be applied inside a type definition to generate methods. The fact that they both have to do with key/value mappings is a small similarity but it's like saying a banana and yellow paint are confusing because both deal with the concept of yellow. It's true, but you wouldn't confuse them, as they're in completely different categories. For example you can't return a maplike since it's not a type, it's a declaration that sits inside a type definition.

Maybe one of the other watchers of this repo can be more helpful than me :/. It's hard for me to understand why this would be more confusing than the difference between a stringifier (another thing that modifies a type definition) and a typedef (another type).

tobie commented 7 years ago

The problem with WebIDL is it's super confusing until you have a holistic understanding of it. At which point it all suddenly starts to make sense. The intro should do a much better job of providing a high level-overview.

bzbarsky commented 7 years ago

In an draft I saw a return value of e.g. maplike<unsigned short, DataView>

That's .... not a thing. As in, that's not even valid IDL as a return value.

I understand where you're coming from in terms of them looking similar in some ways. But the key difference is the one that wasn't meaningful to you: maplike is an annotation on an interface while record is a type. And I'm not sure how to make it meaningful absent an understanding of what a "type" is in this context, which seems to be the situation you were in. :(

bzbarsky commented 7 years ago

@scheib If you have a specific suggestion for wording that would have made the difference clear to you, that would be extremely helpful...

scheib commented 7 years ago

Sorry for the long thread. I see maplike has an open issue for having an example. Adding one to record type also would then likely have helped significantly a reader in my context of not having holistically understood the WebIDL spec, but who was trying to look up particular terms.

Re "not a thing", I'm getting that now - it was an API draft and this started with someone requesting 'record' instead of 'maplike'. Likely the original author had a hard time understanding maplike as well and it simply looked and sounded like what they were after.

tobie commented 7 years ago

Sorry for the long thread.

You have no idea what the average number of comment is here. :D