In 1999, NASA lost the $125 million Mars Climate Orbiter as it went into orbital insertion. Due to a mismatch between US customary and SI units of measurements in one of the APIs, the spacecraft came too close to the planet, passed through the upper atmosphere and disintegrated. Sadly, this hasn’t been the only instance where a mismatch between units of measurements had catastrophic consequences, but it’s certainly one of the most spectacular and expensive ones.
How could this happen? The bad news: if you use primitive types to handle quantities in your code, due to the same practice at best, you’ve codified the unit in a variable name or database field, e.g. calling it lengthInMetres. Otherwise, you’re only relying on convention, just like Lockheed Martin and NASA did.
Join this talk to learn how JSR 385 can help you avoid $125 million mistakes, how it applies the 2019 redefinition of SI base units, and discover the immeasurable world of dimensions, units and quantities.
Indroductory slides for the Adopt-a-JSR Day by Utrecht JUG
5. 6
Mars
Climate
Orbiter
“The problem here was not the error; it was the
failure of NASA's systems engineering, and the
checks and balances in our processes, to detect
the error. That's why we lost the spacecraft.”
—Edward Weiler,
NASA associate administrator for space science,
IEEE Spectrum: Why the Mars Probe went off
course
6. Other Unit
Mishaps
7
● The 12 October 1492 “mishap”
● “Gimli Glider”, 1983
○ Air Canada Flight 143
○ Received less than half the fuel
needed
● Clarence the Tortoise, 2001
● A whole set of medication dose
errors
8. What Is the Fundamental Problem?
9
Primitive (Java) types
are primitive types
9. What Is the Fundamental Problem?
10
● Primitive (Java) types are primitive types
○ As in: building blocks to build other types
● Examples fundamentally in conflict with OOP and DDD:
○ static final double C = 1079252849;
○ static final double SPEED_OF_LIGHT = 1079252849;
○ static final double SPEED_OF_LIGHT_IN_KM_PER_H = 1079252849;
● What it should be:
○ static final Quantity<Speed> SPEED_OF_LIGHT
= Quantities.getQuantity(1079252849, Units.KILOMETRE_PER_HOUR);
10. Rolling Your Own Library
11
● A lot of work
○ Development
○ Maintenance
○ Upgrades and extensions
● Error-prone
● Are you a units of measurement domain expert?
○ Even of the units of measurement system you’re used to?
12. JSR 385: Units of Measurement API 2.0
13
Description:
This JSR is a major evolution of the Unit API 1.0 (JSR 363) specification.
Focused on the SI System redefinition, modularity and support for Java SE
8/9 and above.
JSR 363: Units of Measurement API
This JSR specifies Java packages for modeling and working with
measurement values, quantities and their corresponding units.
13. JSR 385 Basic Concepts
15
● Dimensions
● Units
● Quantities
● Prefixes
● Converters
● Formats
● System of units
15. Definition of a Physical Quantity
18
“A physical quantity is a physical property of a phenomenon, body, or
substance, that can be quantified by measurement.”
Source: Wikipedia
“A physical quantity can be expressed as the combination of a magnitude
expressed by a number – usually a real number – and a unit.”
Ibidem
31. Question: How Much is 0 °C + 0 °C?
● 0 °C
● 0 °C
● 273.15 °C
Two absolute temperatures:
0 °C + 0 °C = 273.15 K + 273.15 K
= 546.30 K
= 273.15 °C 36
32. Question: How Much is 0 °C + 0 °C?
● 0 °C
● 0 °C
● 273.15 °C
An absolute temperature and a temperature change:
0 °C + 0 °C = 273.15 K + 0 K
= 273.15 K
= 0 °C 37
33. Question: How Much is 0 °C + 0 °C?
● 0 °C
● 0 °C
● 273.15 °C
Two temperature changes:
0 °C + 0 °C = 0 K + 0 K
= 0 K
= 0 °C 38
34. Question: How Much is 0 °C + 0 °C?
273.15 °C (546.30 K)
0 °C + 0 °C = 0 °C (273.15 K)
0 °C (0 K)
39
37. Systems of Unit
47
● Metric system
○ Metre, kilogram, second, ampere, …
● Imperial system
○ Foot, ounce, pound, gallon, Fahrenheit, horsepower, …
● United States customary units
○ Foot, ounce, pound, gallon, Fahrenheit, horsepower, …
● Roman units of measurement
○ Pes, uncia, libra, …
● Norwegian units of measurement
○ Fot, favn, mål, tønne, snes, …
41. The Java Community Process
52
“The JCP gives you a chance to have your own work become an official
component of the Java platform and to offer suggestions for improving and
growing the technology. Either way, everyone in the Java community benefits
from your participation. That's one of the reasons the JCP is open to
everyone.”
Source: https://www.jcp.org/en/participation/overview
42. Becoming a JCP Member
53
“Membership in the JCP offers you a chance to become a permanent part of
the Java platform's history by contributing your work and recommendations to
the various standard specifications, and/or a chance of serving on the
Executive Committee.”
Source: https://www.jcp.org/en/participation/membership