Re:Is it time to stop using sentinel values for null / “NA” ...
by Dylan16807 on Monday June 05, 2023 @04:06PM
(#36202784)
What's the memory representation of an Option<> then? Do you want to add 4 bytes to each value to hold the tag? Even if you do that, a lazy author might still provide raw access to the ints.
And in practice, if someone has an odd sentinel value like that in the data format, library authors tend to be lazy and not take the time to do that wrapping; instead, they just expose the i32 directly, maybe Option<i32>, and sharp edges abound around the sentinel.
(That is, the data format — a sentient value — encourages buggy code. And that is the billion dollar mistake: that a nullptr pretends to be a pointer, while it is not, and gets swept up in the same operations.)