Channels ▼

Nick Plante

Dr. Dobb's Bloggers

Mirah: A Ruby Syntax for Java

November 25, 2010

There's been an explosion of interest in alternative JVM languages over the past couple years, which has seen the rise of Scala, Clojure, and Groovy, in addition to re-implementations of existing languages like JRuby and Jython.

The most recent JVM language to really capture my attention is Mirah. Created by Charles Nutter, who is perhaps most well-known as one of the JRuby core team member, Mirah's syntax is unsurprisingly inspired by Ruby. However, unlike JRuby, Mirah is statically typed (with local type inference) and compiles directly to Java bytecode without the need for any bundled-in interpreter.

When Nutter created it about two years ago, it was a hobby project (originally called Duby), an attempt to see how much of the things he liked about Ruby he could implement without requiring a runtime: "I started to realize it was really just a few key features from Ruby that I wanted: nice literals, clean syntax, basic closure support, iteration. I started wondering how many of these things can I implement without any runtime, just generating Java bytecode directly. How far could you take that? And it turns out you can actually take that a long way. You can do a lot of what people love about Ruby without doing anything more complicated than what Java does."

Mirah syntax generally looks very similar to Ruby, and many Ruby developers who have played with it immediately brand it as "statically typed Ruby". Here's an example Fibonacci program, from the collection of Mirah sample code. Note that the argument type is declared, but that the return value is inferred and does not need an explicit declaration.

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

Although it's still young, Mirah is already being used by a handful of people for production purposes. There's currently interest in using Mirah for building and deploying web applications on Google App Engine, which has led to the development of the Dubious framework, a slick Sinatra-like web framework. There's also a lot of interest in leveraging Mirah for Android application development.

My personal interest in the language was sparked by a Rubyconf talk on Ruboto, an effort to make (J)Ruby a viable option for Android application development. Ruboto itself is a compelling project and one that I'm sure will help make Ruby a more attractive option for mobile dev. However, Mirah may be even more suitable for Android work because of it's ability to compile straight down to bytecode without the need for a separate runtime, meaning smaller APK sizes and quicker startup times.

Both of these projects are still relatively new, but interest in Mirah is growing quickly within the Ruby and Java communities. At Rubyconf alone, there were at least 4 talks that included mention of Mirah in some way and it seems like a language that could have wide appeal. "You can do so much for a language just by adding a little more [syntactic] sugar", says Nutter, "and that's really what Mirah does for Java. It's a Ruby syntax for writing Java code."

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video