logo

 

     
 
Home
Site Map
Search
 
:: Bitwise Courses ::
 
Bitwise Dusty Archives
 
 
 

rss

 
 

ruby in steel

learn aikido in north devon

Learn Aikido in North Devon

 


Section :: programming
- Format For Printing...

Rexx World

Power plus simplicity - is Rexx the programming language you’ve been searching for?
Monday 8 January 2007.
 

There are millions of free and open source languages, tools, and development accessories out there. How do you find the right ones for your work?

I’d like to introduce you to a world of related languages and tools with which you may not be familiar. All relate to Rexx, a free scripting language used worldwide, that offers 9 free interpreters and thousands of add-on tools that run on every platform, from handheld devices to mainframes (and everything in-between). This brief article tells you everything you need to know—

The defining characteristic of Rexx is that it combines ease of use with power. This is a neat trick – normally these traits conflict. How does Rexx pull it off? Rexx has—

- Minimal syntax
- Consistent, reliable behavior based on a minimum of rules
- Features are based on linguistic flexibility — rather than identifying syntax
- A small instruction set with functions and objects providing power
- Extensibility
- Free format
- Strong language standards

I do most my scripting in either Perl, the Korn shell, or Rexx. Each has its own unique personality and advantages.

I choose Korn when I need a standard shell language for coding on Unix systems in IT shops. I like Perl for the unparalleled size of its free code library, its power, and its portability.

I pick Rexx when I want a language that I can—

- Code from memory, without looking up complicated syntax
- Know will produce code that can be maintained
- Ensure my programs outlive my presence at the client
- Develop large systems with quickly – with a minimum of errors

This last point bears amplification. When I tell high-end developers that Rexx is powerful yet easy, they sometimes recoil in horror – why would a top-notch developer ever use an easy language? (What an insult!)

Here’s why – you can write a ton of code very quickly. You are freed from the shackles of syntax, so this code requires minimal debugging. And here’s the coup de grace – this code will be highly reliable.

If you consider yourself a “real” coder, writing large commercial systems, there’s much to be said for the so-called easy languages like Rexx. You can write big complex systems, fast and reliably, and this code can be understood and maintained by those who follow in your footsteps.

Varieties of Rexx

Like many languages, Rexx started life as a procedural language. Traditional or classic Rexx today runs on every platform, from handheld devices, to PCs, servers, and mainframes. Six classic free interpreters are available. All conform to the Rexx standards, which are strong and guarantee portability.

The availability of different interpreters means you can choose which is most appropriate to your task – the fastest one, the one tweaked and extended for Windows, the one bundled with your favorite tools, the one with the smallest footprint, or whatever. This presents a big advantage compared to scripting languages that offer only a single source. Choice is good! But like all benefits, this one comes with a cost — not every one of the thousands of free Rexx tools interfaces with every interpreter.

Beyond classic procedural Rexx, there are two fully object-oriented versions of the language. Open Object Rexx was originally developed at IBM. It was open-sourced in December 2004 and handed over to the Rexx Language Association for support and further development. Often called ooRexx, this interpreter is a huge hit. In 2006 it ranked among the top 5 % of all downloads on SourceForge.

ooRexx has the full set of features you would expect in a good object-oriented interpreter - single and multiple inheritance, operator overloading and polymorphism, data encapsulation, messaging, classes, objects, and a huge hammer of a class library. Take a look at the class library in this reference card (pdf).

The other free object-oriented Rexx is roo!. roo! is also fully object-oriented but features completely different OO syntax and classes. I’ve found it particular useful in education, based on its friendly, fun documentation and free tutorial.

Both ooRexx and roo! are true supersets of classic Rexx. Any procedural Rexx program runs under either without alteration. This is a big benefit for sites upgrading procedural code to object-oriented, and for individual programmers who are learning OO programming (just code procedural Rexx and add object-oriented features at the rate at which you feel comfortable).

