Re:Ask HN: Anyone know any funny programming jokes?
by gugagore on Thursday January 21, 2021 @11:41AM
(#25860803)
I'm not sure they were suggesting using type-specific sentinel values (like null and nan), but to always use null or point to a value.
I like wrapping the information in a data structure exactly as you suggested, and if you never mutate the dereferenced pointer, it's equivalent to what they proposed. Big if, though.
The best is to do this generically with https://en.m.wikipedia.org/wiki/Option_type , since this pattern comes up regularly, not just with this one domain concept of "Filter"
Our code is riddled with heavily overloaded meanings in a single value/domain, and if you have a variety of filters, you end up with this atrocity:
Compare that to And the variety of code that has to work with either of these examples.What happens if the boolean is true but the filter is null?
An assertion fails miserably.
What would the vice versa case even mean?
That an assertion failed miserably.
What happens if the filter is one? Minus one? Equals to PC(IP), BP? If NULL filter has to search for NULL values in a dataset? If we are looking for NAN values in a corrupted one (this one is even more tricky)?
Deeply!