AlaaShaker's Weblog

// untitled …

Posts Tagged ‘Languages

LOLCode: Who said programming wasn’t fun?!

with 2 comments

LOLCodeLOLCode is a programming language originated in May, 2007, with the aim of adding some fun to programming languages and making the learning process easier.

Take a look at the “Hello World” example in the image on the right. This is more likely to output our usual “Hai World!” statement.
As you see, the program starts at HAI and ends with at KTHXBYE, and that, I guess, requires no explanation! The CAN HAS STDIO? resembles our traditional include or require lines for the standard input/output header file STDIO. To output the “Hai World!” message, the keyword VISIBLE is used, similar to print. BTW is used to signal a comment.

So far, the code looks nice and easy. Things get wilder if you go on with LOLCode. See this example:

   1: HAI
   2: CAN HAS STDIO?
   3:   I HAS A var
   4:   GIMMEH var
   5:   VISIBLE "You said " N var N " !!"
   6:   IZ var LESS THAN 10?
   7:     YARLY
   8:       BTW this is true, execute loop
   9:       VISIBLE "BIG NUMBER!"
  10:       IM IN YR LOOPUP var!!1
  11:         VISIBLE var
  12:         IZ var BIGGER THAN 10? KTHX
  13:       IM OUTTA YR LOOP
  14:     NOWAI
  15:       BTW this is false, so do nothing
  16:       VISIBLE "LITTLE NUMBER!"
  17:   KTHX
  18: KTHXBYE

The previous example starts by reading a number from the user using the GIMMEH variable phrase. The number is declared using the I HAS A variable statement. If the number is less than 10, it prints a message then enters a loop (do-while) that increments the number by 1 until it exceeds 10. If not, it just prints a message. A loop starts with IM IN YR LOOP and ends with IM OUTTA YR LOOP. The word KTHX is a block-closing keyword but it is used here as break if the IZ-statement – resembling the IF-statement – evaluates to true. The UP var!!1 statement is equivalent to var+=1 or var++ in C++. The rest of the code is self-explainable ..

You’d be amazed that LOLCode even has try/catch blocks as in the following PLZ-block:

PLZ OPEN FILE "MYFILE.TXT"?
  AWSUM THX
    VISIBLE FILE
  O NOES
    INVISIBLE "ERROR!"
KTHX

The exception is handled in the O NOES block. The INVISIBLE keyword sends a inner message to the debugger. Moreover, the foreach loops are defined as:

IM IN YR loop WATCHIN YR item IN bukkit-var
  ...
KTHX

LOLCode is a pretty interesting and funny language. The syntax and keywords are created, enhanced, added-to and documented by its community through voting. Check out more details on their website or through their FaceBook Profile.

Written by AlaaShaker

March 11, 2008 at 6:15 am

Posted in Development, Technology

Tagged with ,