DEV Community

Aniket Kadam
Aniket Kadam

Posted on • Originally published at Medium on

Are you using seconds or milliseconds? Don’t lose a Mars orbiter over it!

If you need an object that includes time, you’re probably going to need to convert it. Unit conversion is the cause of many bugs, some more disastrous than others.

When designing software, always make the right thing easy and the wrong thing hard.

(CNN) — NASA lost a $125 million Mars orbiter because a Lockheed Martin engineering team used English units of measurement while the agency’s team used the more conventional metric system for a key spacecraft operation

What if you never had to bother about which one it was and would get it right 100% of the time no matter if you needed milliseconds or hours?

Here’s how.

Let’s presume you’re measuring exercise duration.

What you get from using this pattern is, it’s impossible to mess up saving or getting information from that object.

It doesn’t matter what internal representation you choose. You’ll never go wrong in either setting or getting time out because you choose a unit each time you actually need it.

You’ll never go wrong in either setting or getting time out because you choose a unit each time you actually need it.

Caution Points

Ask me questions on Twitter or comment below!

Top comments (1)

Collapse
 
nektro profile image
Meghan (she/her)

Lockheed Martin should be sued for negligence. If you work in science, you never don’t work in metric. Accident is 100% their fault.