55

When people mention COBOL, it's usually either met with a snort or groan. I don't know much about COBOL, but I've seen some programs written in it. I can see that it's wordy, and to uninitiated eyes such as mine, unintelligible. But, really, aren't all programming languages complete gibberish to a lay person?

I understand that it works, works well, and is still in widespread use in the industries it was designed for. Aren't those the hallmarks of a good language? What's so bad about COBOL?

JSBձոգչ
  • 1,440
Barry Brown
  • 4,095

9 Answers9

68

COBOL was one of the first languages I learned - if you ignore countless versions of Basic, three or four assembler languages and a variant of Forth, then it was in my first five, and learned concurrently with Pascal. IOW, I'm answering from personal experience using the language.

EDIT I should say ancient experience. I never used the language after the end of the 80s, though I did buy a new book (to replace the old one I threw away in disgust) so that I had something to refer to so my horror stories wouldn't get too distorted. But I have no idea how the language has evolved in at least the last 20 years.

Obviously, for many people, it is just that "old is bad" view that jonsca has already described - and also much more a third-hand pass-me-down attitudes thing. But there are real issues underlying that.

Being too wordy is a real problem - there's too much clutter in the way of understanding the code. This is by far the biggest issue. People who look at the MOVE, ADD and MULTIPLY etc statements in horror have a slightly exaggerated view of this, true - the COMPUTE statement is closer to the assignments in other languages. But there's still a lot of clutter in all those divisions and sections. One of the first things I learned in COBOL was to always start by copying a standard page-of-A4-long SKELETON.COB.

COBOL does have some interesting features, but those features (e.g. the PIC thing) tend to be things that are now more part of the DBMS rather than the programming language, and that seems to me to usually be a better way to separate those responsibilities. Also, some libraries in other languages use something comparable to PIC (e.g. printf and scanf in the C standard library). Arguably, the best has been kept, but the worst dropped.

Also, for every nice feature, there was at least one intolerable one. For example, no matter how trivial a loop is, you have to move the body into a separate procedure. The PERFORM ... UNTIL ... and similar statements are single statements - not block structures. In a sense, COBOL was a taste of structured programming from before structured programming was invented - there was a GO TO, but it's use was discouraged (at least when I used COBOL), but looping in particular just wasn't handled that well.

In fact, the language that I used after COBOL that most reminded me of it was... dBase. As in Ashton-Tate dBase III+. These days, people are more likely to remember all the now-dead-or-dying clones (Clipper, FoxPro etc) that led to the generic name xBase - and there is still a living descendant in xHarbour. The point is that these were database languages, but nothing like SQL.

Even then, where every COBOL program operating on a particular database needs to include a copy of the specification of that database (and the copies could end up inconsistent), that isn't really the case in xBase where the database knows it's own structure.

Taking that into account, then, COBOL is not so terrible if you accept it for what it is. But what it isn't is a language for writing data structures. Which may be why COBOL suffered a lot back in the times of the C vs. Pascal holy wars - both sides could agree that COBOL was no good for reinventing the binary tree yet again.

Oh - and one thing I'll never forget is how my first COBOL textbook didn't describe the SORT command, saying that it was outside the scope of the book - apparently, either the author couldn't cope with the idea of sorting, or considered it to be more than the tiny little minds of COBOL students could cope with [see edit at end]. That kind of thing made it very difficult to take COBOL seriously.

An odd aspect of this was Jackson Structured Programming, which I also was forced to learn at around the same time, and specifically for use with COBOL. Part of this was drawing a structure diagram for the input, then a structure diagram for the output, then drawing the in-between structure diagram for the code. Sorting was clearly expected to be an already-solved problem - you couldn't derive a sorting algorithm in this way. So it was odd to be told by the recommended text-book that the whole concept of sorting was beyond my tiny little mind, while at the same time being taught something like a dozen different sorting algorithms and how to implement them in Pascal.

