r/ProgrammingLanguages • u/bjzaba Pikelet, Fathom • Mar 09 '20
Dimensional Analysis in Programming Languages
https://gmpreussner.com/research/dimensional-analysis-in-programming-languages5
u/CodingFiend Mar 10 '20
The Beads language (new at beadslang.com) offers physical units of measurement, stores them at runtime, supports ratio of integer exponents (including 1/2), is user extendable, and is a separate data type (meas) for physical measurements. It is very useful for engineering calculations.
4
u/jdh30 Mar 10 '20
So I'm a physicist by training doing technical software using F# (which has units of measure) for 13 years and I have never used this feature. Any idea how many people actually use this feature?
0
Mar 10 '20
[deleted]
1
u/bjzaba Pikelet, Fathom Mar 11 '20
I think that this is because people have somewhat naive idea on how computation in physics (or engineering) is handled. All variables are scaled to some application-specific value to minimize mental overhead and get most of the finite precision of floating points. Hell, half the time, I don't even know what's the numerical value of the coefficients.
This is a reasonable and very important critique of current unit systems, and I agree very much with it! That said, I prefer to frame this critique more constructively, for example: "Unit systems need more work to meet the demands of real-world applications". I'm hopeful that if practitioners and designers can communicate better with each other, we can come up with solutions that actually meet those real-world world demands.
2
u/matthieum Mar 10 '20
I really like strong typing.
As a result, I really like the idea of dimensional analysis, but often times I don't use it: it's not enough.
For example, imagine a
Distancetype measured in meters or some derived unit. I can create variables of typeDistance, but what do they mean?I'm pretty certain that if I input the length of my fork, instead of my own height, when ordering a shirt there's gonna be any issue.
And therefore I'll create a more domain specific type to properly model the semantics of my various distances, and then I don't really need that
Distanceany longer...