a companion discussion area for blog.codinghorror.com

COBOL: Everywhere and Nowhere


#181

I unfortunately went to DeVry in the late 90’s and COBOL/JCL/DB2 were the main programming languages they offered.

I remember one day as we were writing some COBOL programs and someone asked “How do you make Video Games with this language?” ha

COBOL is crazy verbose and crazy english like.


#182

Of course, 220 billion lines of Cobol amounts roughly to a “hello world” program, given the verbosity of the language! :wink:


#183

“If it ain’t broke, don’t fix it?”

If your enterprise is entrenched in COBOL, it can make sense to stay the course.

Outside of this, I wouldn’t recommend writing any new enterprises or software in COBOL.

I wonder how soon today’s PHP will be cast as COBOL is now?


#184

COBOL is verbose, but even so it’s nowhere near as bead as Jeff would like to suppose. From 99-bottles-of-beer.net, ignoring the program comments lines, the C# example contains 38 lines of code and the COBOL example 48.

C#
/// A short and sweet C# 3.5 / LINQ implementation of 99 Bottles of Beer
/// Jeff Dietrich, jd@discordant.org - October 26, 2007

using System;
using System.Linq;
using System.Text;

namespace NinetyNineBottles
{
class Beer
{
static void Main(string[] args)
{
StringBuilder beerLyric = new StringBuilder();
string nl = System.Environment.NewLine;

    var beers =
        (from n in Enumerable.Range(0, 100)
         select new { 
           Say =  n == 0 ? "No more bottles" : 
                 (n == 1 ? "1 bottle" : n.ToString() + " bottles"),
           Next = n == 1 ? "no more bottles" : 
                 (n == 0 ? "99 bottles" : 
                 (n == 2 ? "1 bottle" : n.ToString() + " bottles")),
           Action = n == 0 ? "Go to the store and buy some more" : 
                             "Take one down and pass it around"
         }).Reverse();

    foreach (var beer in beers)
    {
        beerLyric.AppendFormat("{0} of beer on the wall, {1} of beer.{2}",
                                beer.Say, beer.Say.ToLower(), nl);
        beerLyric.AppendFormat("{0}, {1} of beer on the wall.{2}", 
                                beer.Action, beer.Next, nl);
        beerLyric.AppendLine();
    }
    Console.WriteLine(beerLyric.ToString());
    Console.ReadLine();
}

}
}

And COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. 99-Bottles-of-Beer-On-The-Wall.
AUTHOR. Joseph James Frantz.
*COMMENTS.
******************************************************************
* PURPOSE:
* This is a sample COBOL program to display the lyrics of the
* song “99 Bottles of Beer on the Wall.”
* This version of the COBOL 99 beers program demonstrates a few
* features of COBOL:
*
* 1. PERFORM VARYING, Cobol’s version of a Loop.
* 2. ADD/SUBTRACT with GIVING for math calculations.
* 3. EVALUATE/WHEN, Cobol’s version of Case.
* 4. INSPECT/TALLYING, which finds the number of specified
* characters in a variable.
* 5. Reference Modification:
* Var-name(Start character:Number of characters)
* which is essentially Cobol’s version of text subscripting.
* 6. Long descriptive variable names.
* 7. Use of SPACES and ZEROES for field/display values.
* 8. Highlight the self documenting nature of COBOL.
******************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Keeping-Track-Variables.
05 Bottles PIC S99 VALUE 0.
05 Remaining-Bottles PIC S99 VALUE 0.
05 Counting PIC 99 VALUE 0.
05 Start-Position PIC 99 VALUE 0.
05 Positions PIC 99 VALUE 0.
PROCEDURE DIVISION.
PASS-AROUND-THOSE-BEERS.
PERFORM VARYING Bottles FROM 99 BY -1 UNTIL Bottles = -1
DISPLAY SPACES
SUBTRACT 1 FROM Bottles GIVING Remaining-Bottles
EVALUATE Bottles
WHEN 0
DISPLAY "No more bottles of beer on the wall, "
"no more bottles of beer."
DISPLAY "Go to the store and buy some more, "
"99 bottles of beer on the wall."
WHEN 1
DISPLAY "1 bottle of beer on the wall, "
"1 bottle of beer."
DISPLAY "Take one down and pass it around, "
"no more bottles of beer on the wall.“
WHEN 2 Thru 99
MOVE ZEROES TO Counting
INSPECT Bottles,
TALLYING Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY Bottles(Start-Position:Positions)
” bottles of beer on the wall, “
Bottles(Start-Position:Positions)
” bottles of beer."
MOVE ZEROES TO Counting
INSPECT Remaining-Bottles TALLYING
Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY "Take one down and pass it around, “
Remaining-Bottles(Start-Position:Positions)
” bottles of beer on the wall."
END-EVALUATE
END-PERFORM
STOP RUN.

