Urgent.News

600+ sources. One page. See who else covered it.

Editions

Tech

Code Smell 208 - Don't Use Null for Real Places

Learn why using (0, 0) for missing coordinates creates bugs and how a polymorphic Location type keeps Kotlin models accurate.

Code Smell 208 - Don't Use Null for Real Places

Null Island, a fictional location at 0°N 0°E in the Atlantic Ocean, has become a popular reference point for geographic information systems and mapping software. Many GPS systems place data with missing or invalid coordinates at this exact spot, where no landmass exists. Data visualization specialists started using the term around 2008 to help filter out errors in location data.

Researchers found over 300,000 geotagged photos and countless social media posts referencing Null Island, including during the COVID-19 pandemic when Johns Hopkins plotting dashboard used it for missing real locations. To avoid using null for real places, you can model unknown locations polymorphically, creating distinct types for known and unknown locations.

In code, instead of using a (0.0, 0.0) sentinel value, create an abstract Location class with methods for distance calculation and handling unknown locations. Define specific classes for Earth locations and unknown locations, each implementing the necessary methods. When processing a list of locations, use the ifKnownOrElse method to apply known actions to Earth locations or unknown actions to unknown locations, ensuring a clear distinction between real and missing data.

This approach maintains the bijection between your model and the MAPPER, preserving the relationship between real coordinates and real places on Earth.

Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at hackernoon.com →

More in Tech

More from Monday 3 August →