Are RPG Subroutines Obsolete?

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

If you want to get a bunch of programmers cooking, say something like this: “Anyone who uses GOTOs ought to be fired,” or “The RPG cycle should be banned.” I’m going to throw in another condiment of the same flavor and say, “Subroutines should be consigned to history.” Let me first say that I plan to stand well clear of the discussions that will no doubt ensue—I like to leave myself room to backtrack. The only absolute I adhere to is “Keep the customer satisfied.” But, just for the record, I haven’t used a GOTO in many years, I’ve almost forgotten how the cycle works, and the last time I coded a BEGSR was over two years ago when V3R6 first delivered the prototyped subprocedure.

Now, allow me to divulge some thoughts on what kinds of programs keep customers happy. They’re the programs you said would be ready with that new mod by Monday, and they are. They go right to work from the day you ship them and don’t come back for rework. When you assign the job of maintaining them to a programmer, there is no hint of fear on his face. They are programs that offer some little improvement the customer didn’t ask for but got anyhow.

In my view, none of these positive elements are possible with programs that are difficult to read, difficult to understand, difficult to test. With most programmers working directly off of screens, certain conditions should be met: Blocks of logic should span no more than a few screen loads. Logic should be structured (and names given) in such a way that it is understood with the least necessary effort. If anything goes wrong, the malfunctioning code should be easy to isolate and correct. And, most important, as a program’s task becomes more complex, its internal structure must become more simple (you can get away with all sorts of poor structure and ill-conceived assumptions when your task is minor).

Compare subroutines to subprocedures with these requirements in mind, and there’s no contest. Subprocedures have local variables; defined physically near to where they are used; and no matter what you call them, they are unique to that specific subprocedure. Subroutines can use only global variables. Subprocedures have formal interfaces; subroutines don’t. Subprocedures can call themselves recursively; subroutines