I coded COBOL for 5 years in the late 80’s early 90’s. It’s just a programming language and like all languages works well in some environments and with some tasks and less well with others. Slagging off COBOL for what it is is like an English speaker slagging off Lithuanian just because it’s at the opposite end of the indo-european language spectrum


#185

COBOL is verbose, but even so it’s nowhere near as bead as Jeff would like to suppose. From 99-bottles-of-beer.net, ignoring the program comments lines, the C# example contains 38 lines of code and the COBOL example 48.

C#
/// A short and sweet C# 3.5 / LINQ implementation of 99 Bottles of Beer
/// Jeff Dietrich, jd@discordant.org - October 26, 2007

using System;
using System.Linq;
using System.Text;

namespace NinetyNineBottles
{
class Beer
{
static void Main(string[] args)
{
StringBuilder beerLyric = new StringBuilder();
string nl = System.Environment.NewLine;

    var beers =
        (from n in Enumerable.Range(0, 100)
         select new { 
           Say =  n == 0 ? "No more bottles" : 
                 (n == 1 ? "1 bottle" : n.ToString() + " bottles"),
           Next = n == 1 ? "no more bottles" : 
                 (n == 0 ? "99 bottles" : 
                 (n == 2 ? "1 bottle" : n.ToString() + " bottles")),
           Action = n == 0 ? "Go to the store and buy some more" : 
                             "Take one down and pass it around"
         }).Reverse();

    foreach (var beer in beers)
    {
        beerLyric.AppendFormat("{0} of beer on the wall, {1} of beer.{2}",
                                beer.Say, beer.Say.ToLower(), nl);
        beerLyric.AppendFormat("{0}, {1} of beer on the wall.{2}", 
                                beer.Action, beer.Next, nl);
        beerLyric.AppendLine();
    }
    Console.WriteLine(beerLyric.ToString());
    Console.ReadLine();
}

}
}

And COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. 99-Bottles-of-Beer-On-The-Wall.
AUTHOR. Joseph James Frantz.
*COMMENTS.
******************************************************************
* PURPOSE:
* This is a sample COBOL program to display the lyrics of the
* song “99 Bottles of Beer on the Wall.”
* This version of the COBOL 99 beers program demonstrates a few
* features of COBOL:
*
* 1. PERFORM VARYING, Cobol’s version of a Loop.
* 2. ADD/SUBTRACT with GIVING for math calculations.
* 3. EVALUATE/WHEN, Cobol’s version of Case.
* 4. INSPECT/TALLYING, which finds the number of specified
* characters in a variable.
* 5. Reference Modification:
* Var-name(Start character:Number of characters)
* which is essentially Cobol’s version of text subscripting.
* 6. Long descriptive variable names.
* 7. Use of SPACES and ZEROES for field/display values.
* 8. Highlight the self documenting nature of COBOL.
******************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Keeping-Track-Variables.
05 Bottles PIC S99 VALUE 0.
05 Remaining-Bottles PIC S99 VALUE 0.
05 Counting PIC 99 VALUE 0.
05 Start-Position PIC 99 VALUE 0.
05 Positions PIC 99 VALUE 0.
PROCEDURE DIVISION.
PASS-AROUND-THOSE-BEERS.
PERFORM VARYING Bottles FROM 99 BY -1 UNTIL Bottles = -1
DISPLAY SPACES
SUBTRACT 1 FROM Bottles GIVING Remaining-Bottles
EVALUATE Bottles
WHEN 0
DISPLAY "No more bottles of beer on the wall, "
"no more bottles of beer."
DISPLAY "Go to the store and buy some more, "
"99 bottles of beer on the wall."
WHEN 1
DISPLAY "1 bottle of beer on the wall, "
"1 bottle of beer."
DISPLAY "Take one down and pass it around, "
"no more bottles of beer on the wall.“
WHEN 2 Thru 99
MOVE ZEROES TO Counting
INSPECT Bottles,
TALLYING Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY Bottles(Start-Position:Positions)
” bottles of beer on the wall, “
Bottles(Start-Position:Positions)
” bottles of beer."
MOVE ZEROES TO Counting
INSPECT Remaining-Bottles TALLYING
Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY "Take one down and pass it around, “
Remaining-Bottles(Start-Position:Positions)
” bottles of beer on the wall."
END-EVALUATE
END-PERFORM
STOP RUN.

I coded COBOL for 5 years in the late 80’s early 90’s. It’s just a programming language and like all languages works well in some environments and with some tasks and less well with others. Slagging off COBOL for what it is is like an English speaker slagging off Lithuanian just because it’s at the opposite end of the indo-european language spectrum


#186

COBOL is verbose, but even so it’s nowhere near as bead as Jeff would like to suppose. From 99-bottles-of-beer.net, ignoring the program comments lines, the C# example contains 38 lines of code and the COBOL example 48.

C#
/// A short and sweet C# 3.5 / LINQ implementation of 99 Bottles of Beer
/// Jeff Dietrich, jd@discordant.org - October 26, 2007

using System;
using System.Linq;
using System.Text;

namespace NinetyNineBottles
{
class Beer
{
static void Main(string[] args)
{
StringBuilder beerLyric = new StringBuilder();
string nl = System.Environment.NewLine;

    var beers =
        (from n in Enumerable.Range(0, 100)
         select new { 
           Say =  n == 0 ? "No more bottles" : 
                 (n == 1 ? "1 bottle" : n.ToString() + " bottles"),
           Next = n == 1 ? "no more bottles" : 
                 (n == 0 ? "99 bottles" : 
                 (n == 2 ? "1 bottle" : n.ToString() + " bottles")),
           Action = n == 0 ? "Go to the store and buy some more" : 
                             "Take one down and pass it around"
         }).Reverse();

    foreach (var beer in beers)
    {
        beerLyric.AppendFormat("{0} of beer on the wall, {1} of beer.{2}",
                                beer.Say, beer.Say.ToLower(), nl);
        beerLyric.AppendFormat("{0}, {1} of beer on the wall.{2}", 
                                beer.Action, beer.Next, nl);
        beerLyric.AppendLine();
    }
    Console.WriteLine(beerLyric.ToString());
    Console.ReadLine();
}

}
}

And COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID. 99-Bottles-of-Beer-On-The-Wall.
AUTHOR. Joseph James Frantz.
*COMMENTS.
******************************************************************
* PURPOSE:
* This is a sample COBOL program to display the lyrics of the
* song “99 Bottles of Beer on the Wall.”
* This version of the COBOL 99 beers program demonstrates a few
* features of COBOL:
*
* 1. PERFORM VARYING, Cobol’s version of a Loop.
* 2. ADD/SUBTRACT with GIVING for math calculations.
* 3. EVALUATE/WHEN, Cobol’s version of Case.
* 4. INSPECT/TALLYING, which finds the number of specified
* characters in a variable.
* 5. Reference Modification:
* Var-name(Start character:Number of characters)
* which is essentially Cobol’s version of text subscripting.
* 6. Long descriptive variable names.
* 7. Use of SPACES and ZEROES for field/display values.
* 8. Highlight the self documenting nature of COBOL.
******************************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Keeping-Track-Variables.
05 Bottles PIC S99 VALUE 0.
05 Remaining-Bottles PIC S99 VALUE 0.
05 Counting PIC 99 VALUE 0.
05 Start-Position PIC 99 VALUE 0.
05 Positions PIC 99 VALUE 0.
PROCEDURE DIVISION.
PASS-AROUND-THOSE-BEERS.
PERFORM VARYING Bottles FROM 99 BY -1 UNTIL Bottles = -1
DISPLAY SPACES
SUBTRACT 1 FROM Bottles GIVING Remaining-Bottles
EVALUATE Bottles
WHEN 0
DISPLAY "No more bottles of beer on the wall, "
"no more bottles of beer."
DISPLAY "Go to the store and buy some more, "
"99 bottles of beer on the wall."
WHEN 1
DISPLAY "1 bottle of beer on the wall, "
"1 bottle of beer."
DISPLAY "Take one down and pass it around, "
"no more bottles of beer on the wall.“
WHEN 2 Thru 99
MOVE ZEROES TO Counting
INSPECT Bottles,
TALLYING Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY Bottles(Start-Position:Positions)
” bottles of beer on the wall, “
Bottles(Start-Position:Positions)
” bottles of beer."
MOVE ZEROES TO Counting
INSPECT Remaining-Bottles TALLYING
Counting FOR LEADING ZEROES
ADD 1 TO Counting GIVING Start-Position
SUBTRACT Counting FROM 2 GIVING Positions
DISPLAY "Take one down and pass it around, “
Remaining-Bottles(Start-Position:Positions)
” bottles of beer on the wall."
END-EVALUATE
END-PERFORM
STOP RUN.

I coded COBOL for 5 years in the late 80’s early 90’s. It’s just a programming language and like all languages works well in some environments and with some tasks and less well with others. Slagging off COBOL for what it is is like an English speaker slagging off Lithuanian just because it’s at the opposite end of the indo-european language spectrum


#187

Don’t go by what someone says regarding whether a language is fading… do a job search and compare it to job searches for other languages. For instance, I just did a search for “cobol programmer” on Monster.com (no locality given) and I got 90 hits. I did the same search for “.NET programmer” and I got 361 hits. “C programmer” got 459 hits, but “ruby programmer” only got 35 hits. Perl got 110 and PHP got 133. Just “Programmer” got 2055.

I guess cobol is fading. Those lines of code must be really good and really old.


#188

Some commenters contrast COBOL with Java, which is supposed to be a modern language, but the tendency I see is that Java has peaked and is declining in popularity. Do not despair, though, Java programmers! Considering the amount of code currently being written in it, Java will be the next COBOL!


#189

Actually, what all these comments say is that IT doesn’t matter. The destested Nicholas Carr was right!

For all that we keep hearing about how IT can be a source of competitive advantage, it rarely turns out to be true. You can search airfares using mainframes and TPF. Or big UNIX servers and C++. Or Linux clusters and Lisp. Doesn’t matter. (These are real examples.)

IT tends to occupy the same percentage of the budget in different organizations. (Not unlike military budgets.) If you find a way to be 10x more efficient at your business-critical processes, then great, your IT staff just gets more time to goof around with non-critical toys that make them happy. It doesn’t, however, allow you to fire 90% of your IT people and pay out the savings as dividends to your shareholders.

COBOL is dead. COBOL is alive. COBOL is ugly. COBOL is beautiful. COBOL corrupts the mind. COBOL promotes good programming. None of this matters. COBOL simply … is. And that’s that.


#190

