DEV Community

Camilo
Camilo

Posted on

Idea: Demorgan Type

This conversation in Wren issues made me search for an alternative naming for Bools that considers 0 as false.

In JavaScript 0 is false.

(() => {
  const zero = Boolean(0);
  // false
  console.log(zero);
})();
Enter fullscreen mode Exit fullscreen mode

In other languages like Wren, 0 is considered as true.

var zero = 0
if (zero) {
   System.print("zero is true")
}
Enter fullscreen mode Exit fullscreen mode

So as a way of standarizing, one idea is using the Demorgan value as an alternative naming for Bools.

In a dream world all languages:

  • Bool will consider false, null, undefined as false, everything else as true.
  • Demorgan will consider false, null, undefined, 0 as false, everything else as true.

But since there are many languages with different implementations and considerations about what 0 means, an idea is:

  • Bool will consider false whatever the language already considers false.

  • Demorgan will consider false everything the language already considers false, except 0 which boolean value would be negated.

So in the JavaScript example:

(() => {
  const zero = Boolean(0);

  // false
  console.log(zero);

  const negatedZero = Demorgan(0);

   // true
  console.log(negatedZero);
})();
Enter fullscreen mode Exit fullscreen mode

Top comments (0)