| I've seen different arguments on this topic and thought I'd ask HN if you all have a standard for this. Say you have a form that's filled out and saved to a DB.
One required field is a dropdown with Yes and No.
But the field begins as blank to show that a value hasn't been selected yet, ensuring that the User pays attention to the field. Do you use a Nullable Bit (DB) and Nullable Bool (Code)?
OR an Enum: Yes, No, Unset? You wouldn't use a boolean to represent states like say New, Processing, Done. But do you consider NULL a separate "state"? Thanks |
If you allow users to complete the form without choosing T/F on your field, what happens? If you fail or prevent the submission, then I would not write the schema to capture the value as a nullable field. If you do accept the form without the user selecting T/F, then you are defaulting to either T/F and the field should likewise not be nullable.
If the value is really nullable and you are using the presence of null to decide anything, then it seems reasonable to enumerate the state space explicitly with an enum so that the next dev riding by on a horse doesn't mistake your ternary boolean for a simple null.
You can make null work in any of those cases, it just seems like a headache and potential hazard, but could also just be personal aesthetics on my part.