From Traditional Rexx to Open Object Rexx

In traditional (classic) Rexx, all data was stored as strings. The strings represented character data as well as numeric data. From an object-oriented perspective, traditional Rexx had just one kind of object: the string. In object-oriented terminology, each string variable is an object that is a reference to an instance of the String class.

With ooRexx, variables can now reference objects other than strings. In addition to the String class, Rexx includes classes for creating arrays, queues, streams, and many other useful objects. Additionally, you can create your own classes that can interoperate seamlessly with the language built-in classes. Objects in these Rexx classes are manipulated by methods instead of traditional functions. To activate a method, you just send a message to the object.

For example, instead of using the SUBSTR function on a string variable Name, you send a SUBSTR message to the string object. In classic Rexx, you would do the following:

s=substr(name,2,3)

In Open Object Rexx, the equivalent would be:

s=name~substr(2,3)

The tilde ( ~) character is the Rexx message send operator, called twiddle. The object receiving the message is to the left of the twiddle. The message sent 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. Conceptually, you are "asking" the String object referred to by variable NAME to give you its substring starting at character 2 for 3 characters. Many String operations are available as both class methods and built-in functions, but the String class also provides many method enhancements for which there are no corresponding built-in functions.

For classes other than String (such as Array or Queue), methods are provided, but not equivalent built-in functions. For example, suppose you want to use a Rexx Array object instead of the traditional string-based stem variables (such as text.1 or text.2). 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 of the Array class is created and reference to it is stored in the variable myarray. A period and the class name identify the class, .Array. The period tells the interpreter to look in the Rexx environment for a class named "ARRAY". The myarray Array object has five elements, but the array itself is currently empty. Items can be added using methods defined by the Array class.

myarray[1] = "Rick"
myarray[2] = "David"
myarray[3] = "Mark"
say myarray[1] myarray[2] myarray[3]

The Array class implements many more methods. See the ooRexx reference for details on what additional methods are provided.

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