As I write this column, ooRexx’s SourceForge Activity Rating is 99.53% and its Download Rank is 835. Quite an accomplishment on a site that features 137,389 projects. SourceForge downloads statistics prove that basing a quality object-oriented interpreter like ooRexx on top of the strong procedural Rexx standard is a winner.

A Sample Program

Let’s take a look at a procedural Rexx program. We won’t stray into tools, IDE’s, GUIs, interpreter choices or the like… we’ll just stick to the basics – the code.

This program scans input text and analyzes its complexity by calculating ratios between longer words and shorter ones, and between prepositions and non-prepositions.

While this program is quite simple, text-scanning has proven useful in such diverse tasks as identifying the authorship of manuscripts and analyzing writing styles. An academic even used a text-scanner to predict the winner of the 2004 U.S. presidential election based on the reasoning styles embodied in the candidates’ speeches.

Here is our simple text scanner. It performs some fundamental poetry analysis—

/*  POETRY SCANNER:                                                  */
/*                                                                   */
/*     This program scans text to perform primitive text analysis.   */

list_of_articles = 'A AN THE'
list_of_preps    = 'AT BY FOR FROM IN OF TO WITH'

big_words       = 0   ;   small_words  = 0
number_articles = 0   ;   number_preps = 0

do while lines('poetry.txt') > 0
  line_str = linein('poetry.txt')  /* read a line of poetry         */
  line_str = translate(line_str)   /* translate to upper-case       */
  line_str = translate(line_str,'      ','.,!:;"') /* remove punc.  */
  call lineout ,space(line_str)    /* display converted input line  */
                                 
  do j=1 to words(line_str)        /* do while a word to process    */
     if wordlength(line_str,j) >= 5 then
         big_words = big_words + 1             /* count big words   */
     else
         small_words = small_words + 1         /* count small words */
     word_to_analyze = word(line_str,j)        /* get the word      */
     if wordpos(word_to_analyze,list_of_articles) > 0 then
         number_articles = number_articles + 1 /* count the articles*/
     if wordpos(word_to_analyze,list_of_preps) > 0 then
         number_preps = number_preps + 1       /* count prep phrases*/
  end
end                
say
say 'Ratio long/short words: ' (big_words/small_words)
say 'Number of articles: ' number_articles
say 'Number of prepositions:' number_preps
say 'Ratio of preps/total words:' (number_preps/(big_words+small_words))

To get a feel for Rexx, let’s walk through the code.

The first two executable lines of the program define two lists:

list_of_articles = 'A AN THE'
list_of_preps    = 'AT BY FOR FROM IN OF TO WITH'

As subsequent code demonstrates, Rexx makes a good vehicle for list processing. Many programming problems can be defined and resolved through the “list processing paradigm.” Rexx also works well for string processing, records processing, and other paradigms (for example, the object paradigm in ooRexx). Rexx supports all the data structures used in the different processing paradigms.

The declarations of variables big_words, small_words, number_articles, and number_preps show that Rexx is a free format language:

big_words       = 0   ;   small_words  = 0
number_articles = 0   ;   number_preps = 0

These lines stack more than one statement per line by ending statements with semicolons. You don’t need to terminate Rexx statement otherwise. Nor does Rexx require much syntax. (Scan the program and you’ll see.) This syntactical simplicity is a big benefit. I code Rexx from memory, which I still can’t do after years of coding Korn and Perl.

Another aspect of its simplicity is that Rexx does not require declaring variables. (I declared big_words, small_words, number_articles, and number_preps in order to initialize these counters to 0.) But like any interpreter designed for large coding projects, Rexx offers a way to override this default behavior and require that all variables be pre-defined. Choices like this render an easy-to-use language powerful.

The do while statement shows off another of the many techniques through which Rexx mates simplicity and power:

do while lines('poetry.txt') > 0

The file poetry.txt does not need to be explicitly opened or closed. There are no statements that open or close this file in the program. Rexx follows this principle throughout – automate everything possible. This minimizes coding effort and maximizes simplicity and power. Yet one can always override these common-sense, default behaviors — an absolute requirement of any true “power language.” For example, Rexx provides the stream function if you need to open, process, and close a file in atypical fashion.

