Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
willol13898yI actually used a 3-states boolean in a database: true, false or null.
Let's be honest: that was an ugly hack, not proud of it. -
Root825318y@willol That can be useful, actually, e.g. to indicate whether the user has been asked for the data yet.
-
willol13898y@Ashkin I don't remember the exact use case, but it began as a simple boolean, and a third possibility came later... No excuses, honestly :)
-
@Ashkin how would that need 3 states? It is either asked or not. That's true and false. Or am I missing something?
-
Root825318y@Charmesal Let me share an example to explain:
Due to developer incompetence, newsletter subscriptions were stored, not in the User table, but on another server entirely. When he was fired, we lost access to that server -- and most others. (He refused to share credentials...).
To remedy the newsletter situation specifically, I added another column to the User table: bool subscribed_to_newsletter. This defaulted to null, indicating "not set." When the user accessed his/her profile and this col was null, the site would ask them specifically if they wanted to subscribe or not, and record their answer as true/false. This allowed me to record both bits (asked and subscription status) within a single column in a very obvious and easy-to-understand way.
(Adding a second column would have also worked; however, the column would be useless in the future. As the question is present on the registration page, all future registrations would have a true/false subscription status set.) -
Sumafu22488y@vrpg1998 Look at TypeScript, it is very similar to JavaScript but with types.
But to work in Browser you need a TypeScript compiler. -
@Ashkin I can see why you would use it in that manner. A bool being null still feels weird to me but I get it and I understand why you would choose that. Thanks for the explanation.
Related Rants
There are in fact three unique Boolean values.
Their names are "true", "false", and
java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
...
undefined
boolean
nullpointerexception
java