UPPERCASE, lowercase

13 Sep

Way back in the early 80’s when I started developing in COBOL, code was always written entirely in uppercase, due to the limitations of the keypunch machines used in those days.  We’ve come a long way since then, and today’s COBOL is pretty easy-going.   It isn’t at all particular about whether you use uppercase or lowercase when you enter your code.

The following lines of code will all compile and have identical results when executed:

MOVE 1 TO NUMBER-FIELD.

move 1 to number_field.

MOVE 1 to number-field.

move 1 to NUMBER_FIELD.

Move 1 to Number-Field.

mOve 1 to nUmBer_FieLd.

Notice that in the examples above I’ve sometimes used a hyphen, and other times used an underscore.   COBOL does not differentiate between these two characters, and that can sometimes drive you crazy when you’re searching for a particular variable name.  If you can’t find the variable name in the code with a hyphen, try using an underscore.

Lately, I’ve found that I prefer to enter my code in lowercase, as it just looks a little friendlier.  I guess that online email etiquette course I was forced to endure at work may have had some effect on me. Now when I review a program that is written entirely in uppercase, it appears to be shouting at me.   Yes, I have created most of the code samples on my blog in uppercase, mainly to avoid confusing any newbies, but please feel free to use whichever case you prefer.    Either way, COBOL doesn’t complain.

One thing to note, though, if you decide to get chummy with your code and convert all of the verbiage in your program from uppercase to lowercase, you do still need to be aware of case when you read an external file or database table.   For example, if you read an external file containing a  field called yes-no-flag, and that field contains an upper case “Y”, you must use an upper case “Y” in your “if” statement.  If not, your program will not have the results you expected.

See the problem?   If the field yes-no-flag contains an uppercase “Y”, and you test for a lowercase “y”, the negative path will be taken.   COBOL is case-sensitive for anything between quotes, and you must be aware of this when coding.

I hope I’ve made my “case”.

 

0 Replies to “UPPERCASE, lowercase

  1. I love this. I’m from a database background (Oracle), and the database industry is plagued by a palaeolithic uppercase habit. People who develop in other languages all week using sensible conventions for sound reasons just seem to hit the caps lock for NO REASON when it comes to anything DATABASE-related, and it drives me NUTS. No Ada programmer ever wrote BEGIN…END, but in PL/SQL (which I love) people can’t help themselves.

    I like to say there is a time and a place for uppercase code, and it’s 1974 and COBOL. Now it turns out you don’t have to write COBOL in uppercase any more either and the good COBOL developers know it.

Leave a Reply

Your email address will not be published.