After listening to all the raving and hype and Cool Things coming from node.js, I decided to give it an honest whirl, and I’m having a really good time so far!
One of the major things that got me interested in poking at node, besides James’s dnode, was jerk, an IRC bot framework. I’ve always wanted an IRC bot, but never really found anything standalone (didn’t feel like just using an irssi client, for example) that felt lightweight enough for me to hold in my head (so, not an eggdrop) and was in a language I had an interest in (Perl is too leet for my soft mind, and TCL felt pretty useless outside of an eggdrop). So, Jerk felt about right!
Oh, and don’t forget about coffeescript. Coffeescript looks awesome.
At the same time, I’ve kinda fallen in love with github. Seriously, awesome stuff. I really like the atmosphere of social coding that github fosters. It makes me feel like everyone here is just, like, hacking up cool shit all the time and giving each other high fives, even if that’s not really what’s happening. It’s fun, though.
So, I took IRC-js (the library underneath Jerk), node-github, and my miniscule knowledge of javascrit, and went to work! Then, after an hour or so, I had my working bot:
(This happens to be the first time I’ve embedded a gist, btw.)
The cool thing I learned about through this exercise is “callbacks.” Node.js code seems to make really heavy use of them, due to the nature of functions in javascript and Node’s concurrency model. Anyone here that’s worked with javascript is probably quite familiar with them, but I thought they were pretty sweet.
So here’s how they work, for anyone that doesn’t know: Basically, when you call a function (that uses callbacks), you pass it another function (the callback), and this function gets executed after most of the other stuff in the original function. So, for example, in the example from Jerk’s readme:
j.watch_for('soup', function(message) {
message.say(message.user + ': soup is good food!')
})
In this example, function(message) is a callback, and gets executed with an argument (“message”) supplied by the function j.watchfor.
Pretty obvious, right?
Well, it should’ve been for me, but I was a little slow to catch on. This is probably due to how python treats functions: Unlike in javascript, where you can throw functions (named and anonymous) around willy-nilly, python either makes you define a one-line lambda, or define a named function somewhere else. Also, most python isn’t being ran concurrently and asynchronously, like code does in Node.js (for something like Node for python, check out tornado. Speaking of, I should play with Tornado.) It also doesn’t help when people start using nested callbacks. XD
Anyways: I expect my bot (dubbed “lulzbot” for now) to be able to eventually do more things, and I expect to have a pretty good time with it! Thanks node-peeps!