Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
6  
COBOL's OK for manipulating hierarchical databases or flat files and for pumping data out into big text-only reports on a giant dot-matrix printer. But most data nowadays is in RDBMSs and most managers like pretty reports. COBOL just doesn't handle that so well. –  pdr Oct 7 '11 at 8:27
1  
@Steve314: Yes! Those! Except ours were Line Matrix, and I hadn't had coffee this morning when I wrote that. - en.wikipedia.org/wiki/Line_matrix_printer –  pdr Oct 7 '11 at 9:36
2  
Without single ing out COBOL, if you search a bit, I think you'll notice a lot of domain specific languages are not very popular here (to say the least); COBOL, Fortran, VB6, MATLAB ... all very good languages, just not good for teaching computer sciences and their abstractions. –  Rook Oct 7 '11 at 10:42
3  
@Rook - do those really all count as domain-specific languages? Even MATLAB, IIRC, is still capable of general-purpose programming. I thought DSL mostly applied to things like yacc, lex etc - languages that are only really capable of a fairly narrow task, leading to the other common name "little languages". It never occurred to me that COBOL, Fortran or VB could be called domain-specific. Of course they each tend to be used in particular fields, but I thought they were still usually considered general purpose languages. –  Steve314 Oct 7 '11 at 10:53
1  
@Steve314 - Yes, well - we can say there are two sides. One says the dom.spec. ones are only those you mentioned, the other takes a more general view and counts in the one I mentioned too, while still keeping them in the general purpose category. But practically, wherever you mention engineering and sci. comp. you'll get Fortran or MATLAB, business ... COBOL ... use the terminology which seems most logical to you. I use this one because I find it fits with most people. In any case, they do get a fair share of bashing for some reason from the cs community in general. –  Rook Oct 7 '11 at 11:49
show 2 more comments

10 Answers

up vote 48 down vote accepted

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. 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.

share|improve this answer
5  
+1 For actually knowing what you're talking about. Wish I could give you another +1 for JSP. Did you ever use "Delta"? It was a Cobol generator such that you could write your JSP into the code, in a similar style to the memory definitions (01 - 03 - 05) and then write your Cobol into the gaps. Both fun and frustrating as hell. –  pdr Oct 7 '11 at 8:23
    
Sorry, no - to me, "Delta" referred to a database program (possibly just a front end) on DOS PCs in the mid-to-late 80s. It sticks in my mind because it had this text-mode menu system where pressing Escape would usually take you out one level, but there was at least one case where escape would push you back down several levels, so that in some cases you weren't allowed to back out from a menu-misnavigation, and were forced to try and find a minimal-damage action to perform to get back to the start. Oh - and also a shoot-em-up for the C64 with some nice music :-) –  Steve314 Oct 7 '11 at 8:42
3  
Wikipedia page on JSP - en.wikipedia.org/wiki/Jackson_Structured_Programming. When I learned it, it was all done on paper. –  Steve314 Oct 7 '11 at 9:36
1  
The reason that sorting was treated as a solved problem was that it was. From my recollection, COBOL really discouraged having more than one or two records in memory at a time (the current record and maybe the previous one). 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. –  kindall Oct 7 '11 at 21:10
1  
@NealB I was just clarifying the point for him, since he admits his experience is outdated, even by COBOL standards. I get your point about COBOL85, but there is a lot of old code out there that was either started before it existed, or was written by people who had their heads stuck in a previous version. You really can't assume a codebase is up to 85 standards, but even if it is, it's still an uncomfortable language. Older programmers are retiring quicker than they're being replaced, and very few new programmers want to work in COBOL. I know I wouldn't want to touch the stuff again. –  AgentConundrum Oct 17 '11 at 16:40
show 13 more comments

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.

share|improve this answer
2  
In my answer, I say COBOL is bad for data structures. Is this a difference in what "data structure" means? Maybe the record-layout tools are excellent, but COBOL is still the wrong language for binary trees etc? Or maybe my experience of COBOL was just too old or otherwise limited? Key question - does COBOL have pointers? (Worryingly, a quick Google suggests yes, though my old book suggests no). I'd hate to retract an answer that earned all those lovely rep-points for me, but if I'm wrong... –  Steve314 Oct 7 '11 at 13:31
2  
There's a downside to the decimal arithmetic: you have to say exactly how many digits you want. I remember finding bugs when we had one too few 9s in the PIC clause in some program within a group. –  David Thornley Oct 7 '11 at 16:12
1  
My (uninformed) impression is that COBOL is particularly good at dealing with data in rigid, fixed-size records. Not so good, perhaps, at dynamic data structures. Correct me if I'm wrong. –  Barry Brown Oct 7 '11 at 19:19
    
@Steve314 -- yep pointers came in about 1985 but were a bit lame as you could only set them to stuff in the linkage section. Later versions allowed you to point to anything. –  James Anderson Oct 10 '11 at 1:37
1  
@Structures -- while its not up to Python standards in in terms of hashes and trees etc. Its as good as C or Java -- except its not as good a C++ plus Boost or Java plus the collections Library. Once again the failure to appreciate the value of standard libraries and functions has crippled the language throughout its long life. –  James Anderson Oct 10 '11 at 1:41
show 1 more comment

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

