More Monkey Business

This is a follow-up to Monkey See, Monkey Do, an experiment in computer language lucidity which looked at implementations of the eponymous program in English, Groovy, Perl and Java.

I have received some contributed monkeys: today we’ll look at Ruby Monkey and Python Monkey.

Ruby Monkey

Ruby monkey quite arguably ought to have been included in the first troop of monkeys. “Ruby” is the word most likely to follow the word “like” when Groovy programmers are talking about Groovy to programmers who have never heard of Groovy. Ruby is Payton Manning to Groovy’s Eli. So without further ado, here is the Ruby Monkey contributed by Jason Felice:

monkey = Monkey.new
monkey.see.each{ |action| monkey.do action }

This monkey is quite similar to the Groovy Monkey, but of course there are some differences. Let’s anglicize this gem of a primate:

Monkey is monkey new.
Monkey see each action, monkey do action.

I’ll admit I may have taken a little poetic license with the placement of the comma in the second line, but I think it was worth it. This is eminently comprehensible as English. In fact I’d have to say this monkey edges past the Groovy monkey and vies with the Perl monkey for the title of Most Lucid Monkey.

Ruby Monkey Guts

Jason’s implementation of this monkey is very similar to the Groovy and Perl monkeys:

class Monkey
  def see
    ["scratch", "climb", "eat banana"]
  end
  def do(action)
    print "Monkey does #{action}\n"
  end
end

All in all, very nice. Of course Ruby monkeys have another nice feature: they can be taught! Let’s teach Jason’s Ruby monkey a new trick. Take a bow, monkey!

class Monkey
def bow
    print "Monkey takes a bow\n"
  end
end

monkey.bow

Python Monkey

This monkey was contributed by Bob Griffin.

monkey = Monkey('lulubelle')
[ monkey.do(action) for action in monkey.see() ]

Bob informs me that “monkey” is one of his favorite variable names. He uses “monkey” when other programmers cling stubbornly to “foo.” He also apparently prefers his monkeys to have names. So let’s see how Lulubelle sounds in English:

Monkey is monkey Lulubelle.
Monkey do action for action in monkey see.

Wow! That’s a totally different grammatical formulation! It almost sounds something like “Monkey does what monkey sees.” Obviously, Lulu marches to the beat of a different drum, preferring not to ape her counterparts from other languages.

Python Monkey Guts

class Monkey:
  name = ''
  def __init__(self, name):
    self.name = name
  def action(self, verb):
    print self.name + ' ' + verb
  def eat(self):
    self.action('eats')

  def sleep(self):
    self.action('sleeps')

  def scratch(self):
    self.action('scratches')

  def see(self):
    #array returns functions not strings
    return [self.eat, self.sleep, self.scratch]

  def do(self,fn):
    #functions are passed as 1st class variables and then run
    #Notice ’self’ does not need to be prefixed as the address of
    #the monkey instance’s function was passed
    fn()

This Python Monkey seems pretty verbose. This is partly because she has distinct methods for each of the things that the Monkey can see. But notice the difference this makes possible: other monkeys are technically seeing strings which represent actions. It’s almost more like “monkey read, monkey do.” But this Python Monkey sees methods; so Lulubelle is literally “seeing” the action which she then does herself.

Python monkeys obviously have a unique take on solving problems. Some say they can’t adhere to a spec. But Python Monkeys generally have a clear objective in mind, and they end up with some very interesting results.

Stay tuned: Jason’s Haskell Monkey and Scheme Monkey are up next!

Monkey See, Monkey Do

I’m learning a new programming language these days, and got to thinking the other day about the lucidity of programming languages relative to English: given a simple program, how easy is it to read and understand? So I have devised a simple program which I have rendered in four languages: English, Groovy, Perl & Java.

English Monkey

Whenever a monkey sees an action, he does the same.

Short, sweet and to the point. This English monkey will be our baseline for evaluating the lucidity of other monkeys. Note the basic parts of this program:

  • the declaration (”…a monkey…”)
  • the iterative loop (”Whenever…”)
  • the set being iterated upon (”…sees an action…”)
  • the operation for each iteration (…does..)

Also note the use of pronoun (”he”) and reference (”same”). Clearly English is a language which has and relies upon a sophisticated sense of context.

Groovy Monkey

def monkey = new Monkey()
monkey.see().each { monkey.does(it) }

Nice. This Groovy program almost reads like English. In fact, let’s transliterate it to English:

Def monkey is new monkey. Monkey see each, monkey does it.

That’s downright comprehensible! I like Groovy’s use of the pronoun it. That’s very English-ish. I’m not sure “Def monkey” really does make sense, but it sounds kinda urban and hip.

Perl Monkey

my $monkey = new Monkey;
for ($monkey->see) { $monkey->do($_); }

The Perl monkey program is similarly terse, and arguably even more lucid than the Groovy version (assuming you can get past all those crazy sigils!). Let’s transliterate into English:

My monkey is new monkey. For monkey see, monkey do.

Whoa, that is catchy! That terribly punchy ending is made possible, in part, by the fact that Perl lets us reuse the “do” keyword, whereas Groovy does not (nor does Java). On the other hand, that pronoun “$_” really doesn’t have a comprehensible English counterpart. Happily the power of English expression leaves the whole thing perfectly lucid if we simply drop it.

Also, note the possessiveness in this program: it’s not just any monkey, it’s my monkey. Perl monkey implementers quickly learn to label everything that belongs to them so that other Perl monkeys don’t come in and just grab and use them as global variables.

Java Monkey

import java.util.ListIterator;

Monkey monkey = new Monkey();
ListIterator see = monkey.see().listIterator();
while (see.hasNext()) { monkey.does(see.next()); }

I’ll say this: Java monkeys leave nothing to chance. For this program I’ve chosen to bring in a useful tool. Some would say that the fact that Java monkeys use tools early and often is a mark of their intelligence. But in this case it just means that using a tool seemed a lot easier than writing the program with the stuff which comprises the Java language itself.

But how does it sound transliterated into English? Kinda like Vogon poetry:

Import java util list iterator.
Monkey monkey is new monkey.
List iterator see is monkey see list iterator.
While see has next, monkey does see next.

What kind of creature could listen to that and not be wracked with pain? It’s florid, murky, and verbose. Sometimes it’s downright misleading! And I could almost endure all of that if not for the occasional use of catchy alliteration which makes it seem like the author is actually saying something meaningful, stomped out in a tribal tattoo: “monkey monkey is new monkey.

Far from using any sense of context, Java monkeys must eschew pronouns, and must often overstate matters, repeating themselves for emphasis: “list iterator see is monkey see list iterator.” I like programming in Java, but when I see it in English, I have to admit it’s absolutely horrible.

How To Implement a Monkey

Obviously each of the above examples assumes that all participants in the context know what a monkey is and where to get one. Without that knowledge, none of them will work. So let’s not just fling.do() at all that messy complexity. Let’s see what it looks like to get an actual monkey in each of these languages.

English Monkey Guts

Don’t make a monkey of yourself. Instead, go to a reliable supplier of monkeys such as a rainforest, zoo or monkey farm, and pick out a nice monkey. Preferably the monkey should be intelligent enough to be trained, but not so intelligent that he innovates. He should have all the normal faculties typical to monkeys in good working order (in particular, eyes, hands, limbs, etc.).

Nobody’s going to argue that English has no expressive power. In fact it’s the baseline for expressiveness for this experiment. But as with many expressive languages, with great power comes great responsibility. While it may seem that the English monkey completely flubs the terseness test, bear in mind that it is far more difficult to get a monkey using English than it is in most computer languages. And as the program itself powerfully implies, making a monkey using English is practically impossible.

Groovy Monkey Guts

class Monkey {
    def see() {
        ["scratch", "climb", "eat banana"]
    }
    def do = {
        println "Monkey does ${it}"
    }
}

