Archive for May, 2008

But They Loved Her

Saturday, May 24th, 2008

I was once sent to a client to take care of some fairly modest modifications to some RPG programs on their System/34. As I went about making changes on a certain report program, I concerned myself with the requested changes, not paying much attention to how the program performed its main processing. As I submitted the program changes for test, an employee said to me that I should expect it to run for about 2 or 3 hours. Having looked lightly at the processing, and being acquainted with the 34’s processing speed and the size of the file being processed, I smiled inside. “More like 15 or 20 minutes, I think”, I said to myself.

To my surprise, it in fact did take around 2 ½ hours. I was anxious to find out why I was so wrong, and what I found disgusted me, and for the first time made me angry about the work of another programmer.

The file being processed was a detail file. That is, it was part of a file setup common in data processing where the line items in, for example, an invoice, are stored in a separate file from the general information about the invoice.

Let us suppose that the invoice “header” has a key of invoice number – the file is organized to be read in invoice number order. For our example, let us suppose the invoice number is 123456. In later versions of RPG, you could define file keys from fields physically separate from one another in the file; but this was RPGII on the System/34, and the key data had to be all together. In this case the key to the “detail” file was the invoice number followed by a 3-digit sequence number. So the detail keys for invoice 123456 could range from 123456000 through 123456999, though in practice the 000 record was not usually used (since the files were no doubt designed by business people, who would think starting to count with 0 was nonsense :) ).

Now, the customary way to read these records was to set lower limits (SETLL) using the invoice number and the lowest possible key (123456000), determining the highest possible key (123456999), then READing the file until you either reached end of file or the key of the record read was more than 123456999. Not having looked closely at the code before, I had assumed that was the way it was done. Since you would very seldom find an invoice with 999 line items, this would be the logical way to do it.

But this was not the way the programmer did it. She instead used a separate counter from 1 to 999; for every number from 1 to 999, she moved that number to the end of the key (getting 123456001, 123456002,123456003, etc.) and performed a random-access CHAIN to the file, using the data if the access was successful. So, if there were 4 detail records for the invoice, she would have 4 successful reads and 995 unsuccessful reads, instead of 4 successful to 1 unsuccessful the normal way. The program was spending over 99% of its time accessing the disk looking for records that didn’t exist!

What made the matter worse was that this logic was replicated in quite a few of their other major programs. Now, I’m not normally a person who likes to rock the boat, but this was too much for me. I went to my supervisor there, explained the situation and asked for permission to change these programs to do it the right way. Permission was granted, and I hunted down the other programs and modified the read routine in all of them to do it properly. And yes, they did complete in 15-20 minutes, just as I thought they should.

Unfortunately, this was too little too late. I found other areas where the programs, though giving correct results, were very poorly designed. The proof of the damage this programmer and others had done to this firm was evident in the fact that, at the time I came to that firm, they were in the process of moving their processing to another, non-IBM minicomputer using another dialect of RPG because it was deemed that the System/34 just didn’t cut the mustard. It was too slow.

This may be an extreme example. Normally, I don’t sweat performance too much, though even today I think programs are more bloated than they need to be. (I once compiled an RPGIV program with only 1 line: eval *inlr=*on. Its size was around 80K.) But bad programming can really have a bad effect.

I prefer that programs be clear and understandable, so that they can be more readily maintainable; performance can be somewhat secondary. I think that reducing disk access is the key to most performance issues. I really don’t worry about whether or not one opcode is 50 nanoseconds faster than another. Talk about a few trillion nanoseconds here and there and we’re talking some real time.

But sometimes you do have to stand up for a certain standard of performance. Unfortunately, in that company, quality control came in a little too late. Perhaps it was a human relations issue. While I was at that company, they talked about how much they liked that programmer as a person. She must have been a real charmer. Evidently, they liked her so much that they accepted whatever excuse she gave for a report run that took 2.5 hours to produce a report. Apparently, she had no intellectual curiosity to try to figure out why it ran so long. That, to me, was her cardinal sin- a lack of intellectual curiosity, a lack of desire to do what she could to improve her product. Her report produced correct results, but she could have done it right, she could have done it better.

I find I’m rambling here, in search of a point. Perhaps it’s just that quality is the important thing. Accuracy and clarity in the design. The ability to discern when something just isn’t right and know how to fix it. Be willing, whether a user or a programmer, to speak up whenever you see something that isn’t quite right, and talk to the people who can do something about it – don’t just vent to your fellow programmers or users. If a user, tell the programmer when you think his program isn’t working right, and show him how. If his pride gets hurt, so be it.

