W3C home > Mailing lists > Public > public-media-capture@w3.org > February 2016

Re: Using enums to avoid default true in "settings dictionaries" (#466, #467, #471)

From: Jan-Ivar Bruaroey <jib@mozilla.com>
Date: Sun, 21 Feb 2016 11:31:02 -0500
To: Peter Thatcher <pthatcher@google.com>, Martin Thomson <martin.thomson@gmail.com>
Cc: Harald Alvestrand <harald@alvestrand.no>, "public-media-capture@w3.org" <public-media-capture@w3.org>
Message-ID: <56C9E646.3000400@mozilla.com>
On 2/21/16 11:01 AM, Jan-Ivar Bruaroey wrote:
> On 2/20/16 2:36 AM, Peter Thatcher wrote:
>> So how are we better off with an enum in this case?
>
> Because there's precedent for expecting undefined to be interpreted as 
> false [1], and no such precedent for strings?

For example, imagine this code in your company's source tree written by 
someone else:

     function foo(label, ordered) {
       pc.createDataChannel(label, {ordered: ordered ? true : false });
     }

then someone touching that area might feel compelled optimize it to:

     function foo(label, ordered) {
       pc.createDataChannel(label, {ordered: ordered });
     }

except today they'll unwittingly have introduced a bug, because 
elsewhere in the tree people readily expect these two calls to mean the 
same:

     foo("label", false);
     foo("label");

and in the second case, the person touching the code will have subtly 
changed data channels to be ordered, which was not their intent.

If instead the code looked like this:

     function foo(label, ordered) {
       pc.createDataChannel(label, {ordered: ordered ? "ordered" : 
"unordered" });
     }

then there is no obvious optimization.

.: Jan-Ivar :.
Received on Sunday, 21 February 2016 16:31:32 UTC

This archive was generated by hypermail 2.3.1 : Sunday, 21 February 2016 16:31:33 UTC