Once nice thing about (most) programming languages is the ability to create highly specialized monkeys, designed for specific functionality and which therefore omit many of the behaviors commonly associated with monkeys. An English monkey almost always has other methods, traits, and event handlers that aren’t pertinent to whatever it is you’re trying to get the monkey to do. It gets to the point that when you ask an English monkey to do something, you don’t know what’s going to happen.

But this monkey is a Groovy monkey, and only really does two things: he can see, and he does.

Perl Monkey Guts

package Monkey;

sub new {
    bless {}, shift;
}
sub see {
    ("scratch", "climb", "eat banana");
}
sub do {
    $self = shift;
    print "Monkey does $@_[0]\n";
}

The Perl monkey, like the Groovy one, is far more concise and focused than the English monkey. However, he isn’t quite as terse as the Groovy monkey. The Groovy monkey has an implicit sense of self identity; his identity comes from the Groovy language itself. The Perl monkey, on the other hand, finds it necessary to explicitly define himself (and as we discussed above, what belongs to him). Without a blessed reference to himself, he’s nothing more than a heap of monkey parts –any of which could be directly utilized by other monkeys, but you couldn’t really say that the monkey was doing things himself, because in Perl, without a “$self”, there really is no monkey to speak of.

So it would seem that Perl does not provide its monkeys with a sense of identity the way other programming languages do. Perl monkey implementers often regard this as a positive feature, however, since they tend to be fiercely independent and often identify themselves with more than one language in any case.

Java Monkey Guts

import java.util.ArrayList;

public class Monkey {
    public ArrayList see() {
        ArrayList see = new ArrayList();
        see.add(”scratch”);
        see.add(”climb”);
        see.add(”eat banana”);
        return see;
    }
    public void does(String action) {
       System.out.println(”Monkey does ” + action);
    }
}

Again we see that Java monkeys like everything spelled out in triplicate, and they often bring in extra tools sooner than the monkeys of other languages would need to do. But I think that the Java monkey’s psychological profile predisposes him to like this arrangement. He doesn’t really mind that his language is so far from English. After all, look at the English implementation of a monkey above: who really wants that kind of bloated, buggy monkey? You practically have to document usage guidelines and installation instructions right in the source code!

The irony here, of course is that Java is as vague when written in English as English ever was from Java’s perspective. I really do think that Java was invented by aliens with a signed permit to demolish the planet.

What does a monkey look like in your native tongue? I have a friend pondering what a Haskell monkey would look like. But I’d also really love to see your ideas for others, such as a Python Monkey, a Ruby Monkey, an Arc Monkey. How about a Basic Monkey? Is that even a meaningful concept?

In any case if you have an example of a monkey in any other idiom, please send it (or its URL) to me at joel ~at~ clickherder dot com; I’d love to include it and compare it to the above examples.

The Cat’s in the Cradle

Snap. No posts in three weeks. Stick a fork in this one, it’s done.

I’m sure we all have our excuses for not posting. Here are mine: I’ve been really busy doing things that are only tangentially related to SEO/WebMarketing/WebDevelopment. During the last three weeks I have magically morphed into a CRM guy. My employer’s CRM product runs on linux servers and so I’ve had some opportunity to do some shell scripting, and some Perl coding, which is always a blast. And I guess that’s why I haven’t done either of those two things at night, and thus haven’t had anything interesting to blog about re: anything to do with this site.

Except for one thing. I wrote a rudimentary word commonality indexer which just pulls down one site, strips out the html and counts up word uses for all human-readable words on a page. My diabolical plan remains: build a broad index from xty-million websites and then cross reference all available single-word domains against the commonality index to see which available single-word dot coms are the most commonly used words. Phase two would be to separate the commonality index into different signatures (i.e. tech sites signature vs. my Space, Yahoo Groups and Multiply.com vs corporate web presences vs government sites. etc.). Then generate popular availables in each signature/sector. It’ll be great.

Hello Two-Tiered Internet

There’s buzz over at Slashdot about Sunday’s Washington Post article The Coming Tug of War Over the Internet. The Telcos want to charge extra to content providers for carrying their content over a premium carrier. Yahoo! may be faster than Google! eBay may be faster than Amazon! Horrors! The Post quotes AT&T Chairman Edward E. Whitacre Jr:

[Whitacre] complained that Internet content providers were getting a free ride: “They don’t have any fiber out there. They don’t have any wires. . . . They use my lines for free — and that’s bull,” he said. “For a Google or a Yahoo or a Vonage or anybody to expect to use these pipes for free is nuts!”

There is, on Slashdot, a lot of socialist-flavored corporate vs. consumer saber rattling going on. But the fact is that on the internet we’re all consumers, and the really cool thing is how many of us actually are corporate. And of course the real concern should not be for Google or Yahoo! but, as Alan Davidson (Google’s Washington policy counsel) said, for “bright young start-up with the next big innovative idea” who may be priced out of his start-up’s goals due to higher access costs or slower connectivity to his clientele.

It’s true that network neutrality has been a cornerstone of the Internet’s commercial success. But asking Congress to weigh in is, frankly, a much worse prospect. Remember that the Telcos have competition. The fact that they dragged their feet, clinging to their virtual monopoly on consumer internet access through most of the 90’s opened the door for the rise of cable internet. If the content providers fought back by offering discounts to customers who don’t use the telcos, consumers would have yet another incentive to move away from the telcos. Perhaps other ISP initiatives could find just the opening they need to bring other alternatives to the consumer such as affordable wide-area ether networks or wireless clouds.

The point is that although Whitacre and others’ desire to change the way access is monetized may seem like a threat to our very way of life, we ought to continue to trust the open market which created the Internet as we know it in the first place. The beautiful thing about free markets is that if left alone, they tend to correct themselves.

The Clock Is Ticking

I can’t stand watching the television show 24 on television. This is mainly because I lag behind the Tivo Generation, and I hate when I miss an episode. So I handle this by not watching the show at all during it’s usual syndicated broadcast season. And then I rent the DVD’s as soon as I can and watch them like a drug addict, jonesing at the end of each cliffhanger episode.

Last night I watched episodes 1-4 of season 4. Then and only then, I retrieved creation and expiration dates for my database of 136,546 single-word .coms.

Tonight I have episodes 5-8 cued up in my DVD drive. Today 142 single-english-word .coms expired, but I have no time to grieve because Jack Bauer needs me.

‘Scuse Me, Are You Going To Click That?

The list of available single-word .coms is growing, and currently stands at around 222,000. I’m intrigued with a set of domains which have been registered, but which apparently don’t have an IP address or name server. This accounts for roughly 6% of all registered domains in the single-word-dot-com set.

So what are those folks doing? How long have they had those unused domains? Are they likely to do anything with them soon? Obviously those domain names were good enough that somebody bought them at some point. So what if I approached them and offered to take the domains off their hands for twice the going rate, to buy out the rest of their registration term? Kinda makes you think.

No Good Name Left Untarred

The conventional wisdom is that all the good single-word dot coms are all gone. Generally when I hear that, I pull a word out of my hat, zip over to GoDaddy and see if it’s available as a dot com. Generally it is not.

But the other day I thought “Hmmm. There are nice big dictionaries of English words freely available on the net, and as a Perl Dude™ I can leverage this to let me find out just exactly which words are taken and which are not.” So that’s what I’m doing.

My makeshift script takes a somewhat reformatted version of the AGID word list (AGID: Automatically Generated Inflection Database, available as a zip or tarball here), sticks .com on the end of each word, and sends it up the flagpole.

The script is running now, and having checked just over 72,000 words out of a total of over 282,000, it’ll be running for some time. But for those readers inclined to statistical modelling, here’s how they’re shaping up so far:

total registered
78,399 54.44%

Of the 35,719 or so single-word dot coms still available, here is a random sample:

borodinos.com
titanosauri.com
westernizing.com
complects.com
maldons.com
linnaei.com
adenopathyes.com
yucatecs.com
cassonades.com
haematoxylum.com

More to come: I reckon this script will finish sometime tomorrow afternoon, at which point we can figure out whether your favorite word is already spoken for.

PS. although my script hasn’t checked it yet, I note that untarred.com is available. Have at it!