And, in harmony with what may be a recurring theme here, don’t worry about doing it the newest way; just do it the best way. Just do it right. That may not be easy; others may think another way of doing something is better (more right). If they are correct, then be willing to change.

And keep your mind open for change that is not the result of someone prodding you, but of you prodding yourself.

Control Breaks and Sanity

Sunday, May 18th, 2008

Charlie Massoglia, a well-known author in RPG circles, as well as the owner of his own consulting firm and past president of COMMON (a prominent IBM midrange user group) once wrote a series of articles introducing RPGIV to the world. In one of them he said: “Contrary to conventional wisdom, our shop does use control level indicators for reports since there is no easier way to produce subtotals and we have found negligible performance differences between input primary and full procedural files.” He acknowledged that he was likely a minority holder of the opinion when he followed the above remark and prefaced further discussion by saying, “Without getting into a debate about whether or not control level indicators should be used…”

A discussion of control breaks (or level breaks) almost always ends up in controversy. Even though control breaks, as part of the RPG cycle, have been part of the language, and very commonly used from the start, many RPG programmers don’t have a clue as to how the cycle functions, or even any reason why a programmer would even want it. It often goes beyond a intellectual discussion of merits and demerits of automatic level break handling by the cycle. Most RPG authorities would say that the less said about them the better. Bob Cozzi, an RPG authority, probably says that the “modern” RPG programmer does not use the cycle, though I haven’t looked at his classic “The Modern RPG Language” in a while, so I can’t be sure.

The divide seems to be at the System/38. If a programmer got his initial experience using RPGII on the System/3, System/34 or System/36, in my observation they have absolutely no problem understanding the RPG cycle and think handling level breaks using the cycle is the obvious way to go; If they started their RPG experience with RPG with RPGIII on the System/38 or RPG/400 or RPG IV on the AS/400, the cycle is mind-boggling and those who use it are demented.

Forum discussions of the RPG cycle often deteriorate into name-calling, generally at the expense of the old guard, who should just retire so the real programmers can fix what they did. It becomes almost a religious issue. Once I just brought up to someone the subject of level breaks using the cycle, not even arguing in favor of it, and by his tone of voice in reaction you would have thought I was suggesting I wanted forcible carnal knowledge of his sister.

I find that some authors will admit in forum entries that RPG using the cycle makes sense at least in some circumstances, even though their full blown books will consign discussion of it to an appendix entry.

Level breaks, as described above, are linked tightly to the RPG cycle. Until recently, all RPG programs use the RPG cycle automatically; however, most “modern” RPG programs tend to try to make believe that the cycle doesn’t exist. The one who wants to ignore the cycle will use a repeated READ or READE statement to read a file or a subset of it. The one who uses the cycle does not need to do this, assuming his main focus is reading a single file (or multiple files) from start to finish. (This programmer may use READ or CHAIN opcodes to read files subsidiary to the main file being read.).

For this reason, I will reserve a further discussion of level breaks until I discuss the RPG cycle. This will involve an interesting discussion of programmer psychology and why programmers sometimes reject useful techniques for the sake of an ideology.

The Good (Indicators Part 2)

Saturday, May 10th, 2008

Back around 1980 or so, I read an article or two by Dick Eagleson in an IBM minicomputer trade publication about the (then) relatively new concepts of structured programming. I believe it was before the System/38 came out, so he explained how to perform sequence, selection (IF-THEN-ELSE-END; CASE;and so on), and iteration (DO-ENDDO-DO WHILE, etc.) in the context of pre-System/36 RPGII, where all you had to work with was COMP and GOTO and TAG. (In this article, he also declared his Law of Software Strangeness: Any code you write and don’t look at for six months may as well have been written by someone else when you look at it again.)

In this article, he also declared that just because IBM provided 99 numbered indicators to use, it didn’t mean that you had to see how many you could stuff into any given program! It was not a revelation, because it was so obvious; but the implications were grand. You did not have to use all the indicators that come to mind in your programs. The need for indicator complexity was nonexistent; do it the structured way.

To give an example, suppose you wanted to convey this RPGIV concept:

     C                   IF        (X>5 and Y<3 and Z=9)
     C                   DOU       X<5 or Y>3
     C**  Some code that changes the values of X or Y
     C                   ENDDO
     C                   ENDIF

