This time of year, even the most hard-core geek thinks thoughts of festive cheer. And there's nothing like, oh, say, a beer, to enhance the mood of seasonal glee. And after a few beers comes the song.
"99 bottles of beer on the wall, 99 bottles of beer" ... .
Hic ... .
Oh — sorry — where was I?
What, you ask, does such a scurrilous ditty have to do with serious developers? Well, nothing — except that it was the vector for an entertaining and informative experiment in programming.
In early 1994, the story goes, someone posted the full lyrics, down to the last bottle on that busy wall, to a humor list. A perceptive reader then noted that the post was unnecessarily long, and the lyrics could have been generated by a scant half-dozen lines of BASIC code.
And here they are, as shown on http://www.99-bottles-of-beer.net/info.html:
10 REM BASIC Version of 99 Bottles of beer
20 FOR X=100 TO 1 STEP -1
30 PRINT X;"Bottle(s) of beer on the wall,";X;"bottle(s) of beer"
40 PRINT "Take one down and pass it around,"
50 PRINT X-1;"bottle(s) of beer on the wall"
60 NEXT
However, the tale goes on, the BASIC poster made the mistake of slighting C++ programmers, and one Tim Robinson remedied the situation, offering his own version of the tune in C++.
You can imagine what happened. Countless other programmers sent in their takes on the problem, and Robinson posted them on a Web page of his own. He started with 20 languages, and by 1998 was up to 227.
Robinson's pages disappeared from the Web in 2001. But by then, Oliver Schade, European IT Project Manager for eBay International AG in Berlin, had begun mirroring the pages on his own Best of Internet site, and he now runs http://www.99-bottles-of-beer.net/. The list is up to 864 languages (I'll bet you had no idea that a loop could be expressed in so many ways!), and Schade has been joined in managing the site by computer science students Gregor Scheithauer and Stefan Scheler.
The languages run the gamut from 1C Enterprize to ZZT (created, I'm sure, to cap the penultimate entry, ZT, by prolific contributor Philipp Winterberg), with stops between in anything from COBOL and Pascal to Haskell and S.
The code for each language can be rated by visitors on a five star scale, ranging from one ("Bad as Hell") to five ("Top Geek").
What makes a Top Geek? Visitors granted that accolade to Mark Hurd's implementation in DotLisp:
(def-macro (prnf f &rest r)
`(Console:WriteLine ~f (vector-of Object. ~@r)))
(for (i 99) (> i 0) (-- i)
(prnf "{0} bottle{1} of beer on the wall
{0} bottle{1} of beer
take {2} down and pass it around
{3} bottle{4} of beer on the wall\r\n"
i
(if (== i 1) "" "s")
(if (== i 1) "it" "one")
(if (== i 1) "no more" (- i 1))
(if (== i 2) "" "s")))
They also liked an anonymous contributor's WordPerfect for Macintosh macro:
Assign (Var01;99)
Repeat
Type Var (Var01)
Type ( bottles of beer on the wall. )
Type Var (Var01)
Type ( bottles of beer. )
Type (Take one down, pass it around. )
Assign (Var01;Var01-1)
Type Var (Var01)
Type ( bottles of beer on the wall.)
Hard Return
Until (Var01=0)
But the ultimate Top Geek award in ratings so far went to Andrew Savige, whose incredible Perl script actually looks like a line of beer bottles.
Aside from being a heck of a lot of fun, 99 Bottles of Beer shows ways of writing code that most of us have never dreamed of, and demonstrates how different programming languages can be. Some variations are a few lines long, while others take dozens of lines of code to do the same thing (then there's the outrageous — but long — singing version in Builder, and the "Chef" version that is actually a recipe for beer).
Despite there being 864 languages already represented, the site team is looking for more. If, after exploring, you find an omission, write your own beer loop and submit it at http://www.99-bottles-of-beer.net/submitnewlanguage.html.
It's not as — er — intoxicating as the real thing, but it's easier on the liver.
|