whatwg / webidl

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

Shepherd: difference between "record" and "record type" #233

Open annevk opened 7 years ago

annevk commented 7 years ago

I don't understand https://heycam.github.io/webidl/#idl-record. The heading is a dictionary definition (not exported). Then we have record type (exported). Then we have mappings (not exported, for=record).

What is the difference between record and record type? Why is mappings for=record and not for="record type"?

And can we export mappings?

I was trying to clean up some of this, but got

Traceback (most recent call last):
  File "/usr/local/bin/bikeshed", line 9, in <module>
    load_entry_point('Bikeshed==0.0.0', 'console_scripts', 'bikeshed')()
  File "/Users/annevk/GH/bikeshed/bikeshed/__init__.py", line 196, in main
    doc.preprocess()
  File "/Users/annevk/GH/bikeshed/bikeshed/__init__.py", line 590, in preprocess
    highlight.addSyntaxHighlighting(self)
  File "/Users/annevk/GH/bikeshed/bikeshed/highlight.py", line 85, in addSyntaxHighlighting
    highlight(el, translateLang(lang))
  File "/Users/annevk/GH/bikeshed/bikeshed/highlight.py", line 27, in highlight
    widl = parser.Parser(text, IDLUI())
NameError: global name 'parser' is not defined
annevk commented 7 years ago

This blocks https://github.com/whatwg/fetch/pull/412 by the way.

tobie commented 7 years ago

Bikeshed's bleeding edge is broken right now, see: https://github.com/tabatkins/bikeshed/issues/867.

tobie commented 7 years ago

What is the difference between record and record type.

I don't know. We seem to have this for some types but not all. Unless there's a good reason to have both, we should probably clean it up.

annevk commented 7 years ago

@jyasskin was this copypasta or intentional?

bzbarsky commented 7 years ago

A record is a thing of that a key-value mapping.

A record type is a type whose values are records.

The difference is the same as the difference between "long" and "5".

annevk commented 7 years ago

I don't really get the analogy.

5 is an instance of a long, sure.

But "record" is not an instance of a record type. A specific record, sure, but the word record by itself is not.

Anyway, I'm going to submit a PR to at least export mappings since that's blocking Fetch from using records.

tobie commented 7 years ago

Closed via #239 and https://github.com/heycam/webidl/commit/274117f761b5366a8ac88187ddb00089f8a63cd3.

annevk commented 7 years ago

I didn't close this intentionally. I'd still like to figure out the difference. Also, if they indeed turn out to be distinct somehow we should probably export both of them.

bzbarsky commented 7 years ago

A specific record, sure, but the word record by itself is not.

I think "a record" would be "some instance of some record type", at least for me.

"the record" would be "a specific instance of some record type".

I'd be interested in how this is actually being used in context.

annevk commented 7 years ago

https://github.com/whatwg/fetch/pull/412/files "if object is a record, then for each mapping (key, value) in object"

annevk commented 7 years ago

Anyway, you're right, and ECMAScript does the same kind of thing describing its types: https://tc39.github.io/ecma262/#sec-list-and-record-specification-type.

Although ECMAScript does not seem to use a distinct <dfn> for the type and instance.

So do we want a <dfn> distinction between type and instances? And if so, should they all be exported?

bzbarsky commented 7 years ago

if object is a record, then for each mapping (key, value) in object

In that case the intent is "if object is an instance of the record type", just like saying "if object is a Headers object" would mean "if object is an instance of the Headers interface type" or so....

TimothyGu commented 7 years ago

Just to be clear, the language I used in whatwg/fetch#412 is adapted from the language in Web IDL spec itself. For instance:

2.11.25. Record types — record<K, V>

The order of a record’s mappings is determined when the record value is created. ... In language bindings where a record is represented by an object of some kind, passing a record to a platform object will not result in a reference to the record being kept by that object.

That is pretty much analogous to other IDL types as well.

dictionary identifier {
  type dictionary_member_identifier;
};

In this case, identifier is a dictionary type, while an instance of it would be a dictionary.

annevk commented 7 years ago

Yeah, I think your PR is fine.

I'm mostly wondering about the distinction between types and instances, but maybe the distinction only matters if there's syntax for types. E.g., the URL Standard defines URLs (not talking about the IDL interface here). Arguably they're a type, but we don't really make that distinction explicit.

annevk commented 7 years ago

The other thing here is that what IDL has as definition for "record" is the heading that says "record types". So even if there's a valid distinction between the two, the current setup doesn't really illustrate that I think.