Why JRuby is the best of both worlds?
What is JRuby?
Ruby, as a language, has a few different implementations. So far, we have been using the original Ruby implementation that was the first in the Ruby world. It is generally referred to as MRI (Matz Ruby Interpreter), which was written using ‘C’ language and hence sometimes referred to as CRuby.
That said, there are other implementations of Ruby that provide integration points with other programming languages or environments.
- JRuby is Ruby atop the JVM (Java Virtual Machine), utilizing the JVM’s optimizing JIT compilers, garbage collectors, concurrent threads, tool ecosystem, and vast collection of libraries.
- Rubinius is ‘Ruby written in Ruby’. Built on top of LLVM, Rubinius sports a nifty virtual machine that other languages are being built on top of, too.
- MacRuby is a Ruby that’s tightly integrated with Apple’s Cocoa libraries for Mac OS X, allowing you to write desktop applications with ease.
- mruby is a lightweight implementation of the Ruby language that can be linked and embedded within an application. Its development is lead by Ruby’s creator Yukihiro “Matz” Matsumoto.
- IronRuby is an implementation “tightly integrated with the .NET Framework”.
- MagLev is “a fast, stable, Ruby implementation with integrated object persistence and distributed shared cache”.
- Cardinal is a “Ruby compiler for Parrot Virtual Machine” (Perl 6)
Do I have to learn YET another..?
Nopes ! The syntax of Ruby what we have been using so far adheres to RubySpec.
So no we don’t have to re-write our ruby code written so far or make changes. the environment or runtime on which the code runs changes based on the flavor or Ruby we select. Then why are we talking about this ?
Some reasons are…
- We have been a Java Shop for many years and have a huge portfolio of libraries, projects etc. that have been well integrated. We want Ruby to be an enhancement on top of that shop and NOT necessarily replace the whole stack.
- As an application developer, we have robust API’s implemented in a Enterprise Service Bus model and we have production customers for many years. We do NOT want to fix something that is NOT broken. Yet, we want to take advantages of using Ruby Syntax with all the closures, lambda’s, elegant code etc.
- Our CI environment has invested in Java Stack for many years and we have gone through enough audit’s to have SOCKS compliance and other regulations and security compliance that was needed to have internal controls in place. We do NOT want to tear that down just for Ruby syntax.
- We want to use Ruby and take the positives of that world, but not at the expense of risking our current relationships with clients or customers.
- And so on….
Yep, all valid points. Below are some thoughts of mine:
Why JRuby is the best of both worlds?
…if you intend to stick with both worlds 😉
Java is Java
Ruby comes in multiple flavors popular ones being JRuby, MagLev,MRI, Rubinius, YARV and so on
- Ruby is elegant, Java is mature and enterprise proven
- Ruby is interpreted, Java is compiled
- Ruby has meta programming, Java doesn’t (however groovy has)
- Ruby syntax is simpler, more readable, lesser lines of code, active support makes it much more readable and ruby blocks (lambdas) are awesome.
- Java wins on performance – See second table, the smaller bar the faster
- Java is well known, easier to find experts , easier to tune
- Language wars actually do not make much sense. Ruby is great for its terse nature, readability and constructs AND Java is great for performance
- JRuby makes them talk together and we get best of both worlds
- Benchmark Suites of different Ruby flavors
- Multi-Threading in Ruby
I ain’t convinced still..
Totally understandable. In our minds, we think Java and Ruby are mutually exclusive and that they are worlds apart – that is – if I choose one, then I will have to sacrifice the other.
Sure, there are differences, but we want the positives of both worlds right? Continue reading, in our next pages, we will see.