Thursday, September 3, 2009

Wasted Space

A programmer trying to find a problem with a program these days is more likely to be looking at a screen than a paper listing. It's a good idea to make things stand out by using blank lines between them, but it's possible to carry this idea way to far. PARAGRAPH-NAME. IF ITEM-A = ITEM-B IF ITEM-C = ITEM-D PERFORM ALL-MATCH ELSE PERFORM FIRST-MATCH END-IF ELSE IF ITEM-C = ITEM-D PERFORM SECOND-MATCH ELSE PERFORM NO-MATCHES END-IF END-IF. ADD 1 TO COUNT-F. READ FILE-E AT END DISPLAY 'END OF FILE' NOT AT END DISPLAY 'NOW PROCESSING RECORD ' COUNT-F END-READ. RTN-EXIT. EXIT. This routine could easily have fit onto one screen and therefore could have been seen at once, if the programmer hadn't inserted so many blank lines into the procedure. With proper indenting, the conditional dependencies of the code are obvious without making the code difficult to follow by going across multiple screens. Remember when trying to examine clauses that should be aligned such as IF / ELSE / END-IF, if the clauses do not appear on the same screen, it is very difficult to tell which one goes with which. One blank line before a PARAGRAPH name or an 01 is usually adequate to make major items more prominent. Here's the way it could have been coded on one screen: PARAGRAPH-NAME. IF ITEM-A = ITEM-B IF ITEM-C = ITEM-D PERFORM ALL-MATCH ELSE PERFORM FIRST-MATCH END-IF ELSE IF ITEM-C = ITEM-D PERFORM SECOND-MATCH ELSE PERFORM NO-MATCHES END-IF END-IF. ADD 1 TO ITEM-A. READ FILE-E AT END DISPLAY 'END OF FILE' NOT AT END DISPLAY 'NOW PROCESSING RECORD ' COUNT-F END-READ. RTN-EXIT. EXIT.