Ed de Moel

WindMills

M Computing, Volume 6, number 4, October 1998, pages 14-15

Implicit bindings and conversions?
by Ed de Moel

One of the articles in this issue presents an interesting idea: using the programming environment to convert values in related "units" automatically to our personally preferred unit. In our various "locales" we all use our own favorite units (Europeans like to weigh things in kilograms, Americans prefer to weigh in pounds, etcetera). When we interact with one another, we prefer not to be bothered with such details, and would like to express entities in "standard" units.

Well... what is the standard? In most European countries, the national standard is the kilogram, and in the USA, the national standard is pounds and ounces... And in some cases, the local favorite may be one that everybody uses, but that just happens to be different from the official standard.

The sequence of instructions:

        Set Weight1=...
        Set Weight2=...
        If Weight1>Weight2 ...

seems straightforward enough, and if we would be able to define Weight1 as "1.01kg" and Weight2 as "2.3pound", that would indeed be extremely nice. But, what would the outcome of this comparison be?

An American pound is 0.3732 kilograms, so the comparison would be "true". A British pound is 0.4536 kilograms, which would make the comparison "false", and a German pound is 0.5 kilograms, which would also make the comparison "false".

An obvious solution to this problem is to add an explicit list of names for units to the standard, which will make it clear which name refers to which version of which unit (we would probably see abbreviations like lbUK, lbUS and lbGer).

That sounds straightforward enough, but, so far, the MDC has attempted to "bind" only to other official standards. This means that units like "British pound" and "American pound" would probably find their way into such a list, but a unit like "German pound" would not, because it was officially abandoned quite a while ago.

Now, how would my mother deal with such a scheme? Even though the Dutch pound was officially abandoned 30 years before she was born, she still asks for any weight in kilograms: "How many pounds is that?" Indeed, old habits die hard...

So, if we want to use an "implicit conversion algorithm" as an extension to our programming language, and we want to be user friendly, we will probably have to maintain a list of "locally preferred units" in addition to the list of official standards that we might bind to.

When?

The first question everyone always asks when a new idea pops up is: "When will we be able to use this?"

In this case, the answer may be a surprise: for any environment where a database management system is being used that checks values before they are entered into a database, or when values are compared to values in the database, the answer is "right now!".

Just add a call to an extrinsic function or subroutine to both the input transformation and the output transformation, and presto! The input transformation would scan the input value for the occurrence of a unit, append a "default" unit when none is present, and then convert the value to the unit that is used internally in the database. The output transformation would convert the value to the unit that is desirable for output purposes. It would be up to the preferences for the application whether the output transformation would append a visible representation of the name of the unit to the produced value.

And later?

In the future, a lot more interesting options are likely to become available.

Suppose that we have an object that describes a person, then we could have the method that defines the value of the property "weight" do the "input" validation and conversion implicitly, and the methods that fetch the values of the various properties could perform the output transformations implicitly. In other words:

Assume that Person is an object describing a patient

Set Person.Weight=...

would implicitly check the value on the right hand side of the equal sign, and convert the value to an internal convention.

There could be a public method that defines a default unit, to be used when a value is entered without an explicitly specified unit.

If Person.Weight>Norm

would invoke the method that obtains the value of the property "Weight", which would implicitly convert the internal value to the units that the application expects for its calculations.

There could be a public method that has a parameter that decides whether or not the name of a unit is presented in the "output" value, and whether this name will be an abbreviated form (lb or kg) or fully spelled (pounds or kilograms).

How long before we can really do this? Well, stay tuned. Objects in M[UMPS] are closer than they appear!


Jacquard Systems ResearchEd de Moel is past chairman of the MDC and works with Jacquard Systems Research. His experience includes developing software for research in medicine and physics. Over the past ten years, Ed's has mostly focused on the production of tools for data management and analysis, and tools for the support of day-to-day operation of medical systems. Ed can be reached by e-mail.