Neither line count, years in development nor the number of active developers are good measures of the quality of a language. A two-person startup using a modern, succinct language can convey a lot of functionality in six months and a few thousand lines of code.

Yes, there are still some people using COBOL. I bet you could say the same thing about any programming language that used to be somewhat popular at one point in time.

But if COBOL programmers are making good money, that only means there are few of them left. If there were plenty, they’d be cheap.


#191

Hi. great Site, reading it little time ago.
Now respect to cobol (escuse my english, im spanish native), im always wish to learn it (no teach it in university).
Now im working in bank industry, and i see a lot of cobol. I enter this company as Java, javascript, bash, html coder. But i´d been so great, that they ofer me a trainee in cobol. I say yes, and now im learning it. Its not dificult to learn, but like the comments expose here, its a economics move, because theres a few programers, and a big market to work (not so big like web thing, but is better paid and stable-im thinking in to stay in this company a few 10 years :slight_smile: )
I think cobol is not dead, and im moving it to this desert market.


#192

I CAN’T READ COBOL CODE WITHOUT WONDERING WHY EVERYBODY IS ALWAYS SHOUTING.


#193

Back in 1999, I taught a Visual Basic course to COBOL programmers at a large company that handled credit card transactions. This was one of the most challenging groups I have ever taught. These fellows really had a huge mental block when it came to “visual” aspects of VB and event-driven programming. They seemed quite intelligent but they just could not “grok” the concept of visual, event-driven programming. There seem to be some strong patterns in COBOL that render a long-time COBOL coder incapable of making an easy transition to modern languages. I decided it was generally easier to teach VB to a novice than to a long-time COBOL coder.


#194

Cobol is Dead? No one gives a damn? Well it looks a pretty long thread if no-one cares.

Cobol is cool - true you would not use it to write a 1k space invaders … Opps showing my age and first comp there, NO not all COBOL programmers are the wrong side of 40, I think we are the right side of 40. COBOL is a tool, excellent for handling Business Data - without creating the Bloat surrounded by modern data database index’s.

All languages have their place, and I certainly will keep writing COBOL code for as long as the demand exists.


#195

I think the 1 million worldwide estimate is probably right. It may sound like a lot, but compared to the multi millions of C++, Java, VB and .net programmer around.
I also find the 220 billion line of code to be believable. Back in the late 1990, due largely to the hysteria drummed up by “The Millienum Bug” and similar books, the “Y2K Problem” became a priority and everyone who had ever had a COBOL course were put to work studying COBOL source code to find and correct date related elements in the code. I had taken a couple of COBOL courses in the late 1980s’ so I stayed busy for several months doing this.

COBOL is a relatively low level language. It runs “close to the metel”, in other words, it compiles to very efficient machine code, and is easily ported to different processors. It is also the second English like language developed and as such has a 50 year head start over the current crop of modern languages when it come to lines of code written.

As for the wordiness, after you include the declarations, prototypes, constructors and namespace related coding found in modern OO languages, COBOL is not really that wordy by comparison. There have even been several OO COBOL compilers such as Fujitsu COBOL. There is one thing supported in COBOL that I haven’t seen in most modern compilers, Arbitrary precision arithmetic. which operates on a data type known as packed binary coded decimal(packed BCD). This feature of the language makes it particularly suitable for high precision accounting needed by government and large corporations.

Most COBOL programmers were taught the “Top-down” design paradigm which is useful in a batch environment where the program explicitly controls the process. Many had difficulty understanding the basics of an event driven system and even had some problems understanding the terminal services module that was added in the 1992 COBOL standard.

There are some COBOL to C++ translators(as wellas as ranslators for other languages), but they are limited by the math abilities of the target language, often requiring considerable knowlege of both COBOL and the target language and generally produce an inefficient tanslation.

Often I have observed that when someone resorts to the “My ___ is better than your because mine is newer!” type declaration in their comments, it is bscause theylack experience.


#196

Ted - try reading something written in the last 20 years. COBOL has been happily mixed case for at least that long.


