I often receive negative comments about my campaign against the use of symbols in programming, specifically in field, data structure, and procedure names. The comments mostly come from programmers who habitually use the dollar sign ($) or pound sign (#) in field names. Some even still use the "at" (@) sign but not many.
This practice originated in the olden days of programming out of a desire to sort the names of work fields so that they would appear near one another in the compiler cross-reference listing. Today, some shops continue to set standards that require the use of these non-invariant characters in the names of work fields. But why? After all, when was the last time you looked at a printed copy of a compiler listing? For that matter, when was the last time you used a compiler listing at all?
RPG programmers worldwide largely use SEU to edit RPG. A few use more contemporary tools such as CODE/400 and CodeStudio, and even fewer use WDSc. But all of these tools, including SEU, have the ability to read, display, and jump to compiler errors from within the source editor. The use of compiler cross-reference listings is as passé as the use of symbols such as $, #, and @ in field names.
Today, as source code is sent out over the Internet, the use of invariant characters in not only field names but also source code has become a worldwide practice if not a standard.
An invariant or never-changing character is a character that is the same in all character sets. Such characters were once called "code pages" and are now called coded character set ID (CCSID). For example, the letters A and a are invariant characters that are available on keyboards in North and South America, Europe, Africa, and many parts of Asia, regardless of the CCSID used on the machines in those regions.
However, if you use a pound sign (#) in a field name and then provide that source code to people in other countries, it is unlikely that the # will appear as # when they move the source to their machines.
IBM specifically recommends that you never use these non-invariant characters when naming the following objects:
- Libraries
- Database files
- Device files (display or printer)
- Help panels
- Message files
- Commands
- Programs
- Record formats
- Fields
Note the last item on the list: fields. It seems that IBM agrees with me on this one.
Invariant Character Set
With a few exceptions, such as Katakana, all EBCDIC code pages (CCSIDs) have a common set of characters. Within any CCSID, these common characters can be found at the same code point:
- A to Z
- a to z
- 0 to 9
- plus sign +
- less-than symbol <
- greater-than symbol >
- equals sign =
- ampersand &
- asterisk *
- double quotes "
- single quote '
- parentheses ( )
- comma ,
- underscore _
- hyphen -
- slash /
- semicolon ;
- colon :
- period .
- question mark ?
- percent sign %
The percent sign has one or two problems with compatibility, but in those CCSIDs, there is another character that displays as a % symbol.
Field Naming
My recommendation is to use A to Z, 0 to 9, and the underscore symbol for field names. Since RPG IV converts lowercase letters used in field names to uppercase, lowercase letters are interchangeable with uppercase.
Also, try to avoid the mistakes many programmers make who are new to upper/lowercase programming. Specifically, try to...
- AVOID MAKING EVERYTHING UPPERCASE.
- avoid making everything lowercase.
- Avoid USING mixed Case inconsistently.
A specific style for mixing upper/lowercase letters in code is not something I can offer because which technique is best is a subjective opinion.
So join me in my blue ribbon campaign to eliminate $, #, and @ in field names and make the world safe for your code!
Corrections
In October's issue on using the Qp0zLprintf API to write to the job log, I also mentioned the Qp0zUprintf API that writes to the user trace area. In that article, I mentioned that the DSPUSRTRC command could be used to display the user trace data. The correct name for the command is DMPUSRTRC, and it allows you to send the user trace data to a database file named QAP0ZDMP in the QTEMP library. You then use DSPPFM or RUNQRY to view the data in the trace outfile.
Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.
LATEST COMMENTS
MC Press Online