Technology Update (Part 2: Merb & More)
So where was I? Ah yes, in yesterday’s post I left off with me going back to Ruby for my personal projects.
My standard choice for web development has been Ruby on Rails for a while now (although I haven’t had a chance to try Rails 2.0 yet). However, lately I’ve been playing with Merb. Merb is essentially a lightweight Rails replacement, originally built to address some specific (largely bloat and performance related) concerns. For Rails developers, Merb will seem quite familiar (at least superficially), as it uses the same application layout as Rails, with the usual directories for controllers and views, etc. But unlike Rails, the core framework is very lightweight, with additional functionality being provided by plugins. Unlike Rails’ slightly awkward plugin framework, Merb plugins are actually just standard Ruby gems that can be installed either as part of the Rails installation or inside the Merb application. In particular, Merb does not include an ORM framework for its model layer. There is a plugin that adds support for ActiveRecord, the ORM framework that Rails uses as well. But as an alternative, Merb also offers plugins for DataMapper and Sequel. And of course very simple applications might not need a database at all.
I am particularly interested in DataMapper, which offers several improvements over ActiveRecord. Most importantly, it is thread-safe. But it also moves the definition of a model’s properties from the database into the Ruby class. The fact that ActiveRecord infers all attributes from the database has always seemed slightly unnatural to me, so moving the definition into Ruby code makes more sense to me. I do however miss ActiveRecord’s support for migrations (anyone remember when ActiveRecord did not have this feature yet and how big a difference it made when it was released?).
One thing I should mention is that Merb is currently undergoing a major transformation. The 0.5 version (which the Merb website still refers to) has been end-of-lifed (0.5.3 was the final release), and development has shifted to the 0.9 version. 0.9 takes an even more radical approach: The existing Merb gem will be split into merb-core (the actual core, very lightweight), merb-more (support for generators, mailers, the Haml template language, etc.), and merb-plugins (things like ORM framework support). Merb is also adopting the Rack interface, which is becoming the standard way for Ruby web applications to plug into any compatible web servers (similar to Python’s WSGI).
The 0.9 release is expected to come out any day now, and you can follow its development on github (Merb shifted from Subversion to Git) and the Lighthouse bug tracker. If you want to get more involved with Merb, Michael Ivey wrote an interesting two-part article on contributing to Merb (and part two). There is also a pretty active and helpful community on IRC (#merb on Freenode). Merb was originally implemented by Ezra Zygmuntowicz, who founded the Engine Yard hosting service, and with the recent investment into Engine Yard, Merb (as well as other Engine Yard supported apps such as Rubinius) now has several dedicated developers working on it and seems to have a bright future.
Right now I am using Merb to build a simple Facebook application. I’ll blog more about this later, but so far it seems like a good choice for this type of application. The transition from Rails is relatively easy (although this is likely more complicated if you are relying on a lot of the Rails magic such as the various helper classes), and the Merb community is very helpful. Deploying a Merb app is not much different from deploying a Rails app. I am currently deploying my Merb app-in-progress via Capistrano to SliceHost and running on Nginx and Mongrel (mainly following these instructions).
In my current application, I am also giving Haml a shot for the first time. It takes some getting used to (after being indoctrinated with HTML for over a decade…), but you quickly learn to appreciate its elegance and conciseness (it really makes you realize how much redundancy HTML carries around).
One thing I haven’t tried yet is RSpec (so far I’ve been using good old-fashioned Test::Unit), but the trend seems to go towards RSpec, so I’ll have to check it out one of these days. It’s amazing how quickly these technologies shift in the very dynamic Ruby world, and sometimes quite hard to keep up when I’m only using it occasionally in my spare time…
February 13th, 2008 at 9:36 am
Playing with toys again, hu? You should definitely check out RSpec. The change in syntax provided by the DSL makes it almost impossible *not* to write tests. It also gives you a nice way to output a “spec” based on the test you’ve written. Very useful, specially if you are following any kind of Agile development methodology.
If you’re looking for a lightweight Ruby based web framework, you should check out Sinatra as well. It’s a very lightweight DSL for simple RESTful like web services. If you have any feedback, let me know. The author of Sinatra works for Songbird
We’ve also made the switch to GIT for our web development at Songbird. The low cost of branching allows for interesting new work patterns, such as creating a branch for each new story being implemented. Compositing a release by pulling from various repo becomes also a lot easier too. Worth checking out.
February 13th, 2008 at 11:10 pm
Yes — right now I’m mainly working with legacy Java code during the day, which means I need to compensate by playing with Ruby in the evening.
I’ll definitely make sure to check out RSpec. The examples that I’ve seen look pretty neat.
I’ve come across Sinatra. It seems like a good choice for simple applications. Another framework that looks nice is Ramaze. I think it’s great that we have several solid Ruby web frameworks to choose from these days.
Git is definitely interesting. I might play with it a bit if I end up contributing some code to Merb or some other open source project. I was initially turned off a bit because I saw a Git presentation by Linus Torvalds at Google, and he is just so terribly arrogant… But ultimately it really seems like it could make a big difference to the workflow, much more so than the more incremental improvement of switching from CVS to Subversion.
Ah, so much cool stuff to play with, and so little time…
February 14th, 2008 at 2:10 pm
I forgot to mention that RSpec integrates well with Mocha, a stubbing and mocking framework.
August 26th, 2008 at 6:15 pm
Hi - I came across this post through a web search of facebook merb developers. I couldn’t find another method of contacting you, so I apologize for the public nature of this message!
We are working on a new social networking site, and the client would like to be able to take advantage of the Facebook Connect API in time for launch of the site. I’m not sure if you have time or even interest in taking this project on for yourself, but if not perhaps you know others who would? Your response is greatly appreciated!