The problems that JSP can handle are probably a good guide for the things that COBOL can do relatively well. But even then, that doesn't necessarily mean that either JSP or COBOL are good ways to handle those problems.


EDIT on 30th July 2014

I just got a reputation boost from this, reminding me it's here. As it happens, due to some nostalgia-fueled ancient book collecting, I can now correct a point WRT the SORT command.

The book I originally used as the recommended text when learning COBOL was "Methodical Programming in COBOL" by Ray Welland. This doesn't cover COBOL 85 (though there was a later edition "Methodical Programming in COBOL-85" which I've still never seen).

kindall comments below that "You were supposed to sort the input files before reading them, or sort the output file after generating it, using the sort utility that came with the OS". From my reply to that, I missed the "came with the OS" point. Kindall was suggesting something akin to the Unix philosophy AFAICT, with COBOL used for the bits it's good for, OS utilities such as a sort utility used for some other things, and presumably using a batch/scripting/shell language to glue the bits together. This makes much more sense in an ancient world where interactive software was rare to non-existent, so you'd be submitting batches of work (hence "batch language") anyway.

The following is quoted from page 165-166 of "Methodical Programming in COBOL"...

The use of ordered serial files implies that it is necessary to have a means of sorting records within a file into some specified order by key. Most larger computer systems have a sort utility which will sort a file given the position, type and size of each of the data-items forming the key.

There is also a facility for sorting records from within a COBOL program but this is beyond the scope of this book for two reasons:

(a) the interface to the operating system is often quite complex and varies from system to system,

(b) the sort module is an optional part of ANS '74 COBOL and may not be implemented in COBOL systems for smaller computers.

Therefore it will be assumed that facilities exist for sorting files into a specified order and the problem of updating such files will be considered.

In short, kindall is correct - the assumption was that usually sorting would be done outside of COBOL. There may even have been a real justification to excluding sorting from a programming language around 1974 for small computers.

What I said above was basically what you get after around 20 years of not being able to check facts due to throwing away the book.

I should still point out, though, that I formally studied COBOL from this recommended book that covered the 1974 standard (not the 1985 standard) in 1988 and 1989. The third edition of "COBOL for Students" (Parkin, Yorke, Barnes) - the first edition covering COBOL 85 - wasn't published until 1990. I'm not certain, but I think the COBOL 85 edition of "Methodical Programming" wasn't published until 1994.

But that doesn't necessarily represent the COBOL world dragging its feet - well, not that much anyway. New standards adoption takes time for any language, even now.

46

Having spent most of today writing some COBOL I think I can give some current input.

First the BAD stuff:-

  • No function calls. Modern COBOL has some built in functions but its a serious engineering job to write your own.
  • No type checking on subroutine calls. You can pass (or not pass) anything on a subroutine call, the called subroutine will blithely assume it has the correct parameters, and, there is no way to detect missing or invalid parameters.
  • No libraries. None zero zilch. No standard libraries, no widely used easily available libraries. You end up coding commomplace tasks by hand over and over again.
  • Everything is implemented as a keyword. Because the language authors don't have the concept of a library every new feature ends up being implemented with new keywords e.g. PARSE and RENDER for XML support.

The misunderstood, i.e. those criticisms commonly leveled against the dear old language which are invalid or irrelevant.

  • Verbosity. So you type a few extra characters! Its not a serious issue. In many cases COBOL is less verbose than say Java.

  • "COBOL FILES" You see this term bandied around a lot. There is no such thing its just that COBOL can handle just about any file format and just about any file organization.

  • No multi-threading. In the environments where COBOL thrives, multi-threading is usually left to application containers like CICS or IMS which are good at it, rather, than programmers who tend to be bad at it.

