DEV Community

NASA’s $125M Unit Error: Why Your API Needs Explicit Naming

The Mars Climate Orbiter's destruction in 1999 resulted from a unit mismatch between metric and imperial systems. The thruster software used Newtons while input data used Pounds-Force, leading to catastrophic failure. Raw numbers without units are inherently dangerous and can lead to silent errors in software. Computers process numbers without considering context, making unit errors easy to overlook. To prevent such errors, bake the unit into your field names, making code self-documenting. Use explicit field names like `size_bytes` or `price_cents_usd` instead of ambiguous ones. Branded types in languages such as Typescript enforce unit safety at compile time, preventing incompatible unit operations. Relying solely on documentation for unit information is insufficient as it can be easily missed. Standardizing on SI units internally is a best practice, but maintaining consistency is key. For legacy systems, introduce new, explicit fields and deprecate the old ones gradually. Integers are preferred for units like currency and time to avoid floating-point precision issues.
favicon
dev.to
dev.to