www.nickhodge.com

microsoft, munging and on being a mercurial iconoclastic professional geek.

LOLCODE: Part 4, A New Beginning

with 2 comments

Time to LOLCODE. Watch­ing the for­ums, it’s fun watch­ing the defin­i­tion of a pro­gram­ming lan­guage where the gram­mar is obvious.

And I’ve also thought of a great, quot­able reason to use LOLCode:

Nick Hodge, Enthu­si­ast Evan­gel­ist for Microsoft, recom­mends the invest­ig­a­tion of LOLCODE as Enterprise-worthy Pro­gram­ming Lan­guage if your devel­op­ment pro­ject has a strong require­ment to enter­tain future sys­tem main­ten­ance engin­eers, and your present devel­op­ment team gets LOLCATS humor.” You can quote me on that.

What was not imme­di­ately obvi­ous, another effort is to make your lines of LOL­Code funny. Care­ful choice of vari­able names should res­ult in LULZ.

There were a few occa­sions where I had a peek at the C# source code of the LOL­Code com­piler. It will be inter­est­ing to see how much of the engine that makes the com­piler is taken over by the new DLR, and how hard/easy it is to cre­ate a domain spe­cific lan­guage. The DLR con­tains mainy of the infra­struc­ture pieces, such as cre­ation of abstract syn­tax trees, etc.

Note that these examples com­piled with LOLCODE.Net Build 35, and are based on the 1.2 spe­cific­a­tion.

First pro­gram: Hello World

HAI
VISIBLE “hello world“
KTHXBYE

What’s going on here? HAI is the indic­a­tion of the begin­ning of the lol­code app; KTHXBYE is the end.

VISIBLE “hello world” prints out, well, hello world.

Second pro­gram: Get­ting Input

HAI
    I HASFLUFFYZ
    VISIBLE “ur namez is?”
    GIMMEH LINE FLUFFYZ
    VISIBLE “hello “!
    VISIBLE FLUFFYZ
KTHXBYE

So, what’s going on this time?

I HAS A FLUFFYZ– declares a vari­able called FLUFFYZ

GIMMEH LINE FLUFFYZ– gets some input, in this case from the keyboard

The exclam­a­tion mark at the end of the VISIBLE “hello “! keeps the prin­tout on the same line

VISIBLE FLUFFYZ prints out the con­tent of the vari­able FLUFFYZ. Simple

Third pro­gram: Loop­ing, Conditionals

HAI
I HAS A LIFE ITZ 1
I HAS A OSCARZ ITZ 10
IM IN YR HEADSPIN UPPIN YR LIFE TIL BOTH SAEM LIFE AN OSCARZ
    VISIBLE LIFE
IM OUTTA YR HEADSPIN
KTHXBYE

This code example should work; it com­piles in lolc but neatly stops when run­ning in the CLR. The new parts are the assign­ment of a value to a vari­able (I HAS A LIFE ITZ 1)

Secondly, the line  “I am in your loop increas­ing your LIFE until both-the same life and OSCARZ” is a simple loop with incre­ment and a test.

The “IM IN YR HEADSPIN” is an example/attempt at humor. HEADSPIN is the name of the loop. Craft­ing these names to some­thing funny will provide a future code main­ten­ance geek some LULZ in the future.

Written by Nick Hodge

August 3rd, 2007 at 11:54 am