News for hackers. Stuff that matters.
Re:A Dangerous Obsession with Primitives by timmaxw on Thursday May 31, 2012 @04:19PM (#4050124)
* Dividing or multiplying a fahrenheit temperature is meaningless, because 0ºF is arbitrary.

* Ideally, you want separate types for absolute temperatures and temperature-deltas. Absolutes cannot be added, multiplied, or divided; subtracting absolutes produces a delta; adding or subtracting an absolute from a delta produces an absolute; deltas can be added and subtracted, and multiplied by unitless values.

* Multiplying a MeterNum by a MeterNum would ideally produce a SquareMeterNum.

* If you don't have to worry about precision, MeterNum and FootNum should both be replaced by LengthNum.

* You can convert a LengthNum into, say, meters by dividing by whatever value represents "1 meter" to produce a unitless int.

* Often operators don't make sense at all. (a << b) only makes sense if b is a unitless integer, for example.

I implemented most of this (but not absolute temperatures) as a Python library. The source is at <http://timmaxwell.org/svn/src/pychem/units.py>; and <http://timmaxwell.org/svn/src/pychem/std_units.py>. (Warning: these will download rather than opening in the browser.) I also found this: <http://pypi.python.org/pypi/units/>.

There are no comments on this comment yet.