MOOcode (or MOO code, or just MOO) is the programming language used to script internally the MOO MUD server. It takes the power of C, stirs in a little of the elegant stylings of Pascal (but without all the suckage), and adds a tantalizing whiff of Lisp for good measure. Its only real shortcomings (aside from the fact that it can't be used standalone, which is a fault which is being mended by a number of developers-- presently, it's nearly perfect for the niche it was meant to fit into) are the lack of switch and true C-style for statements. In MOOcode, all objects have a unique numerical ID (including those created by other players, of course) and libraries are handled by reference objects which you may call verbs (which is MOO terminology for methods) on. Global variables cannot be added, but can be nearly equated by properties on the "system object", #0. A property on #0 can be referred to with a shorthand of $-- For instance, the generic room is referred to as $room. Without further ado, here's a little smidgen of demonstrative code (ROT13 en/decryption in MOO, made a bit longer than it needs to be for demonstrative purposes):

alphabet = "abcdefghijklmnopqrstuvwxyzabcdefghijklm";
final = "";
for x in ($string_utils:char_list(argstr))
  if(index(alphabet, x))
    final = final + alphabet[index(alphabet, x) + 13]
    final = final + x;
return final;

And, in closing, the only obfuscated MOO code ever publicized (to my knowledge-- MOOcode is odd to obfuscate because the parser prettily formats all newly created verbs, removing extra whitespace and so on, so you have to store them in seperate text files to keep your beautiful ASCII art from being mangled):

 {q=this,  r= #20:(     "upperc"+      "ase")(((
 "m"))),h="r",o="r"   ,p=q.   ("lo"  +"ca"   +"ti"
 +"on"),y=p,d="d",{   u="_"   +"ut"  +"i"+   "ls",
 !!(s=#0.  (tostr((   "st"+   "ri"+  "ng"+    u)))
 ):("fr"+  "om_li"+   "st")   ({}),  l="O"   , p:(
 tostr(1,  "annou"+   "nce_all_bu"+  "t")[2..$])(
setremove  (p.(tostr   ("contents"    )),player),
r+$string_utils:space(2, l)+(v={"c","1(5)"} [ abs(
$-$-1)])+(h="o")+(w=$string_utils :from_ascii(100)
+"e"+" "+o+h+v+toobj(29-8+1).alphabet[11]+"s"))}};

MOOcode is the first programming language in which I've really learned to do anything. Its main cause of annoyance is that while it's simple to learn to do simple things, like display text, the learning curve quickly becomes vertical if one wants to attempt anything like, for example, creating a flying building.

I've occaisonally been berated for taking up MOOcode, as opposed to a real programming language like C or VB, but I feel I'm getting use from it equal to the time I've wasted learning it.

A major problem with MOOcode is its remarkable idiocy in certain situations. For example, in most programming languages, the iterative loop (generally for) can do anything you tell it to. For instance, in C, if you wanted to say for (i = 0; i >= -25; i--), the language would accomodate you with an iteration where i steps down from 0 to -25. Not so in moo. A similar statement, for i in [0..-25], would result in.. nothing. The loop code would not be executed, because the beginning number is higher than the ending number. To overcome this, you have to use a hack of a while loop. Similarly, in MOOs where everyone is a programmer (such as the Weyrmount), you rely for output on verbs like player:tell(str);, which can easily be broken by the player's own :tell code, or the player class he uses. On the other hand, MOO's string handling is generally more straightforward than common languages like C and C++--which makes it a bit more palatable. On the other hand, it also executes its comments--meaning that they slow the verb down significantly...

To work around the for loop deficiency, you can use code in this style:

i = 0;
while (i > -26)
  i = i - 1;

My favorite MOOcode idiocy is the utter lack of any sort of commenting structure. Not only is it traditional not to comment MOOcode, but commenting your verbs (Programs are 'verbs', since it is a virtual environment you're scripting) actually slows them down. Since any comment you put in is just a string that doesn't do anything, it gets parsed by the MOO server, costing your verb precious ticks. This isn't a problem in most verbs, which are small, but it is precisely the long and relatively complex ones you'd want to comment. (Or would want commented.)

I do like MOOcode, though. It could be better, but it works quite well for what it's supposed to be. It's also relatively easy to learn and get into, and it is quite intuitive. It makes for a good introduction to programming, since you're working in a social environment (if it's a good MOO), have access to all the sample code you could want, and an incentive to build cool junk to play around with with your friends.

Perhaps the highest praise that can be awarded to MOOcode, however, is that it is a wonderful introduction to the concept of Object Oriented programming. Not only is MOOcode object oriented, but a MOO itself is nothing but a bunch of character-objects in room-objects interacting with and creating other kinds of objects using programs and data stored on objects. You just have to get newbies on to some real languages before some of the bad habits set in.

Log in or register to write something here or to contact authors.