INTRODUCTION:  This 3-part article is by Michael F. Cowlishaw, the creator of the REXX language, and author of two books ("The REXX Language", and "The NetREXX Language").  The article was first published in the "Java Report", June 1997 (pp 45-48), and is reprinted here with permission from Dwight Duego (Editor-in-Chief of "Java Report").

NetRexx -- easier Java programming


The great strength of Java is the Java Virtual Machine and class libraries, which together form a programmable environment that is available on a wide variety of computers.  The Java programming language is one way of creating programs and classes for that environment -- but it is not necessarily the only way.  Just as different artists prefer different tools and techniques, so different programming languages suit different programmers.

NetRexx is a new programming language that is designed specifically to make it easier for programmers to take advantage of the Java environment, without losing any of the capabilities offered by the Java language.  The productivity gains of using NetRexx are available to anyone currently programming in Java, and the ease-of-use of NetRexx will encourage more new users to exploit the advantages of the Java environment.

Java with 'automatic transmission'

The data values in Java objects are all ultimately derived from a handful of primitive types: byte, char, int, float, and so on.  Writing a method or class in Java almost always involves making decisions about which of these types to use for values, and a strength of Java is the ability to fine-tune the performance or space requirements of an application by careful choice among these types.  Rather like an automobile, you can adjust your use of these types to gear the Java Virtual Machine to best match your algorithms.

User-oriented programming languages offer a different strength: by unifying the primitives into a minimum of types and automating the use of the types provided by the underlying hardware, they greatly simplify programming.  NetRexx is just such a language, purpose-built for programming the Java Virtual Machine.  It makes sensible automatic choices for you -- so greatly lessening the more tedious aspects of programming for Java.

There's a twist though: in NetRexx, with the flick of a (virtual) switch, you can engage 'manual transmission', and have the same detailed control over the primitive types as you do in Java.

What's the point?

In a word: productivity.  NetRexx is one of the Rexx family of languages, which all follow a unifying philosophy: the design of the language should make programming easier -- the language should be tuned to the background and expectations of the people using the language. When programming is made as simple and enjoyable as possible, programs can be written more quickly (and may well be more reliable and maintainable, too).

Automatic handling of numbers, strings, and primitive types is the most obvious way in which NetRexx speeds up programming for Java, but there are a number of others; I'll introduce more of them later in this article.  But first, a word on how and why you might use NetRexx.

NetRexx has the feel of a scripting language, but is designed so that anything you can do in Java can be done using NetRexx.  You can use any Java classes from NetRexx, and any class written in NetRexx can be used from Java.  The reference implementation of NetRexx in fact uses a Java compiler 'under the covers' to generate its .class files, so ensuring compatibility.

NetRexx, however, isn't intended to replace Java, but rather to complement it.  Many programmers, especially those primarily educated in the C style of programming, find Java a good match to their expectations.  Others, who have experience of the flexibility and productivity of more dynamic languages, will find NetRexx a more approachable tool.  It's important that there be a choice, because when you use a language that suits you, you can concentrate on the problem to be solved and not be distracted by the mechanics.

An example

Here is a working example of a NetRexx class that implements a simple applet:

  /* Rainbow.nrx -- a simple graphics Applet */
  class Rainbow extends Applet
    method paint(g=Graphics)
      maxx=size.width-1
      maxy=size.height-1
      loop y=0 to maxy
        col=Color.getHSBcolor(y/maxy, 1, 1)
        g.setColor(col)
        g.drawRect(0, y, maxx, y)
      end

This class, entered in a file called Rainbow.nrx, can be compiled by the NetRexx compiler.  The resulting Rainbow.class is then used exactly like an applet compiled from Java. 

Mike Cowlishaw
IBM Fellow
mfc@uk.ibm.com


Part two of this article will be published in the next issue of the RexxLA Newsletter.