3 ms·
> A lot of boolean data is representing a temporal event having happened. For example, websites often have you confirm your email. This may be stored as a boole
by amelius 1y ago
> A lot of boolean data is representing a temporal event having happened. For example, websites often have you confirm your email. This may be stored as a boolean column, is_confirmed, in the database. It makes a lot of sense.
> But, you're throwing away data: when the confirmation happened. You can instead store when the user confirmed their email in a nullable column. You can still get the same information by checking whether the column is null. But you also get richer data for other purposes.
So the Boolean should be something else + NULL?
Now we have another problem ...
- buckle8017 1y agoIt should be a timestamp of the last time the email was verified. It's a surprisingly useful piece of data to have.
- amelius 1y agoEven more useful is a log of all the changes in the database. This gives you what you want, and it would be automatic for any data you store. So, keep the Boolean, and use a log.
- aydyn 1y agoNo? So you have to look at database history to extract information you think is useful? That's a terrible database design.
- afc 1y agoIt should be: std::optional<Timestamp> (or Optional[datetime] or equivalent in others languages) If you're using a type system that is so poor that it won't easily detect statically places where you're not correctly handling the absent values, you do have a much bigger problem than using bool.