|
SYS-CON.TV Webcasts
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Top Links You Must Click On
General Java Dimensioned Numbers In Java
Dimensioned Numbers In Java
By: Andre Van Delft
Jan. 1, 1996 12:00 AM
Introduction 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
For each of these dimensions we can define a primary unit:
The dimension...unit... construct covers these base dimensions: Internal machine representations of dimensioned variables are relative to the base units.
Derived Dimensions
The dimension...m - =... construct covers these derived dimensions:
Derived Units
The final keyword is not needed:
Dimensioned Numbers These examples would produce a compile error, as seen in Listing 2.
Physics Package As shown in the physics package, dimensions can be derived from other dimensions and constants could be provided for common physics values.
Finance Package 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 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
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: 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
double len = 1.5*kilometer; 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. Reader Feedback: Page 1 of 1
Enterprise Open Source Magazine Latest Stories . . .
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||