The Power of JRuby
Posted on November 14, 2011
I hesitated about using JRuby at first. I spend days beefing up on Java, which I hadn’t used in years. Even though I had been using Ruby on Rails for about a year, I felt more intimidated by JRuby than going back to Java. To be fair, the project I was working on involved integrating with complicated, legacy code. I started from a place of FUD.
It took me fighting with Spring MVC to get it to return JSON without a view to say “Fuck it” and try JRuby on Rails. It was a revelation … just like the first time I used Rails itself. Eventually, that code got moved from JRuby on Rails to JRuby Resque jobs and it was then that I realized the true power of JRuby.
When people talk about the advantages of JRuby, they always mention speed, concurrency, and integration in enterprise and legacy environments. All of that it true and awesome. But for me, the power of JRuby is that it means you can write pretty much anything, ever in Ruby.
Let me explain.
Despite the growing popularity of Rails, Ruby, Python, et. al, most of the programming world is divided between Java and some variant of C (C#, C++, C, etc). This means that, in general, you can interact with almost any service, library, etc via Java or C client libraries.
Using MRI or REE Ruby, which is written in C, you can easily integrate C extensions into your Ruby code.
Using JRuby, written in Java, you can easily integrate any Java code or library into your Ruby code.
Throw in Ruby gems for cutting edge technology and a distributed message queue, like Resque, and using JRuby opens you up to almost the entire eco-system of code, ever.
You don’t need to worry if there exists Ruby code to do what you need; you just need some code to do what you need. Need a C extension to work with JRuby code? No problem. Queue up a Resque job and run it on a server running MRI Ruby. Need a Java library for your Rails app? No problem. Queue up a Resque job and run it on server running JRuby. Need a .NET library? No worries. Queue up a Resque job and run it on a Windows server with Ruby installed. You use the best tool for the job regardless of language.
You know what else that means? You inherently end up with modular, scalable code.
And that, my friends, is the truly awesome power of JRuby.