#197

Cobol is still around. Tried C# and it also worked for me… BUT I’m still doing my developed products in Cobol, except this time it is in Web Dev (no more green screen!).

Why I do keep on coming back to Cobol? I do not know. It is probably because I could type the codes even when my eyes are closed.


#198

Hi there. I am a Cobol programmer for 11 years now, I’ve started with 22, direct from the university to a multinational company, and had been invited to join an american global company two years ago.
Despite the ups and downs on cobol programmers needs, there are new joiners every year in the age of 20s.
The systems are quite robust and bug-free because the language is very high-level and easy. But the laws change and so do the requirements for business and there lies the need for programmers, not only the old ones that have retired in the last 10 years…
With the idea that only the new languages would survive it was created a gap on new cobol programers, so now we have them all in the ages of 20-30s.
I develop my software in a big portuguese bank, that have several platforms and several levels of programming, but when comes the need to process large deals of information no other language can do it faster and precisely. I do not work on monochromatic screens and I have a mouse, my computer is a real PC with Win software and internet access, the link to the mainframe is made thru an emulator.

So I’m a girl in the early thirties, I am forming youngsters to use the mainframe and the Cobol and I doubt that it could be translated to another language without enormous risks to the institutions and their customers.

Regards, Clara
Sr. Systems Analyst in Financial Services


#199

It’s true that COBOL jobs are going to India, China and the “Philippines”. Where I work, most of the programmers/demand here is for COBOL. What the 1st world won’t do anymore are being done by people from these countries. So you’ll see COBOL programmers as young as 21. When you get to 30, you’re expected to become a manager already and of course your job responsibilities change. As for COBOL is dead or dying, that still really remains to be seen. Our client alone uses Java as front-end and COBOL as the back-end where hundreds of millions of transactions are processed by the system every month.


#200

Whilst everyone seems to be contrasting COBOL and C, I always favoured BASIC amongst the procedural languages. Best one in my opinion is HP BASIC running on servers using the OpenVMS operating system. Easy to use and learn, no garbage collection or memory issues to worry about and code maintenance is very easy. I used HP BASIC to develop a full blown ERP application suite, effortlessly capable of supporting hundreds of simultaneous users. As long as you supply them with continuous power, servers running OpenVMS almost never crash or need rebooting. IBM AS/400 servers running COBOL code have similar characteristics which is why this technology hasn’t gone away. If you look at most of the world’s high volume mission critical applications they all favour these technology characteristics. Here is a link to an HP video which gives you an idea of stuff running on OpenVMS. The video includes a profile of a company which handles processing and distribution of over half the world’s text messaging traffic.

http://h30423.www3.hp.com/index.jsp?rf=sitemap&fr_story=f155197e00e8a915606b1eedddd2008298621394&jumpid=reg_R1002_USEN

Just for fun, here is the 99 bottles of beer thing coded in HP BASIC.

! HP Basic version of 99 bottles of beer
! Created by John Cookson

FOR BOTTLE.QTY% = 99% TO 1% STEP -1%

 IF   BOTTLE.QTY% = 1% THEN
      PRINT BOTTLE.QTY%;"bottle of beer on the wall";BOTTLE.QTY%;"bottle of beer"
 ELSE PRINT BOTTLE.QTY%;"bottles of beer on the wall,";BOTTLE.QTY%;"bottles of beer"
      END IF
      
 PRINT "Take one down and pass it around,"     
 
 IF   BOTTLE.QTY% = 1% THEN
      PRINT " no more bottles of beer on the wall"
      END IF
      
 IF   BOTTLE.QTY% = 2% THEN
      PRINT BOTTLE.QTY% - 1%; "bottle of beer on the wall"
      END IF
      
 IF   BOTTLE.QTY% > 2% THEN
      PRINT BOTTLE.QTY% - 1%; "bottles of beer on the wall"
      END IF

NEXT BOTTLE.QTY%

END PROGRAM