Merb: A Memo

You may or may not have heard about the lightweight Ruby web framework Merb http://merbivore.com/. Merb stands for Mongrel + Erb, but it's a whole lot more than the name might imply. I've been using it over the past few weeks to build a file upload app which will coincide with the main application built in Rails.

It's worth asking what the main distinctions are between the frameworks and why you might want to use one over the other. Whereas Rails is the framework that has lowered the barrier to entry for many people, Merb brings performance and purity to a clever but sometimes obfuscated world. If you're an MVC buff like me, you'll appreciate the attention given in making each of the parts (Model, View, and Controller) independent and therefore replaceable. A great example of this can be found in the choices of supported ORM (Object Relational Mapping) libraries; something Rails doesn't offer out of the box. Merb also provides you with a straightforward way to use any template engine you'd like, very similar to Rails' implementation.

Unlike Rails, Merb is thread-safe. To illustrate the difference, imagine a one-way road with a single lane (a process). In a non thread-safe environment, cars can only travel down the road single-file, one after the other (each car being a thread). Having a thread-safe environment simply means that our road can handle more than one lane and allow cars to travel alongside one another (share process resources simultaneously). In practical terms, this means a single Mongrel instance can handle multiple file uploads simultaneously.

Merb is truer to Ruby than it is to making sure web development doesn't hurt. I'm not saying building an application with Merb is painful, but you will need a bit more Ruby prowess than Rails demands. Tradeoffs are a fact of life, so in many cases learning more Ruby and using Merb can mean far better performance.

Using the right tool for the right job is important. I highly recommend checking out Merb and using it when applicable.

Jordan Fowler

Reader Comments

Your Voice: