Re: Handling too few arguments in method calls

On Jun 22, 2009, at 12:05 AM, Simon Pieters wrote:

> On Mon, 22 Jun 2009 02:53:22 +0200, Cameron McCormack  
> <cam@mcc.id.au> wrote:
>
>> Does anyone have an opinion on which way this should be specified  
>> in Web
>> IDL?  Assuming this interface:
>>
>>  interface A {
>>    /* f1 */ void f(in DOMString a);
>>    /* f2 */ void f(in DOMString a, in float b);
>>    /* f3 */ void f(in DOMString a, in float b, in float c, in float  
>> d);
>>  };
>>
>> option 1 would be to have:
>>
>>  a.f() be like calling f1 with (undefined)
>>  a.f('a') be like calling f1 with ('a')
>>  a.f('a', 1) be like calling f2 with ('a', 1)
>>  a.f('a', 2, 3) be like calling f3 with ('a', 2, 3, undefined)
>>  a.f('a', 2, 3, 4, 5) be like calling f3 with ('a', 2, 3, 4)
>>
>> and option 2 would be to have:
>>
>>  a.f() throw an exception
>>  a.f('a') be like calling f1 with ('a')
>>  a.f('a', 1) be like calling f2 with ('a', 1)
>>  a.f('a', 2, 3) throw an exception
>>  a.f('a', 2, 3, 4, 5) be like calling f3 with ('a', 2, 3, 4)
>>
>> Web IDL currently says to throw on any incorrect number of arguments,
>> so it seems that it should change to be one of the above two options.
>
> I think I prefer option 2. It's easier for authors to find their  
> mistake. If a spec author wants the behavior of option 1, then  
> that's possible with [Optional].

I prefer option 1 because it is closer to the behavior of the built-in  
functions in the JavaScript language.

     -- Darin

Received on Monday, 22 June 2009 07:25:41 UTC