3 ms·
> SQL is afaik unique in its belief that algebra involving nulls should yield nulls instead of boolean values. Really? The basic operations of boolean algebra
by dragonwriter 5y ago
> SQL is afaik unique in its belief that algebra involving nulls should yield nulls instead of boolean values.
Really? The basic operations of boolean algebra or AND, OR, and NOT.
In JavaScript, what is:
1. null && true
2. false || null
3. !null
Well, one of them produces a boolean result, but... Actually, JS has basically an infinite valued logic, because of its truthiness/falsiness dichotomy and the rules around how the “boolean” operators preserve truthy or falsy inputs; only ! of the core boolean operators always returns a boolean
which is why !! is equivalent to Boolean().
- Pxtl 5y agoRight, but js treats all values as either truthy or falsey. Only SQL does this weird 3rd-way approach where values can be neither true nor false (except in a WHERE or ON clause where NULL is treated as false). Like, this is a language where "X OR NOT X" is not true if X = null JS, for all its wonky truthiness rules, still satisfies the basic premise that "X || !X" yields something truthy.
- dragonwriter 5y agoSQL NULL and IEEE 754 NaN are very similar in weirdness of how they propagate, for very similar reasons (they are both hacks for encoding “not a value in the domain” in a value otherwise restricted to the domain; they aren't actual values but information about the absence of an acceptable value.) Most other languages treat NULL as a distinct-but-normal value. IMO this isn't better or worse than SQL, or rather, the SQL approach is better for querying in SQL, whereas the approach common in general purpose programming languages is better more generally, but forces more special case handling.