BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Lift-JRuby Integration Bridges the Gap Between Ruby and Scala

by Mirko Stocker on Feb 01, 2011 |

Lift, Scala's popular web framework (more about Lift on InfoQ), wants to attract Ruby programmers with a dedicated JRuby API. Lift creator David Pollak writes that in its current state, "with the exception of a few things [..] Lift is reasonably usable from JRuby".

But why should a Ruby developer want to use Lift when he has Rails and all the other Ruby frameworks to develop web applications? David writes in his announcement:

Lift is hands-down the best web framework available today. It's got better semantics for Comet and Ajax than any other web framework. It's more secure by default than most other web frameworks. Lift- based apps scale nicely. Lift apps are more concise than most other web apps. Put another way, if you're a Ruby developer looking for a more secure, more scalable web framework that allows you to build more interactive apps, Lift is it.

You can verify these claims yourself on Lift's Seven Things website that has demos and examples for "7 things that are hard or impossible in other web frameworks".

We asked David for his motivation for bringing Lift to Ruby programmers: 

I love Scala and it's my favorite programming language. After talking to a lot of development organizations and watching Scala's adoption rate, I've realized that Scala is unlikely to have Ruby or even Python-level adoption in the next few years. On the other hand, Lift has matured into a web framework that's more secure and more oriented toward building interactive applications than any other web framework (see Seven Things). So, I made the decision to support other languages in Lift.

I believe in doing things right and I've recruited some hardcore Rubyists to help me make sure that as we create Ruby APIs in Lift, they feel like Ruby APIs, not like some bolt-on to Lift... we're going to do the Lift-Ruby code the Ruby way. For the first glimmer of that, please see http://liftjr.org.

I sincerely hope that the Ruby APIs on top of Lift expose Lift in a new and better way than the Scala APIs... that one day, the Ruby way will positively influence Lift's Scala APIs.

But, as the static language, Scala-lover, my main goal is to talk less, and listen more to see how we can make the Ruby APIs better.

InfoQ: What kinds of problems does one run into when accessing Scala from JRuby and vice-versa?

The JRuby APIs are clean, slick, and easy to use. There are no real issues... beyond the standard unityped vs. fully typed issues, see this talk from Philip Wadler.

In terms of accessing Scala from JRuby, there are some issues with Scala's singletons (the object keyword) and we've enhanced JRuby to treat these as Ruby Class objects. Scala also has symbolic method names (!, %, &, etc.) which we need to expose in JRuby and we're still working on that.

InfoQ: A very neat and often used feature of Scala is pattern matching, which has no equivalent in Ruby. You mentioned a DSL for pattern-matching in Ruby, can you show us how this might look?

This is perhaps the hardest part of the project. We've gotten a design (not implemented yet) for Actors that seems to be nice: 
  class MyActor < LiftActor
    def string(str) # same as case str: String =>
    end
   
    def some_message(p1, p2) # same as case SomeMessage(p1, p2) =>
    end
  end

We're working on other pattern matching on a case-by-case (pattern matching joke) basis. Once again, the idea is to have the APIs be the Ruby way, but reflect Lift semantics rather than shoe-horning Scala syntax into Ruby syntax. 

Having input from other Rubyists on the Lift Google Group would be great. 

The Lift JRuby integration has its own website on liftjr.org. What do our readers think about this? Can the Ruby and Scala communities benefit from this cross-fertilization?

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Bold move! by Daniel Sobral

This is a very bold move! There have been some movement of web frameworks trying to reach other languages (for instance, Play), but this seems bigger to me than any other such project I can think of. While Ruby and Scala share some common elements, they are very different languages with very different styles. And Rails is a milestone in web development, so going after Rails turf shows some guts.

I'm intrigued by what may come out of this.

Re: Bold move! by Daniel Ribeiro

It is also nice to see more Scala frameworks with Ruby integration. I recently made one for Akka, in order to help with easily enhancing performance through Akka Actors.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT