Object-oriented units of measurement

  • Authors:
  • Eric Allen;David Chase;Victor Luchangco;Jan-Willem Maessen;Guy L. Steele, Jr.

  • Affiliations:
  • Sun Microsystems Laboratories, Burlington, MA;Sun Microsystems Laboratories, Burlington, MA;Sun Microsystems Laboratories, Burlington, MA;Sun Microsystems Laboratories, Burlington, MA;Sun Microsystems Laboratories, Burlington, MA

  • Venue:
  • OOPSLA '04 Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications
  • Year:
  • 2004

Quantified Score

Hi-index 0.00

Visualization

Abstract

Programs that manipulate physical quantities typically represent these quantities as raw numbers corresponding to the quantities' measurements in particular units (e.g., a length represented as a number of meters). This approach eliminates the possibility of catching errors resulting from adding or comparing quantities expressed in different units (as in the Mars Climate Orbiter error [11]), and does not support the safe comparison and addition of quantities of the same dimension. We show how to formulate dimensions and units as classes in a nominally typed object-oriented language through the use of statically typed metaclasses. Our formulation allows both parametric and inheritance poly-morphism with respect to both dimension and unit types. It also allows for integration of encapsulated measurement systems, dynamic conversion factors, declarations of scales (including nonlinear scales) with defined zeros, and nonconstant exponents on dimension types. We also show how to encapsulate most of the "magic machinery" that handles the algebraic nature of dimensions and units in a single meta-class that allows us to treat select static types as generators of a free abelian group.