Wednesday 21 December 2011

Strange Programming Languages: RPG II

Opinions differ on the best programming language. Opinions also differ on the strangest programming language. I am going to offer my own humble opinion on this.

I want to talk about two contenders: RPG II and LISP. In this posting I will deal with the former.

RPGII was the first language that other people paid me to program in (well, more or less). “RPG” was an acronym for “Report Program Generator”.

It is an extraordinary language in a number of respects:
  • It has its own “cycle” where it will read a record, perform some computations, and then output something. The input could be from a file or from a screen which has been displayed on the workstation. The output could be to a file, the screen, or to the printer. The cycle just kept repeating over and over until all of the available records had been processed.
  • It used “indicators”. This was a set of Boolean values which could be set, cleared, and tested. So when a record with a “A” in column 1 was read from an input file, you could specify that indicator 10 should be turned on. Then you could have computations that were only executed when indicator 10 was on, and output that was only written when it was on also.
  • Code had to be put into the right columns in order to be valid: the columns were significant. For example, the operation code for a calculation had to start in column 28. In order to read a printout of a program, a developer would use a “template” which would show the purpose of each of the columns.
There were 99 ordinary indicators (01-99) which could be used as needed.

There were also special indicators such as:
1P – which was only on during the first output cycle (“1st page”)
LR – which was only on for the “last record”
MR – was put on when there were “matching records” in two input files (when reading customer and transaction records from two different files, for example).

Once, when I had just started as a programmer in an insurance company, an auditor approached me looking to see a sample RPG program as he had been told by one of my colleagues that RPG was “self-documenting”. I told him that I had just joined the company and it would be better for him to ask someone else and off he went. What I did not tell him was this: RPG II was probably the further thing from a self-documenting language that there ever was! Here are a few reasons:
  • To read the code at all, you needed to understand the built-in cycle and what F specs, I specs, C specs etc. were all about
  • To read a code printout, you needed an “RPG Debugging Template”. You could line this up with the code and it would allow you to recognise the columns (I can’t believe that (a) I don’t have one of these and (b) I can’t find a picture of one on the web!)
  • All of the operation codes were limited to 5 characters. So there were operations such as “Z-ADD”, “LOKUP”, “SETOF” and (my personal favourite) “XFOOT”.
  • Field names were generally limited to 6 characters (contrast this with current best practice for Java!)
In some ways (although it was a MUCH higher-level language) reading RPG code was a little like reading Assembler. But people writing Assembler code tended to write a lot more comments!

To see a sample of RPG II code, take a look here.

In conclusion, although it may not seem like it from what I have said above, I was a big fan of RPG. It was quirky and obscure, but you could get a lot done with a very small amount of code. The build-in cycle did so much of the work for you. And although I understand that flavours of RPG are still in use today, one this is for sure: we will never see the emergence of another programming language like it!