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: Wed, 24 Feb 2016 01:48:28 -0500
To: Peter Thatcher <pthatcher@google.com>
Cc: Martin Thomson <martin.thomson@gmail.com>, Harald Alvestrand <harald@alvestrand.no>, "public-media-capture@w3.org" <public-media-capture@w3.org>
Message-ID: <56CD523C.4000405@mozilla.com>
On 2/23/16 6:30 PM, Peter Thatcher wrote:
> My opinion: B is better than A.  I have no sympathy for someone 
> calling foo(bar) and expecting it to be the same as foo(bar, false).  
> This is JS, which does all kinds of bizarre things with 
> undefined/false values, and that's just asking for pain.  For example, 
> what if foo() does addition?

And I have no sympathy for someone doing boolean addition.

> function foo(bar, baz) {
>   return bar + baz;
> }
>
> foo("bar") // "barundefined"
> foo("bar", false)  // "barfalse"
> foo(1, undefined)  // NaN
> foo(1, false)  // 1
>
> Not the same!

Lets return from WAT!-land and use booleans correctly, in conditions:

function foo(bar, baz) {
   return baz ? bar : null;
}

foo("bar") // null
foo("bar", false)  // null
foo(1, undefined)  // null
foo(1, false)  // null

.: Jan-Ivar :.
Received on Wednesday, 24 February 2016 06:48:59 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 24 February 2016 06:49:00 UTC