DEV Community

Camilo
Camilo

Posted on

2 3

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

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay