Hacker News new | ask | show | jobs
by ADRIANFR 4074 days ago
Also, 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
1 comments

If you want to find the periphery of something you DO want to add length to width...
No, 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.

Or 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.