5 ms·
>This tool is underrated. Failing to deal with units conversion already crashed a Mars probe The mistake there was that they were unaware that they had to make
by krger 3y ago
>This tool is underrated. Failing to deal with units conversion already crashed a Mars probe
The mistake there was that they were unaware that they had to make the unit conversion, not that they did it wrong.
No tool can, by itself, overcome your ignorance of its necessity.
- nequo 3y ago> No tool can, by itself, overcome your ignorance of its necessity. A type system that understands units of measurement can help: https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/units-of-measure https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
- klausa 3y agoThat still requires you to know about its existence. It's perfectly possible to write F# code without those and messing up units conversion.
- nequo 3y agoSomeone on the team needs to know about it. That person needs to set up the API to expect properly typed inputs. Others can remain ignorant about units of measurement and the compiler will educate them. F# has this built in but it can be achieved with libraries in some other languages. For example, in Haskell with the dimensional package[1]: import Numeric.Units.Dimensional.Prelude import Numeric.Units.Dimensional.NonSI (mile) speedLimit :: Velocity Double speedLimit = 30 *~ (mile / hour) main :: IO () main = do let speed1 = 35 *~ (kilo meter / hour) let speed2 = 35 *~ (mile / hour) let speed3 = 35 print (speed1 <= speedLimit) print (speed2 <= speedLimit) print (speed3 <= speedLimit) GHC will give you an error because `speed3` is mistyped. [1] https://hackage.haskell.org/package/dimensional https://hackage.haskell.org/package/dimensional
- midoridensha 3y agoYou're not getting it. The Mars probe didn't crash because of bad unit conversion. It crashed because there were no units in the data!!! Go read about it yourself. NASA got some data from a contractor. The data had no units at all. The contractor assumed the data to be in some kind of US-standard units. NASA got these raw numbers and assumed they were in some kind of SI units. Having enforced units in your language isn't going to help in this situation at all. They weren't exchanging code, they were exchanging raw data, or more specifically, a table with a bunch of numbers on it. The people at NASA simply assumed some units (instead of calling the contractor and asking), and they would have done this in your scenario too.
- Qem 3y ago> The mistake there was that they were unaware that they had to make the unit conversion, not that they did it wrong. I think the root cause here was continued use of medieval units, instead of just standardizing on the metric system as it's already done around nearly the entire world.
- fest 3y agoEven if it was all metric, in embedded systems you often have to deal with the same measurements in different units, like angles in radians, degrees, centidegrees, length in mm, m, cm, due to various reasons (mostly historical, like integer math being faster than floating point math). It is getting less frequent in modern code bases that target 32-bit MCUs with hardware-floating point support, but converting large codebases
- gumby 3y ago> Even if it was all metric, in embedded systems you often have to deal with the same measurements in different units, like angles in radians, degrees, centidegrees, length in mm, m, cm, due to various reasons (mostly historical, like integer math being faster than floating point math). It’s also cultural - different fields use different SI units for historical or practical reasons. My second year at MIT I was in a program (16.001 & 2) that had different classes using cgs, mks, and mills. They all met in the same classroom (different times of course!), so there was no spacial reminder. But we all survived.
- deleted 3y ago[deleted]
- extraduder_ire 3y agoHave you ever accidentally set your calculator to gradians? We were warned about it when doing trigonometry in school, the first time we had to go between degrees and radians.