This is how you could render it in RPGII:

     C           X         COMP 5                    25
     C   25      Y         COMP 3                      25
     C   25      Z         COMP 9                        25
     C  N25                GOTO EIF001
     C           LUP001    TAG
     C           X         COMP 5                      25
     C  N25      Y         COMP 3                    25
     C  N25                GOTO LUP001
     C           EIF001    TAG            

This new way of thinking changed the way I programmed from then on. While I did not swear off indicators as I learned RPG400 and RPGIV, I made sure that my code would be as succinct as possible, using as few indicators as possible. At the same time, I was not afraid of using them or overly concerned about getting rid of them.

Much of the dislike for indicators seems to be based on the fact that they are not self-defining like a field name is (CUSTBAL, for instance meaning Customer Balance). If you set on indicator 89 for an unsuccessful CHAIN(random file access) operation, and you continue on into your calculations without referring to indicator 89 in your calculations, you tend to lose track of the significance of indicator 89. That is true. But immediately after the CHAIN, you DO know the significance of indicator 89. Do whatever you need to do with it-change the course of your processing, put out an error message, or whatever- then FORGET about indicator 89. If you really need to save the result of the CHAIN, set a field to Y or N based on the results (or in RPGIV, save it in a named indicator variable). Go ahead and use 89 somewhere else, if the spirit moves you.

Other examples could be given. Record identification indicators can be defined by the program to identify when a particular file is read. Especially if you are dealing with Input Primary and Input Secondary files (where entire files are read from beginning to end with no need for a READ calculation), these indicators are self-documenting (unless, if you’re foolish, you change their settings in calculations).

Now, do I use an indicator when doing a CHAIN operation? No, I don’t; I use the %FOUND BIF (built-in function) to test whether a chain was successful. But I have no problem with others using CHAIN with an indicator. At a previous employer, they were considering coding standards, and they wanted to mandate the use of BIFs like %FOUND. Another programmer pointed out that when you use %FOUND, when running a program in debug mode, the BIF does not give immediate feedback on the success of the CHAIN; using CHAIN with an indicator gives you immediate feedback. I had never thought of that; and I can see that as a reason why a programmer should indeed be permitted to use an indicator in this situation, if he deems it appropriate.

So I have no problem with indicators as such; only when they are used badly, as I showed in my previous post. And I think that RPG gurus and others who have a hissy fit when indicators are used (in a proper way) should just calm down, relax, get another cup of coffee and find something worth worrying about.

The Bad and the Ugly (Indicators- Part 1)

Friday, May 9th, 2008

For the uninitiated, indicators are essentially Boolean variables which, until recently were defined automatically by the RPG compiler. (With RPGIV, you can now define your own named indicators. See this article for details.)

The system defined indicators are named by the digits 01-99, which may be defined by the programmer, L1-L9 to define level breaks(where changes in input data are automatically detected by the program), MR (used when matching file reads with similar keys), halt indicators H1-H9 to halt the program when an error occurs, and overflow indicators OA-OG and OV to flag when a printout is at end of page and ready to go to the next.

The trend today is to totally swear off indicator usage in RPG programs. This is understandable. Misused indicators have been the cause of many programmer headaches or worse. You’ve never lived until you’ve tried to get your head around a 10000 line RPG program that uses all 99 numbered indicators in calculations, and as many as possible in the output. You find yourself frantically turning from line 2000 to line 8763, trying to find out what on earth is the significance of indicator 56, or when it is true that indicators 45, 65, and 67 are on and 33 and 89 are off, with even fields in the output conditioned by up to three indicators.

Or how about these calculations and output?

C           X             COMP 25                   253746
C  N25N37   Y             COMP 36                   161514
C   25 46 16Z             COMP 83                   1726
C   26 16 25CUST#         CHAINCSTMST               12
OCUSTMSTRE         17 16        OUTPUT
O                  25 27 46     FIELD1   45
O                  37 15 46     FIELD1   50
O                  14 27 46     FIELD1   45
O                        12              57 'NOT ON FILE' 

There’s just too much going on in one line of code.
So when people want to get rid of indicators entirely, you can understand. But do such programs prove the point that indicators must be gotten rid of at all costs?
Well, not necessarily. It depends……

A Bit of my Philosophy

Monday, May 5th, 2008

