4.9. Alternative Ruby Implementations

When we talk about Ruby it's common to assume that we are referring to the latest stable version of Matz's interpreter. It is important to keep in mind that Ruby is a programming language, not a single implementation. Several alternative implementations have popped up over the past few years, thanks to the incredible success that Rails brought to the language. Most of them were aimed toward fixing Ruby's main Achilles' heel, the speed of its most commonly used interpreter. But the world of alternative implementations is so much more than that, and each of them is characterized by particular strengths and weaknesses. Every year new implementations are released and thus there is a form of natural selection in place, which will end up whittling the selection down to a few established players that will become somewhat commonly used. In their wake, many others will fall to the wayside and end up being used far less routinely. The following list introduces you to the ones that are today's main players:

I periodically run shootouts among all these implementations. You can find them on my blog at http://antoniocangiano.com.

  • Ruby 1.9 is the next version of Ruby. In this version, the heart of Ruby has been replaced with a bytecode interpreter known as YARV (Yet Another Ruby VM). It has support for Rails and it's about three times faster than Ruby 1.8.6, according to a series of micro-benchmarks that I run periodically. Unfortunately other benchmarks have shown that Rails applications running on Ruby 1.9 don't gain nearly as much speed. But that said, it's still a huge improvement over the current interpreter nevertheless, especially if you consider that a few design flaws of the language are being addressed as well.

  • JRuby is an implementation of Ruby for the JVM, which is aimed at being fast and providing integration with the Java world. It is the oldest and probably most mature alternative implementation, and it has been able to run Rails since 2006.

  • Rubinius is a compiler and Smalltalk-like virtual machine for Ruby. The focus of this VM is on correctness, extensibility, and speed. The development team, joined also by other VM implementers, did a great job in creating specs for the Ruby language (which unfortunately, lacks a formal grammar). In 2008, Rubinius was able to introduce preliminary support for Rails applications.

  • MagLev is the youngest of the lot, but was able to wow the audience at RailsConf 2008, thanks to its impressive results during a series of micro-benchmarks. At the time of this writing it is not yet publicly available, or able to run Rails. But I have tried it and can confirm that it's a promising project with the potential to do very well in terms of performance. It's developed by Gemstone, a well-known company in the world of Smalltalk, and may become a commercial product with a free version available as well. The basic idea behind this project is that Ruby is not all that different from Smalltalk, and as such, Gemstone should be able to leverage their experience in delivering a fast and scalable platform for Smalltalk, even when applied to Ruby.

  • MacRuby is an implementation of Ruby 1.9 in Objective-C, developed by Apple, Inc. Its goal is to become a fast replacement for RubyCocoa when it comes to writing Ruby applications for Mac, and at the time of this writing, is not able to run Rails applications yet.

  • IronRuby is a version of Ruby implemented by Microsoft. It's built on top of the Dynamic Language Runtime (DLR), which in turn sits atop of the CLR. If you are a .NET developer, this is the alternative implementation that should interest you the most, given that when a stable version is released, it will allow you to write Rails applications that can take advantage of Silverlight and the .NET Framework. This would be the best of both worlds, as long as you haven't decided to abandon the .NET ship altogether. At the time of this writing, IronRuby has added preliminary support for both Rails and Silverlight.

A similar project that was sponsored by Microsoft is Ruby.NET (based on the CLR). Though it is clear that IronRuby is going to become the de facto standard for Ruby on .NET, particularly after the head of the project left Ruby.NET and joined IronRuby, few developers do try to actively keep the Ruby.NET project alive, but its future is uncertain at best. I recommend that you explore the IronRuby possibility first, if you are interested in the interoperability between Ruby and the Microsoft world.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.186.109