[PATCH] Amend divetrip model to use int units

Linus Torvalds torvalds at linux-foundation.org
Wed Apr 24 10:43:01 PDT 2013


On Wed, Apr 24, 2013 at 8:57 AM,  <amit.k.chaudhuri at gmail.com> wrote:
>
> Amend the DiveItem class to avoid float in favour of int

No. Don't do this. "int" is better than "float", but it's still bad,
because there is no unit, and there is no type safety.

There's a really good reason why we do *not* write

   int depth;

but instead write

   depth_t depth;

and that is very important. The "depth_t" is typesafe (you can't
mistakenly switch the order of a depth_t and a duration_t, even if
they end up both having integral values), and "depth_t" has a *unit*,
namely "mm". There is never any question about what "depth_t depth"
means, unlike "int depth".

We've used these types since very early on, and they've helped avoid
unit issues etc. When you have to use "temp.mkelvin" to actually look
at a temperature value, there's never any confusion about whether the
values might have been converted to Celsius or Fahrenheit or whatever
for display. Because our variables have *units*.

                      Linus


More information about the subsurface mailing list