Philosophy is such a pretentious word. Perhaps I should call it my way of thinking about programming.

If I am not programming for my own use, I want to do what the user wants and needs. Of course, sometimes the user does not really know what he wants, and I must help him try to figure it out. But I do not take the attitude that I know better than him what is good for him.

As for technique, I try to be like the physician- at least do no harm. I try to be careful and not introduce careless errors. And I desk check as much as I can. The earlier you catch errors in the process, the better.

But perhaps I should get to areas where I might differ from a great number of other RPG programmers. In RPG, due to language evolution, there are often many ways of doing the same thing. Unless doing so will only perpetuate and intensify confusion, I prefer to maintain a program using code in the style it is written. That is not a hard and fast rule, but a general principle. If it is in RPGIII style, it will usually continue to be so, even if I have migrated it to RPGIV. I might enhance it with code unique to RPGIV, but I will not often consider it my duty to go beyond my maintenance function, rip the program apart and rewrite it.

My consideration of coding choices revolves about effectiveness. I will use whatever will create smooth, elegant code, whether it is considered new, or “old” and “archaic”. If an “old” technique works better, I will use it rather than some solution cobbled together from “new” techniques. If the new one is better, I will use it. It is all about what works most elegantly and clearly. Terseness is not the only goal. The time it takes to key in a program is the least time-consuming part of programming. If terseness, the keying of the fewest characters on the keyboard, were the goal, I would have given up RPG long ago and learned APL.

Too often I feel, programmers think that “change is good”, so they feel the urge to update old code, even if it is working without error at present. Programmers also seem to be easily swayed by what is the newest fashion in programming. I am not. To condemn a programming technique as being not “modern” is the grossest form of condescension. Remember, Adolf Hitler was at one time the “newest” ruler of Germany, was a popular choice, and represented vast “change” in the political landscape. That “change” was not good for Germany or the world. On a less cosmic level, change in programming technique is not necessarily good. An opcode is not good merely because it is a part of a set of new opcodes or BIFs (built-in functions). Each one must withstand inspection to make sure it is worth using in any given situation.

And sometimes we seem to forget that any RPG installation that existed before the advent of RPGIV is going to have “old-styled” code; the older the shop, the older the code. It is pointless to try to hide this fact from new RPG programmers; it is useless and self-defeating to try to hide this code from the new programmer or let him believe it does not exist. Unless you are part of a software company and have free rein to make any changes you please, you will be maintaining old code at some point.

How these principles apply in my coding technique will be made more clear as we go on this blog. There may be other ideas that also come into play. For now let the above suffice.

A Bit of Background

Friday, May 2nd, 2008

My name is Curtis Barron, and I am a computer programmer.

Almost 30 years ago, I began to learn about computers and to program them using the business language RPGII. I was part of a group of people being taught by the manager of an IBM System 3, Model 10 minicomputer installation. The school was in his kitchen. We got the appropriate textbook. (I believe it was by Shelly and Cashman.) I was the only one of the group who actually got a job programming as a result of that class. My teacher hired me as a programmer at his company one day a week; providentially, only about a month before he left the company. I came on board full time in December, as a combination programmer and accounts payable clerk. I had gotten my toe in the door; I went in and never looked back. I have proceeded to learn all the succeeding new dialects of RPG- RPGIII, RPG/400, and RPGIV.

My attention has been focused, by my job, on RPG; however, I have an intense curiosity about other languages, old and new. I have tried to learn some of them, but I have usually been stymied by the fact that I had no particular project to use them on- I find it difficult to learn them without a particular goal. I have learned the following computer languages well enough to write “production” code - code that would be used by someone else - in Apple BASIC, GWBASIC (that came with my Tandy 1000), Visual BASIC, and a few routines in Rexx. I was rather proud of the GWBASIC effort; I built data entry screens in the style of the AS/400, instead of line-at-a-time data entry, having the user press enter to go from field to field and processing all the data when the last field was entered.

Besides religious activities, I enjoy reading and being with my family. My favorite authors are Jane Austen and James Herriot. I have contributed a number of comments to Austenblog, a Jane Austen discussion group.

I intend to write on my experiences and feelings about RPG - promoting it as a valuable computer language, discussing my ideas on programming technique and on programming in general. When I really get underway, which should be in just a couple of days, I hope you will find it interesting enough to come back and read again.

Comments are encouraged and welcomed.