4 ms·
Not sure if having a boolean value where "null" and "false" mean two different things is a good idea. Sounds like a source for a lot of bugs in business code an
by relix 14y ago
Not sure if having a boolean value where "null" and "false" mean two different things is a good idea. Sounds like a source for a lot of bugs in business code and SQL.
- krapp 14y agonaive but honest question -- aren't 'null' and 'false' different?
- majormajor 14y agoThey are, and that's where the bugs can come from. :) It leads to a situation where it's easy to come back to the code in the future (or have a new developer working on it) and see a field that's a boolean and make an assumption like "well, this is a boolean, so if it's not True than it's False." I like to make my booleans not-null so that they're, well, actually booleans, and leave stuff with three or more states to enum-like behavior.
- whit537 14y agoYeah, maybe should've gone with an enum. I end up doing "is_suspicious IS NOT null" etc.
- groby_b 14y agoOr you could just admit that it's lots of grays and use an actual number. [0..1] for a trust scale. Trust _never_ is binary. (It also rarely is one-dimensional. But that's a different story... You might get away with one dimension, since it's restricted to a very limited set of interactions)
- whit537 14y agoGood point. I was trying to get something going quickly. I expect the system to continue evolving.
- thedufer 14y agoYes, but in many languages they are both false-y. Since it looks like a boolean, the natural way of dealing with it (`if suspicious then ... else ...`) will quietly treat null the same as false in those languages.
- whit537 14y agoGittip is written in Python, where SQL's NULL becomes None, which is indeed false-y.
- sbov 14y agoDepends upon your language. Java treats a null Boolean pretty sanely.