(no title)
davidverhasselt | 4 years ago
Having a distinction between `null` and `false` can be handy for values that are optional or have a dynamic default. If it's `null` you know it is not explicitly set and could use a fallback value. If it's false you know it's explicitly set as false.
A simple use-case for this is when a user can leave the field blank. This is impossible to model with only a timestamp-as-boolean.
Another use-case is dynamic defaults or fallbacks, e.g. `hidden` of a folder where if `hidden` is nil, you fall back to the parent folder's value.
TL;DR a boolean column actually has 3 states, a timestamp only has 2. Article makes a big deal about there not being any nuance about the fact that a timestamp is superior. I disagree, because you go from 3 states to 2 states, there are cases where you'd want a boolean instead of a timestamp. Ironically OP missed this nuance (or they'll pull a no-true-scotsman).
alpaca128|4 years ago
> a boolean column actually has 3 states, a timestamp only has 2.
Going with your logic a timestamp has billions of states, you just have to arbitrarily assign special meanings to certain dates that won't ever be used. Just like using null as another state I wouldn't call it a good idea, though.
hallway_monitor|4 years ago
andix|4 years ago
Use enums (or any equivalent) for states that are non-boolean.
jimktrains2|4 years ago
hallway_monitor|4 years ago
cdirkx|4 years ago
You just have to pick your `false` timestamp somewhere far into the future, let's say something arbitrary like 03:14:07 on Tuesday, 19 January 2038. The software won't be around for that long anyway, so it will never be a problem...
davidverhasselt|4 years ago
gpvos|4 years ago
Supermancho|4 years ago
Positive = timestamp
-1 = false
0 = null
thirdlamp|4 years ago
notatoad|4 years ago
cratermoon|4 years ago
Remember that in some languages the behavior of null is weird, and can be false, or can be treated as 0.
secondcoming|4 years ago
doodpants|4 years ago
[1] https://thedailywtf.com/articles/What_Is_Truth_0x3f_
timzaman|4 years ago
tuukkah|4 years ago
hibbelig|4 years ago
pezezin|4 years ago
chadlavi|4 years ago
BiteCode_dev|4 years ago
kijin|4 years ago
Javascript developers are used to certain functions returning -1 if there's no match, so -1 shouldn't feel strange as long as it's well documented.
johnchristopher|4 years ago
Besides it's about an improvement to boolean, not about adding one more optional value (which likely lead to optional values and definitely out of the boolean field).
underwater|4 years ago
rrrrrrrrrrrryan|4 years ago
Discrete events are usually more binary by nature: a thing either happened or it didn't.
That said, if it's possible for an event to un-happen, you're back in ternary-land: there's now a distinction between un-set and false which may be important to capture.
There's a reason why relational databases use ternary logic when most of the rest of the computing world uses binary logic.
You might argue that you could just create a brand new event, but now you've almost assuredly changed the grain of your table and goofed up the primary key. Your nice normalized table is now a dumb, non-performant endless event log: good luck with indexing that table and tuning those SELECT queries.
davidverhasselt|4 years ago
another-dave|4 years ago
* NULL — never published (e.g. draft) * true — live now * false — previously live but explicitly unpublished
Which you miss if just a date. Similarly he talks about `is_signed_in` — NULL/true/false let's you model the case where a user has never signed in (e.g. an admin created your account but you've never used it) but NULL/timestamp missed this
goofballlogic|4 years ago
joosters|4 years ago
maxlybbert|4 years ago
You’re correct that a Perl scalar can always be set to undef, which is the Perl name for null. But that’s not really unique to Perl. For instance, while a Java boolean can’t be null, a Java Boolean can be.
jwr|4 years ago
davidverhasselt|4 years ago
867-5309|4 years ago
gorkish|4 years ago
Viliam1234|4 years ago
Aeolun|4 years ago
unknown|4 years ago
[deleted]