And the good stuff - some aspects of COBOL are superior to other languages:-

  • Data structures. COBOL has a concise and flexible syntax for defining complex data structures and odd data types.
  • Decimal Arithmetic. It has native support for decimal arithmetic i.e. arithmetic as understood by accountants, with proper rounding etc.
  • Moving with the Times. Some aspects of COBOL are surprisingly modern. Built in XML support, support for OO programing, the ability to use Java classes etc.
  • Integration with DB2,CICS etc. This only applies to IBM's mainframe COBOL (but that is by far the largest chunk of COBOL still running) but the integration with DB2, CICS and other mainframe environments make it easier to code up things like data base backed web services than in any other environment.
  • Screen handling. The standard screen handling as implemented on AS/400 and MicroFocus Cobol is excellent.
  • Performance. For many years COBOL compilers have been producing very high performance executables. Only native C and native Assembler beat COBOL on an IBM mainframe.

So all in all its doing quite well for something that was put together by a committee in the 1950s. If an existing application is implemented in COBOL and does the job there is no reason to re-write it. However unless there is a really good reason I don't see any justification for new projects to use COBOL.

27

This is probably down to Djikstra. Djikstra stated that "The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense." Cobol was viewed as naive, unstructured and verbose. With the ability to self-alter code (a practice discouraged even among cobol programmers) it was viewed as quite difficult to debug or follow too.

Then there is the matter of great incompatibility between versions too.

I would suggest reading the criticism and defence section in Wikipedia for the language - http://en.wikipedia.org/wiki/COBOL#Criticism_and_defense

9

It's age and verboseness are typically the things that make people groan about it.

I seem to recall that the main aim for IBM when designing COBOL was that it "should allow a bank manager to write a program". This goal obviously had a profound affect on the way the language was designed, and it now it evolved.

Apparently there's more COBOL out in the wild than any other language. However, after working in IT for almost 20 years (15 in banking) I've never encountered a single system that was implemented in it.

Sean
  • 1,134
8

What's so bad about COBOL?

Nothing.

I think people have a preconceived notion that old is bad, "newest is bestest". It's still very much in use, and I'm sure there will be enough maintenance work on code to be had for another half century.

In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually. (via wikipedia)

In coding, one must always select the best tool for the job, and with certain industries that are married to certain hardware, the language is optimal. I've never worked in banking, where I had heard it was popular, but Sean's answer indicates this isn't the case.

If there's a problem with legacy code looking old, as long as you can slap a UI or a web interface in front of it, most users won't even know the difference.

jonsca
  • 585
5

People dislike COBOL because it has limited application. It was designed for business, finance, and administrative systems for companies and governments.

What do all of these have in common? Data. Lots and lots of data.

Guess who was designed to crunch data and have lots of files for breakfast? Can you say COmmon Business-Oriented Language?

50 years ago COBOL was the best thing for large organizations with lots of data to manage. Today there are better ways to manage a large volume of data so COBOL is no longer relevant. Or is it?

Let's consider governments. What data does a government need to track? People ids, birth certificates, medical records, taxes (oh... yes... taxes) etc etc. And they must hold these infos indefinitely, today and 50 years ago also.

People also mnetioned banks in some of the answers and indeed banks are heavy user of COBOL. Why? because unlike other types of companies banks usually have a history. Some exist for hundreds of years (like this one for example).

That means that some data from 50 years must still be here with us, today, the 7th October, 2011. Now we have SQL Server and C# or Oracle and Java, but 50 years ago there was COBOL and files.

As time passed the data for govs and banks grew larger and larger and it was more and more expensive to migrate the systems. Which means they must remain in COBOL and be constanlty maintained and evolved as business evolves. Some banks are slowly migrating while other just stick a nice Web2.0 interface in front of the mainframe (c# and Java are the mostly used). Can you say legacy code? (COBOL goes hand in hand with (extreme) legacy code, some that was touched by plenty of people over decades of existence - another thing we programmers don't like :D).

And now you have a niche of activity. COBOL now has limited application and your experience is affected.

And people who get into COBOL eventually discover that you do the same thing over and over and over again, year after year after year and by the time they wake up they are no longer competitive on the market because people now want PHP, Java, C#, REST, jQuery and only banks look for COBOL people.

At this point the demand is lower than the supply and those who don't make the cut must move to something else. And they must start as juniors since COBOL does really cripple the mind (believe it of not Copy-Paste is the main style of development in COBOL and accounts for large its large productivity) and now they curse the day they picked up COBOL and don't lose any occasion to tell their horror stories about it :). But you could tell those stories about any old fart language that is no longer in demand these days but you are the unfortunate person stuck with it. O well...

