From Traditional REXX to Object REXX

How was it possible to add object-orientation to traditional REXX while maintaining compatibility? The trick was in the handling of variables. In traditional (or "classic") REXX, all data was stored as strings. The strings represented character data as well as numeric data. From an object-oriented perspective, we might say that traditional REXX had one kind of objects: strings. In object-oriented terminology, each string variable was an object that was an instance of the String class.

We changed REXX so that variables could reference objects other than strings. In addition to a string class, REXX now includes classes for creating arrays, queues, streams, and many others useful objects. Objects in these new REXX classes are manipulated by methods instead of traditional functions. To activate a method, you just send the object a message.

For example, instead of using the SUBSTR function on a string variable Name, you send a SUBSTR message to the string object. Here is the old way:

s=substr(name,2,3)

And here is the new way:

s=name~substr(2,3)

The tilde (~) character is the REXX message send operator. We call it the twiddle. The object receiving the message is to the left of the twiddle. The message is to the right. In this example, the Name object is sent the SUBSTR message. The numbers in parentheses (2,3) are arguments sent as part of the message. The SUBSTR method is run for the Name object, and the result is assigned to the s string object.

For the new classes (array, queue, and so on), methods are provided, but not equivalent functions. For example, suppose you want to use the new REXX array object instead of the traditional string-based stem variables (such as text.1, text.2, and so on). To create an array object of five elements, you would send a NEW message to the array class as follows:

myarray=.array~new(5)

A new instance, named Myarray, of the Array class is created. (A period precedes a built-in class name in an expression, so .ARRAY is correct, not just ARRAY.) The Myarray array object has five elements. Some of the other methods, besides NEW, for array objects are PUT, AT, REMOVE, SIZE, [], and []=.

By adding object technology to its repertoire of traditional programming techniques, REXX has evolved into an object-oriented language, like Smalltalk. Object REXX accommodates the programming techniques of traditional REXX while adding new ones. With Object REXX, you can use the new technology as much or as little as you like, at whatever pace you like. You can use classic and object techniques together. You can ease into the object world gradually, building on the REXX skills and knowledge you already have.


[Back: A Classic Language Gets Classier]
[Next: The Object Advantage]