share|improve this answer
15  
Someday they'll discover a vault filled with code written by Dijkstra in languages he denounced. –  jonsca Oct 7 '11 at 7:10
6  
@jonsca - you'll be surprised at what you'll do for money. –  JeffO Oct 7 '11 at 7:20
2  
Incompatible versions was IIRC pretty common until at least the 70s, and even in the 80s there was Basic. Dijkstra was probably making his point based on an issue I mention in my answer - COBOL isn't good for (or meant to be good for) data structure coding. Therefore, for a particular value of "teaching programming" or "teaching computer science", COBOL really is poison. Of course since COBOL isn't intended for that, it's a pretty unfair claim - but then again, IIRC, the context was that some people were trying to teach these things using COBOL. –  Steve314 Oct 7 '11 at 7:51
2  
Dijkstra <- a man who talked too much ... –  Rook Oct 7 '11 at 12:01
2  
@Danny: COBOL was despised well before Dijkstra wrote that line in 1975. –  John R. Strohm Oct 7 '11 at 13:22
show 12 more comments

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.

share|improve this answer
    
I'd heard someone mention banking in passing, which is the only reason I included it, but I'll certainly take your word for it over someone else's. –  jonsca Oct 7 '11 at 7:06
4  
I worked for 20 years in Banking, almost all of it in COBOL. Different banks have done things different ways I suppose. –  TrueDub Oct 7 '11 at 7:52
    
I know of at least one major ERP system that has (or had up to about 2007) a lot of COBOL in it. –  Alan B Oct 7 '11 at 8:39
2  
It was not IBM who designed COBOL. The main instigators were the US Navy and UNIVAC. –  James Anderson Oct 7 '11 at 10:25
6  
"the main aim for IBM when designing COBOL was that it "should allow a bank manager to write a program"." A noble goal, although the vast majority of managers I know can't even write me simple literature for a website, let alone write COBOL. –  maple_shaft Oct 7 '11 at 12:25
show 3 more comments

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.

share|improve this answer
1  
Languages are for users? –  JeffO Oct 7 '11 at 7:23
12  
"Lines of code" is not a good cross-language measure. COBOL is notoriously verbose. Those 5 billion lines of code anually are probably equivalent to seventeen regex'es ;) –  MSalters Oct 7 '11 at 7:52
3  
Sometimes COBOL is the right tool for the job - a lot of times it isn't. The hard part is getting people to recognise the difference. –  TrueDub Oct 7 '11 at 7:53
1  
Quite true, @TrueDub. My sentence sounded a bit salesy, but it wasn't meant to be. –  jonsca Oct 7 '11 at 8:01
2  
@TrueDub: If COBOL is the right tool for a job, I don't want to do that job, as long as I have alternatives. There are far more interesting jobs I can get paid well for. –  David Thornley Oct 7 '11 at 16:07
show 8 more comments

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.

share|improve this answer
    
"lack of support to Windows like interface".... what about netcobol.com/products/Fujitsu-NetCOBOL-for-.NET/overview –  JoelFan Oct 7 '11 at 19:21
    
@JoelFan thanks for your comment. You are correct that today, there are better tools for COBOL but I think that they all have arrived too late. My point regarding lack of if support to Windows interface was bout the beginning of the 90s where only Micro Focus was the only player on the market. –  Emmad Kareem Oct 7 '11 at 19:45
add comment

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.]

share|improve this answer
    
I don't remember either of those - either repression, or I never learned them. A quick search tells me that I certainly agree that ALTER is evil, but this feature is rarely if ever used, so it isn't really a reason to hate COBOL. I'm not so sure about REDEFINES, though. Comparing it with union makes me think a bit more kindly towards it - but maybe what's OK in a low level bit-fiddling and data-structure handling language may not be such a great idea in data processing. –  Steve314 Oct 7 '11 at 10:41
    
Sometimes your answers strike me as dismissive, but this one is just useless. I don't know whether you are trying to help here, but doing it badly, or if you are just talking to yourself. I could ask you what you mean by 'pure evil', but the beauty of the good answers above is that I don't need to start a conversation in order to learn something. –  Eric Wilson Oct 7 '11 at 12:43
    
@EricWilson: Thanks for dismissing my answer so thoroughly. That helped me understand what more needed to be added. –  S.Lott Oct 7 '11 at 13:07
1  
@Eric - the problem with ALTER is that it redirects gotos. First, that means you're using gotos - in itself I don't think that's evil, but in most languages it's an unusual special-cases thing. Second, that means the gotos go somewhere other than where they say they'll go to - and that's just terrifying. I'm not really convinced this is self-modifying code, but it's described as that where I looked, and thinking of it as modifying jump-instruction targets in assembler explains why. –  Steve314 Oct 7 '11 at 13:08
    
@S.Lott Thanks for your additions (you too @Steve314), I learned something interesting, and reversed my vote. –  Eric Wilson Oct 7 '11 at 13:47
show 4 more comments

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?

share|improve this answer
add comment

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!)

share|improve this answer
1  
"Hello World" takes how many lines?. Parsing/generating XML - is now built into the language. Maybe you should be upgrading your knowledge base. This answer belongs to the 1960's era of COBOL. –  NealB Oct 17 '11 at 16:20
    
Interesting. I haven't had to work with COBOL for close to a decade, but that last time I saw it it was written just as I remembered it, IDENTIFICATION DIVISION, WORKING-STORAGE SECTION and all. I guess all those "required comments" (AUTHOR, DATE-WRITTEN, SOURCE-COMPUTER, OBJECT-COMPUTER) are optional now. XML parsing doesn't look that impressive -- you have to structure the data division to reflect the file structure, there's no SAX or DOM-style processing. Good to know it's there, though. –  TMN Oct 17 '11 at 18:10
add comment

Before getting too wrapped up in Gartner, go over to Gartner.com, register a free account, go to the Research tab, and search on the keyword COBOL. You get summaries and a keyword snippet, and you have to sift to find something that really intuits. However, it seems clear that Gartner is quietly pushing businesses to move off COBOL as they appear to see COBOL as winding down.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.