Project Listing




Business Card




Technical Articles


Refactoring RPG on the Power i
by Stephen West


What is Refactoring and Why Do It?

Referring to something as a "dinosaur" is a pejorative adjective meant to characterize as obsolete, or inflexible to the point of extinction. Paleontologists claim that dinosaurs roamed the earth for over 160 million years and their extinction was caused by an asteroid hitting the earth. A reign of 160 million years is hardly inflexible; in fact it is an astounding success. I would say that the asteroid hitting the earth was a fortuitous event for us mammals. In post-cataclysmic earth, mammals were better suited for survival than the dinosaurs. The real trick is to survive the disaster.

If RPG is to survive, it must adapt to support newer technologies and advances in the programming languages landscape. One has only to look at an indicator laced RPG II program source and compare it to a functionally equivalent free-format RPGLE version to see the huge steps forward that RPG has made. Support for newer technologies (CGI, web services, XML, java integration, etc...); they are there. Advances in programming languages are there too (indenting code, native SQL calls, module linking, and eliminating indicators ... OK, OK maybe reducing indicator use). Will RPG survive? Well that depends on us; the programmers. Why? Because not all the RPG code out there uses the advances that are available. What exactly is that suppose to mean? It means that we cannot let go of the old RPG knowledge; we have to remember it so that we can support the old code. How can we let go of the old RPG knowledge to make room for new if we must always be prepared to revisit old code? The answer is to "refactor" the old RPG code.


Here is the point where you are supposed to ask "what do you mean by refactor?"

In the java world you will hear the term "code refactoring" frequently. With the quick pace of technology changes that plague the java world, a way had to be found for abandoning last years solution (deprecated) and embracing this years newer, better way of solving the same problem. The practice of code refactoring is an established software engineering approach for keeping source code up-to-date. Never heard of code refactoring? OK. Stop reading this article and google "code refactoring". You got over 2 million hits, right? Now look up "code refactoring" in wikipedia and read the first couple paragraphs that describe it. STOP! Now come back to this article.

Refactoring source code means to change the code to use newer techniques, newer syntax, newer opcodes, to clean-up, remove dead code, and improve the overall organization of the code, WITHOUT changing the behavior of the compiled program.


How is refactored code any better? For one thing, you don't have to remember all those antiquated RPG III coding techniques, you just have to keep up with the new stuff. The refactored code will start to look like all the other [modern] programming languages out there. Continually refactoring code provides an opportunity to implement coding standards. Once you get rid of the MOVE's, Z-ADD's, and other highly proprietary opcodes the code may even begin to look "portable." The result is more people will be able to read the code (understandability) making it more maintainable. It will be easier to take advantage of newer opcodes and programming techniques.



OK, that was the Refactoring RPG sales pitch. Now let's get into the practical application.