4 ms·
This isn't an isolated problem; it comes up in other contexts as well. Consider the default zero-zero GPS coordinates (and use an app for plane or shipping trac
by cstross 10y ago
This isn't an isolated problem; it comes up in other contexts as well. Consider the default zero-zero GPS coordinates (and use an app for plane or shipping tracking to look at it). It's about 200 miles off the coast of Africa and there are thousands of dodgy transponders identifying various vessels as being located there.
And then there was this deplorable incident ( http://www.freerepublic.com/focus/news/653846/posts http://www.freerepublic.com/focus/news/653846/posts ) in which changing the batteries in a special forces' air controller's GPS receiver caused it to reset and display its current location rather than the previously dialled in coordinates of a target, resulting in a fatal friendly fire incident.
Moral of story; if you're building a geolocation database or application of any kind it's a really good idea to ensure that the default values it returns in event of a reset or a query with inadequate input parameters points somewhere harmless or pointedly asks, "are you sure about that?"
- philipov 10y agoAnd this is why nullable data types are important!
- Filligree 10y agoNullable types are fine. The key is to make them explicitly nullable, so that programmers are allowed to use non-nullable types as well. Both need to be permitted. Ideally by way of sum types, but Kotlin's approach should be okay.
- sanderjd 10y agoWhy do you need both? Are there use cases for null that are not covered by a (non-nullable) type with present and absent variants?
- clappski 10y agoI think the distinction between nullable types and the non-nullable types you speak of is fairly narrow, you've just made it type safe (which isn't a bad thing!).
- sanderjd 10y agoI don't necessarily disagree, what I don't understand is the parent comment's use of the word "need" in "Both need to be permitted". It makes me think there is something nullable types can do that non-nullable types can't do, and I'm just not sure what that is. Something like "it is fine to permit both" would make sense to me. I guess maybe it's because in a language with no value types (like anything on the jvm), using Optionals everywhere requires a lot more objects to be allocated, so in allocation-sensitive code it might make more sense to use nulls instead.
- willvarfar 10y ago> about 200 miles off the coast of Africa http://www.nullisland.com/ http://www.nullisland.com/
- rmc 10y ago> Consider the default zero-zero GPS coordinates (and use an app for plane or shipping tracking to look at it). It's about 200 miles off the coast of Africa and there are thousands of dodgy transponders identifying various vessels as being located there. There actually is a weather bouy at 0, 0. It's mapped in OpenStreetMap with a note of "This is actually here, it's no a bug" https://www.openstreetmap.org/node/3815077900