P.S. and COBOL is bad for all the other reasons mentioned by the others :)

P.S.2. In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually. Really? And how did day measure that? Did they go do every company in the word and ask them how many lines of COBOL do they have or what?

4

Two features.

  • The ALTER statement is pure evil. While rarely used in more modern COBOL applications, it was heavily used in the "olden days" because it was more efficient than the equivalent "IF-GOTO" structure. When computers only had 32K of RAM, each instruction mattered. It modified a GOTO statement to have a different destination.

    This made some code opaque because the code itself was stateful.

  • The REDEFINES clause in a data structure (like the union in C) is a perpetual problem. The term "free union" -- i.e., overlayed data structures without a discriminator -- is a way to summarize the problem. Two REDEFINES aliases cannot be trivially distinguished by the data; only extensive reading of program logic could determine the meaning of the two alternate interpretations of the bytes.

    This made many data structures opaque because the data cannot be understood without the code.

The readability of the English-like syntax was defeated by these two constructs.

[I've been warned by moderators that short answers are dismissive of your important and interesting question. If you find this dismissive, you could ask for details. Or flag it so that the moderators can delete it.]

S.Lott
  • 45,522
  • 6
  • 93
  • 155
3

I have programmed in COBOL for several good years. Its syntax is simple compared to today's languages and you don't need to much theory to learn to get going. COBOL worked very well with IBM's CICS (an on-line transaction management system) and the programmer needs to do noting in the code to scale the application number of users from 1 to several thousands. CICS provided a character based GUI that worked with a screen as a unit of display (no windows). You could display charts using (IBM's GDDM) on the mainframe. COBOL can talk to indexed files (VSAM and ISAM) as well as DB2 (SQL based relational) and also IMS. COBOL/CICS is a very robust environment and you can learn it in few weeks. That means you focus on the business not on the technology, so you work 7 out of the 8 hours on coding not at learning MVM, JavaScript and the like.

The issue with COBOL is bad marketing that lead to lack of interest from 3rd parties to develop tools and programming environments for it. Also, its lack of support to Windows like interface caused its popularity to decline after 1993. The mainframe cost lead customers to look for alternatives and compilers for COBOL was available in UNIX and DOS. The C language drew much of the light as it was able to be more portable and had direct access to OS functions which is something COBOL had very little of.

Languages like VB, DBase,FoxPro and Clipper had better ways to access 'databases' on the PC than the comparable COBOL on DOS so COBOL lost. CICS was not made cheap on DOS or UNIX for a long time, so its value was not present on these environments.

Today, COBOL is supported with .NET but I guess that it has lost the battle on all platforms except the mainframe (and possibly AS/400) where it is still there because of the huge number of mission-critical applications that are fully dependent on it.

NoChance
  • 12,532
2

Heh, I went to college in the early 80s, and people were scornful of COBOL even back then. I think the biggest problem is its verbosity -- a simple "Hello, world!" in COBOL is probably over fifty lines, 95% of which are required boilerplate. It's just not a very elegant or attractive language. It was also designed to handle yesterday's problems, and doesn't really lend itself to development paradigms developed after about 1970. It's a pretty good report generation language — as long as your reports are endless columns of numbers with headers and footers. If you want to stick in a graph or a logo somewhere, forget it. I think it's still the fastest language for "data processing"-type tasks (take a fixed-format file with 5M ATM transactions and do a simple balance adjustment for each one), but how many developers do those kinds of things any more? And lots of systems use XML or JSON nowadays, I'd hate to think about trying to parse anything like that with COBOL (actually, I'd hate to think about parsing in general in COBOL!)

TMN
  • 11,383