JVM Languages

NetRexx: The Original JVM Scripting Language Returns

By René Jansen, April 15, 2013

The first scripting language for the JVM was recently open-sourced by IBM. After a major update, it is once again finding its place by leveraging its unique benefits.

The point here is, we can stand on the shoulders of others. The more "componentized" these libraries are (for example, using JavaBeans signatures and events), the easier the use and integration is. On the subject of JavaBeans, the NetRexx properties indirect statement generates getter and setter methods for all these properties  something that Java developers depend on an IDE to generate or must write by hand. (While many NetRexx developers use editors, there is a NetRexx Eclipse mode that fills in the need for and IDE, and JEdit also has a very usable NetRexx mode.)

The clear separation between the language and library layers makes it possible to have a lot of options for user interface technology. All user interface technology that works with the JVM also works from NetRexx (including AWT, Swing, or JavaFX), as well as server-based technology (such as servlets, Struts, JSP, or JS)F. Some years ago, I even wrote a Web front-end with Flex with a Tomcat and NetRexx server back-end: Just think about the burning hoops you'd have to jump through to do that in another language.

Syntax

When looking at a NetRexx program, one of the most striking things is the lack of ceremony and punctuation. Its designer, Mike Cowlishaw, is a known opponent of superfluous punctuation. So the repetitive declaration style that plagues C, C++, Java, and JavaScript is absent from NetRexx. There are no curly braces, and semicolons are optional.

Intuitive constructs such as loop … end and select … when … otherwise … end require no explanation. In parameter declarations, the local variable comes first, followed by and equal sign and the type of the variable. When the equal sign and type are omitted, they are assumed to be type Rexx. A method declares a return type whenever it does not return Rexx. This makes for a very relaxed definition of methods. The equal sign can also be used to compare a variable to a type; once you are used to that, it is very natural and you just use it as you would in English.

Runtime: The Rexx Data Type

Type Rexx (Java integration is such that nothing precludes you from using this from a Java language program) is the historical Rexx invention of having one type for strings and arbitrary precision numbers. It resides in the runtime package netrexx.lang, which is automatically imported for every program so you don't have to think about it (although it requires explicit import if you're calling NetRexx from Java).

String comparison is caseless and humanized in the sense that leading and trailing spaces are ignored. If you want strict comparison, the == operator can be used: It is required if you want to write classes that are not dependent on the NetRexx runtime JAR.

New Features in Version 3.02

After JRE-only compilation was introduced in version 3.01 in 2012 (before that, NetRexx required a JDK for compilation), ease-of-use was addressed in version 3.02, which will be posted to netrexx.org around the time this article appears. New is the closer integration between the Rexx type and the Java Collections Framework.

Where we had to cast a lot in previous versions, and did not have a natural order for elements of type Rexx, these are now recognized and fitted for cast-less operation. We have gone from:

Here, the keys are automatically put in the order of the now built-in comparator, and variable r will be of type Rexx. So, when getting elements out of the collection, no cast to Rexx is necessary.

This is generic handling without the syntax. All Rexx type container facilities (the associative "indexed strings" functionality) is usable from the elements in a collection, as are the NetRexx string methods.

Also, to ease integration in products that need on-the-fly compilation or interpretation of a string of code, an API was added to the existing, file-based compiler API. It enables program execution of a string containing the source, as in:

Also, the Rexx type can now be subclassed, a long-standing wish of our user base.

Code Examples

NetRexx is written entirely in NetRexx. Other examples can be found at rosettacode.org, which catalogs various algorithms and puzzles with equivalent implementations written in numerous languages. The examples are also included in the NetRexx distribution, as are others that show nearly every aspect of the use of NetRexx in application software, including all the IBM NetRexx Redbook example code. I expect these examples will convince you that NetRexx is one of the most original and productive alternatives to Java on the JVM.

René Vincent Jansen is the current president of the Rexx Language Association; he was a systems programmer for decades and now manages technical teams in infrastructure and application projects. He likes everything that just works.

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task.
However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Video

This month's Dr. Dobb's Journal

This month,
Dr. Dobb's Journal is devoted to mobile programming. We introduce you to Apple's new Swift programming language, discuss the perils of being the third-most-popular mobile platform, revisit SQLite on Android
, and much more!