Let WDSc Help You Format Your Source Code
August 8, 2007 Ted Holt
It’s widely accepted throughout the world of programming that indenting source code to show logical structure makes source code easier to read. Program Indentation and Comprehensibility, a study by Richard Miara, Joyce Musselman, Juan Navarro, and Ben Shneiderman, supports this position. Miara, et al, determined that using a two- to four-space indentation scheme improves comprehension by 20 percent to 30 percent. (That’s for humans, of course. The compiler protested that indentation was of no benefit.) Indenting source code is sometimes a nuisance, but it happens that WebSphere Development Studio client (WDSc) can help you indent source code, and can help you improve readability in other ways. The features that help you “pretty up” your source code are buried in the preferences within WDSc. To arrive at the preferences in Version 7, follow the following menu trail:
The sequence is slightly different in Version 6.
In either case, you will eventually arrive at a list of source types.
Some of these source types expand even further to allow you to maintain templates. Since we’re not interested in templates for now, you won’t need to expand any of the source types. The features that are available to you depend on the source type. Let’s look at some of the options, starting with indentation. Automatic Indent: Under CL and ILE RPG, you will find an automatic indent option. If you check this option, the system gives you access to a box in which you can specify from one to 20 blanks of indentation. I like the number three. If you turn on this feature, LPEX indents the cursor when you press Enter after keying a line that defines a block structure (e.g., if, do-while). Automatic Uppercasing: This option changes the source code to all capital letters as you key it. However, character literals are not affected. Automatic Closure of Control Block: If you select this feature of the ILE RPG parser, LPEX automatically generates the corresponding ENDxx op code when you press the Enter key after keying an op code that defines a block structure. You have a choice of five styles: ENDXX, EndXx, Endxx, endXx, and endxx. Here are a few CL-only possibilities. Automatic Formatting: This option allows you specify the positions where the label, command, and continued lines should begin. This option was already checked in my implementation of WDSc. One of my co-workers had already encountered this setting and was able to tell me how to disable it before I became frustrated. Label Above Command: Checking this option tells the parser to place each label on a line by itself. One Parameter per Line: If this option is active, the parser places each parameter of a CL command on a line of its own, like this: CRTDUPOBJ OBJ(SOMETHING) + FROMLIB(SOMELIB) + OBJTYPE(*FILE) + TOLIB(OTHERLIB) + NEWOBJ(OTHERTHING) + DATA(*NO) When I took programming classes at the vo-tech, I didn’t care what my code looked like. I just wanted something that worked correctly. When I started programming for real and had to maintain the garbage I had written, I began to care about writing legible code. That’s one reason I have enjoyed editing with WDSc. I hope you find some of these editing features helpful as well.
|