Type Safe Units of Temperature

  • Thread starter Thread starter Jeff Louie
  • Start date Start date
Jeff said:
Here is a type safe unit of temperature that can be used to enforce type
safety at compile time.

http://www.geocities.com/jeff_louie/OOP/oop38.htm

In terms of efficacy do you think it is better to spend additional
coding time using type safe classes such as this or do you think it
better to spend the extra time giving clear specs and coding rules and
doing more tests.

To my mind what was needed was a clear communication that all
measurements should be performed in metric.

I have worked on a few projects that have spent far to much effort
designing mechanisms to get a round project management failures.
 
Hi Nick... A type safe unit library certainly does not replace
documentation and design requirements. But "to err is human" so IMHO
system solutions are a worthy goal. C# is type safe so we are all
_currently_ coding using type safety such as double or decimal or int. I
see no extra effort necessary to code using Meter, Grams and Celsius. In
fact, coding using Meter, Grams and Celsius is self documenting and
moves us toward the goal of self documenting code.

Regards,
Jeff
 
Jeff said:
Hi Nick... A type safe unit library certainly does not replace
documentation and design requirements. But "to err is human" so IMHO
system solutions are a worthy goal. C# is type safe so we are all
_currently_ coding using type safety such as double or decimal or int. I
see no extra effort necessary to code using Meter, Grams and Celsius. In
fact, coding using Meter, Grams and Celsius is self documenting and
moves us toward the goal of self documenting code.

It definitely would be more effort to use temperature classes.

It is often much harder to understand a project which uses a number of
new Types to wrap normal more familiar type. Rather than follow the flow
of the code you need to take time out to investigate and understand the
new type. If you are putin a seat and asked to make a change to a
unknown large project the last thing you want is unnecessary complexity.


In this case it is also a bit heavy to have multiple classes why not
have one class which can be converted/from displayed as any of the other
temperature types. The four temperature types are equivalent the only
difference being the formatting and conversion from/to a double.
Redefining the FREEZE_H2O constants for each type is also a recipe for
disaster and may lead to inconsistency. A similar concept occurs with
DateTime where a locale is used to determine how UCT is displayed.


It may be that you have a project where the benefits of some kind of
type safety outweigh the drawbacks but I doubt it.

The SI unit of temperature is Kelvin I would need tremendously strong
reasons to allow anything else to be used.
 
Back
Top