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!

原文链接:Are you using seconds or milliseconds? Don’t lose a Mars orbiter over it!

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容