The several lines of code after the do while use the built-in Rexx functions linein, translate, and lineout to read an input line, translate it to upper-case and remove punctuation, and write it:

line_str = linein('poetry.txt')  /* read a line of poetry         */
line_str = translate(line_str)   /* translate to upper-case       */
line_str = translate(line_str,'      ','.,!:;"') /* remove punc.  */
call lineout ,space(line_str)    /* display converted input line  */

You can identify Rexx functions because all are followed immediately by a parentheses that contain arguments. A function without any arguments still requires parentheses, as in example().

Rexx has a very small, simple instruction set, surrounded by a large function library. Like C or C++, the result is that you can start programming with minimal knowledge, yet power is available as you learn the functions and classes.

The interior do loop uses the built-in functions words, wordlength, wordpos, and word to analyze each line of text:

 do j=1 to words(line_str)        /* do while a word to process    */
     if wordlength(line_str,j) >= 5 then
         big_words = big_words + 1             /* count big words   */
     else
         small_words = small_words + 1         /* count small words */
     word_to_analyze = word(line_str,j)        /* get the word      */
     if wordpos(word_to_analyze,list_of_articles) > 0 then
         number_articles = number_articles + 1 /* count the articles*/
     if wordpos(word_to_analyze,list_of_preps) > 0 then
         number_preps = number_preps + 1       /* count prep phrases*/
  end

This processing counts “big” and “small” words, the articles and the prepositions. words returns the number of words in a string, while word returns a specified word from the string. wordpos returns the word number position of a word in a string, and wordlength provides the length of a word.

All Rexx functions can be written one per line, as in the program code, or nested to any level. I’ve kept it simple here.

The concluding lines in the program use the say instruction to automatically concatenate and write out text strings or labels along with calculations:

say 'Ratio long/short words: ' (big_words/small_words)
say 'Number of articles: ' number_articles
say 'Number of prepositions:' number_preps
say 'Ratio of preps/total words:' (number_preps/(big_words+small_words))

As this program shows, Rexx is especially noted for its string processing power. Many problems can be solved through this paradigm and Rexx is quite adept at it.

While this poetry processing program is procedural, you can also use regular expressions to achieve the same result. Regular expressions are a succinct, non-procedural way to process strings (text). Grounded in pattern matching, they can reduce code and result in elegant text-processing solutions.

Rexx offers regular expressions through its external function libraries. Many of the thousands of free Rexx add-in tools are supplied in the form of such function libraries. You code and use the functions in these libraries just like Rexx’s own built-in functions (once you’ve coded a line or two to establish access to the external function library). With Rexx (as in Python), you have several different forms of regular expression processing available in different free external function packages.

This brief program gives you a feel for Rexx – its lack of syntax, its high level of automation, how it combines simplicity with power, and the way in which its flexibility solves problems with different processing paradigms.

I’ve left out objects. If readers are interested, I’ll follow up this article with another that will specifically look at Open Object Rexx. ooRexx, as it’s called, combines the simplicity and power of procedural Rexx with all the capabilities of object-oriented programming.


Learn More…

Rexx supports dozens of web sites in many spoken tongues. Start with these—

- RexxInfo Start here… downloads, interpreters, tools, tutorials, sample code, everything
- ooRexx.org The official home of Open Object Rexx… information, downloads, documentation
- Rexx Language Association The user group of the Rexx community


Howard Fosdick is the author of the The Rexx Programmer’s Reference, the complete 700-page tutorial and reference guide to all varities of Rexx, its interpreters and tools. He has coded in most major scripting and programming languages.

AddThis Social Bookmark Button

