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