microformats

Liminal Existence

Clouds in Iceland

Monday, May 12, 2008

Scalability

Updated: Go read Steve's Dynamic Languages Strike Back. It's a longer read, but it's much more interesting, and he's much smarter than I am.

LOL. <-- this is a link. Read Ola's post, first.

For all those who don't get it, languages don't scale, architectures do.

Now, some languages are faster than others. That means that to complete a given operation, it costs less, everything else being equal. Costing less is a good thing. But developers also cost money, so if you have to spend money on developers' time porting from one language to another then you might not be saving any money at all, and really you're just treading water.

Once upon a time, Shell Scripts were used to write CGI applications. With the correct architecture, and enough money, you could build Google with tcsh. No, really. It wouldn't be fun, and you'd be dumb, because there are much cheaper ways to do it. But then again, if you stuck with it, perhaps you'd optimize tcsh to be really fast at spawning and serving up web requests. Faster than Java, faster than <insert your favourite language here>. Faster means cheaper, it doesn't mean more scalable.

I point to exhibit A. Perl used to be slow. Now it beats JoCaml with the bestest concurrency (re: “Scalability”) around. What was Perl built for? Parsing text. Lots of it. All the time. It's fast. Does it mean that you can't build Wide Finder with another language? Absolutely not. Does it mean that you couldn't build Wide Finder to scale out to a trillion documents with gawk? If you answered “yes”, go back to the start of this post and read again! :-) If you're still answering “yes,” try reading some more. Leonard, Ted, Joe, Cal, and Theo are good places to start.

If you answered “no,” congratulations! Pat yourself on the back for knowing what scalability means.

Labels: , , , , , ,

Thursday, November 09, 2006

Announcing Jabber::Simple

Jabber::Simple [src, doc] is a simple (duh!) Ruby library that aims to make the implementation of basic Jabber functionality trivial. It is an extraction of the Jabber support that was added to Twitter, and is released under the GPL by Obvious. A line of code is worth a thousand words, so here is the complete code for sending a simple message to a Jabber user:

jabber = Jabber::Simple.new('rex@friendosaurus.com', 'password')
jabber.deliver("bront@friendosaurus.com", "Hey! I'm thinking of going Vegetarian - Any suggestions?")
Getting incoming messages is just as easy:

jabber.received_messages do |msg|
  puts "#{msg.body}" if msg.type == :chat
end
You can also set your status, and get information about your friends' statuses:

jabber.status(:away, "Eating at the Tree Cafe. I need a ladder.")

jabber.presence_updates do |update|
  friend = update[0]
  presence = update[2]
  puts "#{friend.jid} is #{presence.status}"
end

Installation


sudo gem install xmpp4r-simple
or download the package from RubyForge. Source code is also available, licensed under the GPLv2.

Yet Another Jabber Library?

There are a number of existing Jabber libraries for Ruby (jabber4r, xmpp4r, and Net::XMPP), so why Jabber::Simple? First off, Jabber::Simple does not aim to replicate any core XMPP protocol functionality present in these libraries — in fact, Jabber::Simple depends on xmpp4r and the Jabber::Simple#client and Jabber::Simple#roster methods expose all of xmpp4r's awesome functionality. When I started building in Jabber support for Twitter I'd used various Jabber clients, and even set up a simple Jabber server. Writing my own client, however, was a bit more complex. It turns out that the seamless experience of "adding a friend" and chatting with them is (unsurprisingly) comprised of a series of disjoint steps, and fraught with the peril of threads, XML streams, and arcane magic. The available libraries handle these tasks and many more admirably, but lack in elegance. My hope is that Jabber::Simple provides a sufficiently obvious interface with which to develop tools that use the Jabber protocol.

But Wait! There's More!

Now, you might shy away from writing that really cool chat-bot you've been meaning to write, saying "Wow, this is great, but setting up a Jabber server is a pain." --- but fear not! Go over to Google Talk and sign up for an account. Once you're done, use your Google Talk username and password, and start Jabbering. No really, it's that simple.

jabber = Jabber::Simple.new("you@gmail.com", "password")

Labels: , , ,

Saturday, November 04, 2006

.irbrc

irb is a wonderful tool; with a few tweaks and additions, though, it becomes essential. I spent too long getting by with just readline support, but today, finally, I added a few of the extensions that I've seen floating around on various ruby blogs. Now my tab completion and history run in overdrive, and the number of extra terminal windows I keep open has been reduced greatly. A quick summary of the features present:
  • Full readline support and tab completion
  • Copy-friendly prompt
  • Auto-indentation
  • Persistent history
  • Object#local_methods, to view methods unique to an object
  • Colourized output (via wirble)
  • Method finder. e.g., "hello".what?(5) #=> [:length, :size]
  • Colourized inline ri support (either Object#ri(*methods) or ri Object, works best with Ruby 1.8.5's much improved ri
  • Output spooling, via more, less or most. e.g., less { puts really_long_string }
  • Simple regular expression helper (/an/.show_match("banana"))
  • Textmate and Vi launching
You can get my .irbrc here: ~lattice/.irbc.

Labels: , ,