Re:Ask HN: Do You Use Enum for Yes, No, Unset?
by sumy23 on Saturday June 18, 2022 @02:23AM
(#31787639)
I think people are conceptually fine with null. What they’re annoyed with is the inability to know if null is a possible value for a variable in many programming languages, e.g. Java.
[ Parent
| on HN ]
Re:Ask HN: Do You Use Enum for Yes, No, Unset?
by dhzhzjsbevs on Saturday June 18, 2022 @03:34AM
(#31787946)
I understand this but just basic code hygiene of null checking at boundaries and edges makes this a non issue.
You shouldn't be setting nullable variables to null so far away from where they're used that they're a problem.
E.g. if you're passing around an object with a possibly null value attached you should instead set it to a default empty state, empty string, zero, false etc.
Its only in rare circumstances that you should be needing to worry about null values.
I will however concede that non nullable types are super useful. I just don't think languages should remove null entirely. E.g. some rust projects have so many options types null would have been easier to code around. I know this is down to inexperience but at that point you've lost me - inexperience with null types is the only thing that makes null types a big problem.
Re:Ask HN: Do You Use Enum for Yes, No, Unset?
by unsafecast on Saturday June 18, 2022 @03:11AM
(#31787829)
Indeed. Optional values are literally the same as null, but you know that it _can_ be null.