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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more