RE: [sysapps/raw socket api]: New version based on Madrid meeting comments and comments from Ke-Fong Lin

Hi,

Yes, both are possible and actually used in W3C:
- Web Intents API [1] uses a dictionary and documents in prose which dictionary members are mandatory.
- IndexedDB API [2], File API [3] and DOM Event [4] seem to be using the other pattern (mandatory argument distinct from the dictionary).

I tried looking at the Web API Design Cookbook [5] to see what was advised. It does state "Property bag objects are commonly used to define optional parameters for certain methods of given interfaces". However, one of the examples is taken from Web Intents which uses a Dictionary containing non-optional members.

So as Jonas, either way seems acceptable. It does seems that dictionary are more commonly used for optional parameters though.

Kr,
Christophe DUMEZ.

[1] http://www.w3.org/TR/web-intents/#intent-parameters-dictionary
[2] http://www.w3.org/TR/IndexedDB/#widl-IDBDatabase-createObjectStore-IDBObjectStore-DOMString-name-IDBObjectStoreParameters-optionalParameters
[3] http://www.w3.org/TR/FileAPI/#creating-revoking & http://www.w3.org/TR/FileAPI/#blob
[4] http://www.w3.org/TR/2012/WD-dom-20120405/#interface-event
[5] http://www.w3.org/TR/api-design/#using-dictionaries
________________________________________
From: Jonas Sicking [jonas@sicking.cc]
Sent: Tuesday, April 23, 2013 21:23
To: Marcos Caceres
Cc: Christophe Dumez - SISA; Nilsson, Claes1; public-sysapps@w3.org; Edenbrandt, Anders; Ekberg, Björn; Falk, Mattias; Isberg, Anders
Subject: Re: [sysapps/raw socket api]: New version based on Madrid meeting comments and comments from Ke-Fong Lin

On Tue, Apr 23, 2013 at 11:04 AM, Marcos Caceres <w3c@marcosc.com> wrote:
>
>
>
> On Tuesday, April 23, 2013 at 6:52 PM, Jonas Sicking wrote:
>
>> Yup, as written they are optional.
>>
>> What we can and should do is to use prose to say that an exception is thrown if either of them is left out when the constructor is called.
> If the method has required not-nullable arguments, shouldn't those be the first two arguments of the method (and the third argument being the optional dictionary stuff)?

I think either is fine. I think we should use whatever creates the
most understandable code for authors.

It would be nice if WebIDL pointed out that this was an ok practice.

/ Jonas

Received on Tuesday, 23 April 2013 19:53:04 UTC