Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News

SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Dimensioned Numbers In Java
Dimensioned Numbers In Java

Introduction
Computing in scientific and engineering areas often deals with manipulating numbers that represent physical entities, such as durations, weights, and forces. A common source of errors in scientific computing involves processing numbers that represent different kinds of entities, or that are related to different units, and utilizing the result for additional computation. A number is referred to as dimensioned when it relates to a specific entity such as distance, time, or temperature, and the number implies a particular unit of measure. A dimensionless number, also known as a nondimensional parameter, is a ratio of physical properties and conditions of such a nature that the resulting number has no defining unit of weight, duration, and so on.

There have been several attempts to add support for handling dimensioned numbers to programming languages. The goal was to ease programming and to make it less error prone. The concerns of scientists and engineers have apparently not been noticed by programming language developers, since we don't see support for dimensioned numbers built in to many programming languages. This is unfortunate not only for scientific computing, but also for object-oriented business and financial programming, which could also benefit from compiler and language-level dimensioned number support.

This article presents a simple proposal for supporting dimensioned numbers in Java. Application development using Java in scientific and engineering environments is not yet in the spotlight, since performance is still lagging behind other languages (Fortran, C, C++, Pascal) by an order of magnitude. This situation will improve within the next few years and Java's excellent power-complexity ratio gives it the potential to soon rank as language number one in scientific and engineering areas.

The proposed language extension involves two new keywords (dimension and unit), and an extension to the syntax of numeric types. It prevents mangling different kinds of physical entities, and it takes care of unit conversion. Conversion from and to scalar (plain numeric) values is only possible by specifying applicable units.

The extension mainly performs dimension checking at compile time; its only run-time involvement deals with unit conversion, as far as non-basic units are used. The proposal consists of four categories of language extensions, and two keywords. It uses Java support for packages. It does not use object-oriented features.

Even though Java currently lacks support for dimensioned numbers, you can already adopt a convenient programming style for dealing with units, as outlined at the end of this paper.

