On Thursday, December 16, 2010 05:15:59 pm Colin Bartlett wrote:
> On Thu, Dec 16, 2010 at 6:36 PM, Michel Demazure <michel / demazure.com>wrote:
> > Tony Arcieri wrote in post #968904:
> > > Have you considered trying to use a library like JAMA with JRuby?
> > > 
> > > http://math.nist.gov/javanumerics/jama/
> > 
> > I am still reluctant to a jump to jruby. I'll first check GSL on MRI
> > (1.9.2).
> 
> Doing fairly intensive actuarial type calculations I've found:
> 1. JRuby is currently(?) and anecdotally somewhat slower than MRI 1.9, but
> not so much slower as to be a problem.

And JRuby is getting faster all the time. It's not clear whether one will 
necessarily beat the other.

In particular, I remember hearing discussions of a commandline flag in JRuby 
which one could use to disallow altering methods on the core numeric types. 
This would basically make Ruby math compile down to Java math. I imagine most 
scientific applications wouldn't care about altering the core numeric types, 
while most scientific applications would care about fast math.

> 2. Integration with Java seems to be easy: I'm not a Java programmer,

I am, and it is _trivial_. Every now and then I open up irb and pull in some 
Java things, just for fun:

require 'java'
import java.util.ArrayList
a = ArrayList.new
a << 5
a << 'ten'
a.each{|x| puts x}

Basically, you think "How would I want this to work?" And then you "require 
'java'" and do it, and it works. It's beautiful.

About the only unintuitive thing I ever found was implementing a Java 
interface, and while it's somewhat unintuitive, it's still trivial:


require 'java'
import java.util.PriorityQueue
import java.util.Comparator

# singleton comparator
comp = Class.new {
  include Comparator
  def compare a,b
    a.to_s <=> b.to_s
  end
}.new

pq = PriorityQueue.new 11, comp
pq << 2
pq << 3
pq << 10
pq.remove  # => 10
pq.remove  # => 2
pq.remove  # => 3


Aside from that, connecting to a Java class from Ruby is pretty much: Read the 
Javadoc, open up irb, try to use it, watch it do exactly what you think it 
should.

Oracle's behavior lately is making me kind of iffy about the future of Java as 
a platform, but JRuby is just made of awesome.

> That's a big plus because I definitely don't
> understand at the moment how to compile C code and integrate that with MRI
> Ruby.

ruby-inline is very cool, but it's still not quite as easy as being able to 
write a Java class, pretend it's a Ruby class, and have it work.

I'd say, give it a spin. Worst thing that happens is you make the core of your 
project portable among Ruby implementations.