9 ms·
People keep talking about "you don't want to add meters to feet", but that's exactly the opposite of what you want to do. You want to add inches to yards or fur
by moron4hire 12y ago
People keep talking about "you don't want to add meters to feet", but that's exactly the opposite of what you want to do. You want to add inches to yards or furlongs or flea wings, and you want to get it right.
What you don't want to do is add length to weight. The true type of your value is not inches, it's length, and expressing it in inches is a formatting issue.
- ADRIANFR 12y agoAlso, ideally, you don't want to add length to width, or Hertz to Becquerel (both have [1/sec] unit). This was my humble attempt to address this with a Scala Units library: https://github.com/adrianfr/scalau https://github.com/adrianfr/scalau
- coldtea 12y agoIf you want to find the periphery of something you DO want to add length to width...
- Someone 12y agoNo, you add the lengths of the sides. That's type-safe and generalizes from rectangles with edges parallel to the x and y axes to general polygons: perimeter = poly.edges.map(length).sum() Height and width have (implicit) direction; length doesn't. But yes, this will get hairy. For convenience, you want the ability to add heights, but that only makes sense in some cases. Two 100m high skyscrapers only make a 200m high skyscraper if you place one on top of the other.
- marvy 12y agoOr maybe you want to find the height of an average skyscraper so you want to add and then divide. This is going too far maybe. At some point, one has to accept that not all logic bugs are type errors, and not all type errors are common enough in practice to worry about. I have no idea where that point is, but I'm sure it exists.
- ndr 12y agoYou might be interested in http://www.wolfram.com/mathematica/new-in-9/units/ http://www.wolfram.com/mathematica/new-in-9/units/ - Wolfram's take on units.
- dllthomas 12y agoWhen people say "you don't want to add meters to feet" it's a short-hand for "you don't want to add [a primitive data type representing] meters to [a primitive data type representing] feet [thereby getting a nonsensical result]." Whether "inches" is the "true type" of my value depends on the context - what invariants am I trying to enforce by giving it that type?