Base Dimensions
Some dimensions are more basic than others. There are five base dimensions in physics (that I recall):

  • distance
  • time
  • mass
  • temperature
  • electric charge

    For each of these dimensions we can define a primary unit:

  • meter
  • second
  • kilogram
  • Kelvin
  • Coulomb

    The dimension...unit... construct covers these base dimensions:
    dimension time - unit second;
    dimension distance - unit meter;
    dimension mass - unit kilogram;
    dimension temperature - unit Kelvin;
    dimension electricCharge - unit Coulomb;

    Internal machine representations of dimensioned variables are relative to the base units.

    Derived Dimensions
    Using the base dimensions, others may be expressed through multiplication and division, e.g.,

  • speed equals distance divided by time
  • acceleration equals speed divided by time
  • impulse equals mass times speed
  • force equals mass times acceleration

    The dimension...m - =... construct covers these derived dimensions:
    dimension speed - = distance - / time;
    dimension acceleration - = speed - / time;
    dimension impulse - = mass - * speed;
    dimension force - = mass - * acceleration;

    Derived Units
    Units are final variables of dimension types. The ones that are not defined with the base dimensions are derived. Their definition may suggest internal representation like integers, floats or doubles, but the actual representation is adapted at compile time to the highest precision applicable in the context.

    The final keyword is not needed:
    mass - gram - = kilogram / 1000;
    distance - kilometer - = 1000 * meter;
    time - minute - = 60 * seconds;
    time - hour - = 60 * minute;
    time - day - = 24 * hour;

    Dimensioned Numbers
    The actual usage of dimensions is in dimensioned numbers. These have a type made up of a numeric type (int, float, ...) and a dimension. Actual values are made up of a combination of numeric values (0, 1, 0.1, ...) and units. As with dimensions and units, multiplication and division on dimensioned numbers yield dimensioned numbers of possibly different dimensions. The examples in Listing 1 would be accepted by the compiler.

    These examples would produce a compile error, as seen in Listing 2.

    Physics Package
    The sample package in Listing 3 illustrates how a physics package might look once the dimension and unit keywords are added to Java.

    As shown in the physics package, dimensions can be derived from other dimensions and constants could be provided for common physics values.

    Finance Package
    A finance package would also be an interesting way to take advantage of dimensioned number support in Java. See Listing 4 for an example.

    The sample finance package shown brings up an interesting aspect of dimensioned number support in a programming language: that of non-constant units that are derived from variable dimensioned numbers.

    Computing Packages
    A computing package might also be of value. Such a package could greatly simplify the process of building and debugging applications which require reliable calculation of memory or disk space quantities or conversions between computer-oriented units of measure. Listing 5 shows such a package.

    Other dimensions and units would also apply in the computing package, such as CPU clock speed, system and network traffic load, or end-user frustration levels, as they wait for Java applets to execute within Netscape Navigator 2.0.

    Implementation
    Java compilers may adopt the proposed extension without major difficulty (if you disagree with this proposition, send me e-mail). However, full support will require a modification of the .class file format for the dimensioned numeric data types. This would call for a synchronized operation by all Java compiler builders and users. That can only be justified if the proposed extension has proved to be worthwhile to enough Java developers (and if Sun agrees).

    Therefore experiments are needed; the proof of the pudding is in the eating. We need to try out the extension, using preliminary support by compilers and preprocessors, that does not require changes to the class format. This support would be possible in the following way:

  • the original package files are named physics.dim instead of physics.java, etc
  • the compiler or preprocessor gets a command line hint to use the appropriate .dim files, e.g., guavac -d physics.dim - d finance.dim
  • files physics.java etc. are derived from the .dim files by only selecting the constant definitions; these become all double scalars

    An example for new physics.java is shown in Listing 6.

    Who is going to implement these ideas? At least for the time being, not me. I am extremely busy with other projects, e.g., see http://www.delftware.nl/scriptic/. So if you are a compiler builder, or if you want to contribute to a GNU Java compiler, please go ahead and let me know.

    Emulating Units in Java Today
    While no compiler support is available today for dimensions and units in Java, you may use the previous physics.java file to deal with physical units in your code now. Just forget about the double*length syntax etc, but write things like the following:

    double len = 1.5*kilometer;
    double t = 8.3*minute;
    System.out.println("Speed: " + ( (len/t) / (meter/second) ) +
    " m/s");

    This working style doesn't give you the full benefits of dimensional checking, but at least it will make your code more readable, and you will have less worry about units.

    About Andre Van Delft
    'Andre van Delft studied Mathematics and Business Administration in Holland. Then he joined the Department of Computer Science at Leiden University for four years. From 1989 on he has worked in Delftware Technology as consultant and software developer. His topics of interest are software engineering, reliability and parallel programming.

  • In order to post a comment you need to be registered and logged in.

    Register | Sign-in

    Reader Feedback: Page 1 of 1

    Latest Cloud Developer Stories
    Rackspace Hosting, the service leader in cloud computing, on Thursday announced its acquisition of SharePoint911, an industry leader in SharePoint consulting, training, and "JumpStart" services within SharePoint. The unification of both companies provides capabilities to deliver ...
    With Cloud Expo 2012 New York (10th Cloud Expo) now under four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have techn...
    Nimble, the social CRM platform has announced the launch of Nimble 2.0, billed as the “most social” CRM platform on the market today. Nimble was designed entirely with social CRM in mind and is the first social business platform that empowers companies with the ability to get clo...
    2011 was a year of rapid adoption for public and private cloud services. Instant and on-demand server provisioning was the driving force behind the massive growth. On top, cloud server templates and script automation simplified application installation for simple and pre-defined ...
    "Having been in the IT field for many years, I believe the cloud computing chapter in the industry is an exciting one and I am proud to be a part of it," said National Reconaissance Office (NRO) Chief Information Officer Jill T. Singer Tuesday, as it was announced that she was on...
    Subscribe to the World's Most Powerful Newsletters
    Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON Featured Whitepapers
    ADS BY GOOGLE