Saturday, June 9, 2007

LOLCODE, messed up language or refined coolness?

I keep running into the word LOLCODE whenever I go into Technorati or Digg, and maybe clicked it a few times but never stayed long to view the whole page. What's crazy about this language is that it's based on the Lolcats Image Macros which is also a derivative of Leetspeak (computer geek language). LOLCODE was created 25 May 2007 by Adam Lindsay with the early versions of Hai World (hello world application), COUNT!!1(a simple loop that counts and displays numbers), and FILEZORZ (file handling code).

Code examples from the LOLCODE website:

Hai World
HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
The code is wrapped by the HAI (Hi!) and KTHXBYE (Ok, thanks, bye! ) delimiters, and the CAN HAS STDIO? is something like the #include or using namespace directives in C++/C#, and lastly the VISIBLE is the printing statement. All this program does is deliver the never-ending "Hello world" but in a cuter and funkier way.

COUNT!!1

HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
UP VAR!!1
VISIBLE VAR
IZ VAR BIGGER THAN 10? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE
We now tackle the new keywords. Variable declaration is done by the "I HAS A 'variablename'" (I have a variable), and the loop is enclosed within the "IM IN YR LOOP" (I'm in your loop) and the "IM OUTTA YR LOOP" (I'm out of your loop) block. Incrementing is done by using UP 'variable' !! 'increment steps', and lastly "IZ 'variable' BIGGER THAN 'number'? KTHBYE" compares the variable with the number of time the loop has to execute, if the statement is true, the program end using the KTHXBYE keyword. This program simply counts from 0 to 10. But I don't really get how the compiler will know what datatype the variable is.

FILEZORZ (Filesource)
HAI
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
AWSUM THX
VISIBLE FILE
O NOES
INVISIBLE "ERROR!"
KTHXBYE
It's interesting to note that LOLCODE has the ability to display files. Although I haven't seen the actually program (and the code itself looks like pseudocode), LOLCODE makes file handling look easy! It starts by doing some file error handling using the keywords "PLZ OPEN FILE "filename"?" (almost like a try-catch block) and evaluates the file status by using the two keywords AWSUM TNX (file exists) and O NOES (oh no! =p ). We know what VISIBLE does, and INVISIBLE writes the sting to the console.

LOLCODE is developing quite a loyal following and is quickly gaining support, hope you too can help develop and contribute useful LOLCODE. Check out the LOLCODE site here!

KTHXBYE!

No comments: