In the course I teach on legacy software, Cobol is the most feared of all languages. Why? Probably because it does not look like any language students have seen before. After a couple of weeks of coding Cobol, they often run away screaming, or sit very silently in a corner. It is feared largely because it doesn’t things in different ways – and this can lead even the most confident programmer to have doubts about what they are coding. The challenge is that a Cobol program may run, even though there are inadequacies in the syntax. Not grievous issues, but small silent things. A good example is a cascading if statement. A C programmer is normally happy writing code which looks like this:
if (aNumber < 0) printf("the number is negative"); else if (aNumber > 0) printf("the number is positive"); else printf("the number is zero");
A novice Cobol programmer will try something of the form:
if aNumber is < 0 then display "the number is negative" else if aNumber is > 0 then display "the number is positive" else display "the number is zero" end-if
This will work, however it will raise a warning of the form “IF statement not terminated by END-IF“. In more complex code, it could lead to problems with the program logic. The code should be written as:
if aNumber is < 0 then display "the number is negative" else if aNumber is > 0 then display "the number is positive" else display "the number is zero" end-if end-if
Yet Cobol provides another, simpler way to write this piece of code:
evaluate true when aNumber < 0 display "negative" when aNumber > 0 display "positive" when aNumber = 0 display "zero" end-evaluate.
So Cobol need not be feared. It is just different.