Forum

  • Rexx World
    10 January 2007, by Bill Turner

    I definitely would like to see a follow-up article on OO-Rexx, especially if it could compare "classic" and "oo" styles...

    I have used REXX in a mainframe environment, and now am writing fullsized applications under the Windows operating systems, where I have been able to find well defined and stable interfaces for accessing Databases and drawing "windows".

    Some of my code is comand line oriented, and some of it uses the "windows" approach that many end-users are used to seeing. Either way, because of language features, especially the string processing ones, the code is generally quite compact, very readable, and quite maintainable.

  • Rexx World
    10 January 2007, by Dave Johnson

    Great Article! It really gets to the simplicity and power of the language. But there is much more under the hood as they say.

    I have been using REXX and Object Rexx since my days in OS/2 land and currently develop and support applications on the Windows platform with the REXXLA ooRexx variant. I have no qualms about using ooRexx for mission critical applications. I have several running around the clock 365 days a year without a whimper. I can also attest to the rich OO component of the language. I’m also a Smalltalk developer.

    My recommendation: give REXX a try and you’ll shortly find a valuable language for your developers toolkit.

  • Rexx World
    9 January 2007

    Excellent article,

    I remember Arexx (an Amiga version of Rexx) during the mid 80’s, and this was invaluable for automating tedious tasks with the Amiga.

    Good to see that Rexx did not die, unlike the poor Amiga.

    Your article is good, but only scratches the surface of what Rexx can achieve, IIRC even some hardware used Arexx to communicate with the Amiga.

    I am not too sure about an object orientated version of Rexx, I only hope it doesn’t over complicate an otherwise simple language, but at least there is a choice of OOP or not, unlike most other scripting languages.

    Once again you guys have delivered some new and interesting articles to us readers.

    Please keep up the excellent work!!

  • Rexx World
    9 January 2007, by Steve Coalbran

    Thanks Howard, A nice concise description and examples that will hopefully induce others to start enjoying this wonderful language. As an essential MVS(z/OS) biggot, I am generally constrained to the mainframes where only the ’classic’ Rexx is available. However that, to me, does not feel like a limitation. Worth noting, for other fans of z/OS, that Rexx is the language of choice for control of many IBM products. Tivoli, Netview, I can list. Also the AD Tools, a good example being FileManager which uses Rexx as its control language. Exits can be written in Rexx in many products. ISPF even goes so far as to provide for REXX PANEXITs (PANEL exits) and ’*REXX’ ’sections’ within it’s PANEL logic, vastly simplifying the comprehensibility whilst at the same time extending the capabilities.

  • Rexx World
    8 January 2007, by Dan Carter

    This is an excellent article in support of the use of Rexx. Mr. Fosdick’s clear and concise style coupled with his in-depth knowledge of the subject is itself one of the strengths of the Rexx community. That style does carry over into his Rexx Reference.

    I am at present working to select a scripting tool to use for packaging and installation of a large zOS system being ported to a number of different Unix-based environments, and this article provides the best, most readable reasons I have seen to support the choice of Rexx or ooRexx for this purpose.

    I will refer my teammates to this article to gain additional support for recommending Rexx to the management of the porting effort.

  • Rexx World
    8 January 2007, by Ralph Balzac

    This was very clear. I would like to see a version using "regular functions", and would also like an oo example.

    Ralph Balzac

  • Rexx World
    8 January 2007, by vmrexx

    Nice introduction to some of the best features of Rexx, without getting to complicated. Self describing variable names is very helpful... the comments in the code are a true bonus!

  • Rexx World
    8 January 2007

    A nice and helpful introduction. Thanks!

  • Rexx World
    8 January 2007, by Sahananda

    Another great article Howard. I think it’s a shame you didn’t mention the Parse instruction which I feel shows the real power of Rexx when it comes to text analysis, so I hope you’ll follow this one up getting some more of the goodies out of the tool bag.

    An article on ooRexx would be welcome too.

  • Rexx World
    8 January 2007, by Lee Peedin - VP Research & Development - Safe Data, Inc. www.safedatausa.com

    Thank you for this article on Rexx. Our shop has a staff of 6 Rexx programmers that work on Windows, Linux, and OS/2. A few of us even use Rexx on our Palm PDAs. We provide telephony and web-based application services to the agriculture industry (primarily swine & poultry) as well as hospice and home care clients. The portability of Rexx programs across platforms has proven to be invaluable. I hope BitWise will continue to publish such articles.


Home