3 ms·
I've worked in mapping software and GPS in some capacity for 20 or so years, and Null Island is always my go-to example of why it's bad to use an actual valid v
by ryandrake 2y ago
I've worked in mapping software and GPS in some capacity for 20 or so years, and Null Island is always my go-to example of why it's bad to use an actual valid value for a variable as a default-initializer, as a sentinel value, or as a signal for "invalid". 0,0 is a real location and should not mean anything special besides "that exact location in the Atlantic" to your code. There are an infinite number of actually invalid lat/lon pairs, if you really, really need some constant that gets interpreted as "an invalid lat/lon". 0,0 is not one of them.
I always joke that if nuclear war ever broke out, that spot in the Atlantic is going to bear the brunt of the explosions from all of the poorly-coded computer systems firing the missiles.
- vitus 2y agoThat's not as bad as MaxMind deciding that US IP addresses should default to geolocating to the middle of some Kansas farm, in the absence of more data. (38°N 97°W) Original article: https://web.archive.org/web/20160410172437/http://fusion.net/story/287592/internet-mapping-glitch-kansas-farm/ https://web.archive.org/web/20160410172437/http://fusion.net... (I see others have also linked to other related posts)
- trailbits 2y agoEven non-physical numbers are problematic to signal 'invalid'. I had a customer use -999 as a placeholder for 'invalid' data. Years later somebody made a higher level data product that averaged and combined that data with other products, without knowing to first remove those 'invalid' values. The resulting values were all now within physical limits, but very very wrong. The best solution is to use IEEE NaN https://en.wikipedia.org/wiki/NaN https://en.wikipedia.org/wiki/NaN so that your code blows up if you don't explicitly check for it.
- HdS84 2y ago999 or 9999 etc. are extremely common in traditional statistics, especially because there is no known good sentinel value. In many cases I wished that they used the maximum value as a sentinel, e.g. take 255 for a short as invalid and make only -244 to +244 normal numbers.
- addaon 2y agoAs someone else who regularly uses 8.93 bit words for computations, I understand completely.
- gizmo686 2y agoNaN is a sentinel value, just as much as 2,147,483,647 is The only difference is that NaN is implemented in hardware. However, taking advantage of that requires using the hardware arithmetic that recognizes NaN, which restricts you to floating point numbers, and all the problems that introduces. If you have good language support and can afford the overhead, you want to replicate that behavior in the type system as some sort of tagged union: data SentinelInt32 = NAN | Int32 Or, more likely, using the equivalent of Optional<T> that is part of your languages standard library. Of course, this means boxing all of your numbers. You could also do something like: type SentinelInt32 = Int32 Then provide alternative arithmetic implementations that check for your Sentinel value(s) and propagate the appropriately. This avoids the memory overhead, but still adds in all the conditional overhead.
- ksp-atlas 2y agoThis is why languages that require handling null properly (such as Zig) are important
- xen0 2y agoOn the other hand, an advantage with using a valid 'zero' value as a default state is that nothing will break when given it. It's a perfectly valid location whereas 'sentinel' values are not.