BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Lift-JRuby Integration Bridges the Gap Between Ruby and Scala

Lift-JRuby Integration Bridges the Gap Between Ruby and Scala

This item in japanese

Bookmarks

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?

Rate this Article

Adoption
Style

BT