Beyond Ruby: Mirah, Reia, Rite

Programmer productivity and fun are both core design goals behind the Ruby language. Matz has always placed high emphasis on both in his interviews, and by all accounts, his philosophy and the uptake of Ruby are clear indicators of success – language designers take note, design for humans, not machines! First shipped in December of 1995 (version 0.95) Ruby has come a long way since that initial release. We now have half a dozen of alternative runtimes, tens of thousands of libraries, and arguably one of the most active developer communities.

However, just as Ruby was not created in a vacuum and took a lot of ideas and learning from Smalltalk, Lisp and Perl, it is now also having a similar influence on new languages which go beyond just replicating the original runtime. Mirah, Reia, Rite, and RubyGoLightly are all great examples. Some of them are still only on paper, some are purely experimental, and some are already fully functional and run in production. Let’s take a closer look.

Mirah: a simpler Java

A brainchild of Charles Nutter, one of the core contributors to JRuby, Mirah looks like Ruby, but is statically typed (with type inference) and compiles directly down to the JVM bytecode. In fact, the syntax is the only common thread between the languages – Mirah inherits nothing else except a JRuby parser:

def fib(a:fixnum)
  if a < 2
     fib(a - 1) + fib(a - 2)

puts fib(10) # => 55

The class model, the types, and the object behavior in Mirah are all native Java. In fact, because Mirah code can be compiled directly down to the JVM bytecode (or java source), it also means that Mirah requires no additional runtime libraries. Mirah is a simpler Java, a Java that is fun to work with. Best of all, it is also already fully functional, and is just a simple gem install away:

$ gem install mirah
# Successfully installed bitescript-0.0.7
# Successfully installed mirah-0.0.4-java
# 2 gems installed
$ mirah -e 'puts "Hello World"'
# Hello World

For some production examples of Mirah at work, take a look at Dubious, which is a web framework written for Google’s AppEngine. Likewise, you can build native Android apps with a Ruby-like syntax, but which compile directly to Java! With an active mailing list, over 12 contributors, and a recent move to the Apache 2.0 license, definitely a language to keep an eye on.

Reia: scripting the Erlang VM

Reia is a Ruby/Python inspired scripting language for the Erlang VM (BEAM). Tony Arcieri, the author of the language, describes it as the best of both worlds: friendly syntax, meta-programming, and power of blocks from Ruby, combined with Erlang’s concurrency, distribution, and fault tolerance:

module Fibonacci
  def compute(a)
    if a < 2
      compute(a - 1) + compute(a - 2)

"Fibonacci: #{Fibonacci.compute(10)}".puts() # => 55

Reia offers a wide range of native types: numbers, booleans, lists, tuples, dictionaries, rangers, binaries, and regular expressions. Combine that with support for modules, classes, instance variables, anonymous functions, and you have a promising language on top of the Erlang VM (and if you have ever programmed in Erlang, you will definitely appreciate the nicer syntax from Reia).

At the moment, there are no official releases of Reia, but if you want to experiment with it, simply clone the repo, run rake, and a few minutes later you’ll have the Reia interpreter as well as a REPL to play with:

$ bin/ire
Reia Interactive Shell (prerelease)
Running on Erlang R14B (erts-5.8.1) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:true]

>> "Hello World".puts()
Hello World

Most of the sequential features of Erlang are already fully functional and the concurrent features are coming. If having the power of Erlang’s OTP library, and the syntax of Ruby seems like an exciting idea, then be sure to jump on the mailing list!

RubyGoLightly: simple concurrency with Go

Go is a systems language by Google, aimed at improving productivity, optimizing performance and simplifying concurrency. Or as Eleanor McHugh, the implementer of the GoLightly VM, described it: lighter than Java, safer than C. Based on her GoLightly VM, RubyGoLightly is an experimental reimplementation of tiny.rb, which in itself is a subset of the Ruby 1.8 runtime.

In effect, RubyGoLightly is tiny.rb, except with the C code replaced by idiomatic Go, and running on top of the GoLightly VM. The project hasn’t seen much attention in the past year, as Eleanor’s focus has been on the VM, but it is a great implementation example to study due to its relatively small footprint.

Rite: embeddable Ruby by Matz

At his RubyConf X keynote, Matz announced that he is working on Rite: an embeddable Ruby. Think Lua, but better. It will offer a usable subset of Ruby we know, but focus on delivering a lightweight and a portable runtime for embedding in small devices, digital appliances, games, and so on.

The work on Rite is sponsored by the Japanese government (two year project, 2010-2011), and no code has been shared to date, but Matz has promised an MIT or GPL license and a repo on GitHub – chances are, sometime before the end of 2011. In the meantime, take a look at his presentation slides from RubyConf X.

Looking beyond Ruby

Each of the languages above is distinct in its approach, features, and even the problems it tries to address. However, whether it is making a simpler Java, leveraging the concurrency of Erlang/Go, or targeting embedded devices, the common thread is the focus on the programmer productivity and fun – we get used to good things quickly, so why not carry these concepts over to other languages!

Perhaps in the not so distant future we will be writing JVM apps in Mirah, deploying distributed apps in Reia, and wiring our digital appliances to the web with Rite. Ruby, like any other language, is a just a stepping-stone.

Ilya GrigorikIlya Grigorik is a web ecosystem engineer, author of High Performance Browser Networking (O'Reilly), and Principal Engineer at Shopify — follow on Twitter.