99 Bottles Of IdocScript

There's a great developer site out there called 99 Bottles Of Beer. It shows you how to output the lyrics of the oh-so-annoying camp song in well over 1000 different programming languages.

Woah... 1000 languages, you say? Yes, there are well over 1000 known programming languages, but please keep in mind how developers think. Most of these languages are klunky, impractical, or intentionally impossible to use. These are sometimes called esoteric languages, or even Turing tarpits. Here are some of my favorite bizarre programming languages:

  • Whitespace: no letters, no numbers, no symbols... the only valid syntax is tab, space, and carriage returns.
  • LOLCODE: the syntax looks like something you'd see on a LOL cats poster. I HAZ A BEERZ ITZ 99! IM IN YR LOOP! IZ VAR LIEK 0? KTHXBYE!
  • Piet: just damn pixels on a screen... no letters even!
  • Cow: instead of number and symbols, you only get moOmOOmoOmOoOOM.
  • Brainf**k: trust me... you do NOT want to maintain code written in this language...

Kidding aside, there's a pretty good argument that learning how to print out 99 bottles of beer is a useful exercise when learning a new language. You need to learn the syntax of variables, conditionals, text output, and loops. Not to mention the fact that every language has nuances that can sometimes help you to further minimize your code base, but not sacrifice clarity... there's probably a dozen ways to write it in each laguage, each with different benefits.

So -- seeing how Oracle UCM was being left out -- I submitted the below code to their site. 99 Bottles of Beer, in IdocScript:

<$numBottles = "99", bottleStr = " bottles "$>
<$loopwhile (numBottles > 0)$>
	<$verse = numBottles & bottleStr & "of beer on the wall,\n" &
		numBottles & bottleStr & "of beer!\n" & 
		"Take one down, pass it around,\n"$>
	<$numBottles = numBottles - 1$>
	<$if numBottles > 0$>
		<$if numBottles == 1$>
			<$bottleStr = " bottle "$>
		<$endif$>
		<$verse = verse & numBottles & bottleStr & "of beer on the wall!\n"$>
	<$else$>
		<$verse = verse & "no more bottles of beer on the wall!\n"$>
	<$endif$>
<$verse$>
<$endloop$>

Nifty, eh?

Naturally, there are multiple ways to do this... you could use resource includes, localization strings, result sets, etc. But that's part of the fun of learning a new language. I'll leave it as an exercise for my audience to make it better.

I do hope though that this

I do hope though that this was not meant to advertise Oracle UCM. 'Cause looking at it sure hurts. Anyone remember jelly script?

nope...

just trying to make sure that the site 99 bottles of beer is fully represented ;-)

just to be clear... Oracle UCM is written in Java. However, on occasion it uses IdocScript to generate HTML, or to manage internal logic. Sometimes Java is a little too inflexible, and all other scripting languages were too unsafe or too obscure. Rolling your own language isn't hard -- just ask Joel Spolsky about Wasabi -- and it allows you to inject flexibility into an application in ways that off-the-shelf languages cannot.

sub post

This is a great example of how every programming language has the same fundamentals and everything else is just syntax.

A buddy of mine was working on a website and he asked me "hey do you know ____________"?

I said "No, but how hard can it be, a loop's a loop, an if's an if"

Ten minutes and two Google searches later we had his page working.

Now I should tell him to redo it in Brainf**k

my thoughts exactly...

Most Turing-complete languages have the same general form... after you know 3 or 4 languages, its pretty easy to pick up new ones.

The power of each language is not in the syntax, but rather in the libraries. Is it easy to do what I want to do? If so, you can fairly easily work through syntactic differences.

If you must redo it, I suggest a port to LOLCODE. At least its fun to read...

Nothing like coding a drinking game

I never thought I'd learn so much, from so little, so fast.

Thanks!

Recent comments