JRuby – Understanding the fuss
Some background, Ruby is a dynamically typed, pure OO language. It’s open source, pretty easy to write and fairly powerful. A couple of deficiencies being addressed in the current 2.0 effort include green threads and unicode support.
Everything in Ruby is an object, dynamically typed, though strongly typed. However, type is less important than behaviour:
Duck typing, runtime exceptions (sounds scary, but rarely happen – I’m waiting to be convinced!).
Mixin modules allow you to include additional behaviour e.g. class Circle include ShapeStuff.
Blocks are nameless functions you can pass and invoke to remove repetitive code.
Well, that’s my version of Ruby in a very small nutshell, now onto JRuby – a Java implementation oof Ruby.
JRuby, gives you easy integration with Java libraries, and you can call to Ruby from Java via JSR-223, and use Java classes from Ruby.
include Java
import javax.swing.JFrame
Now you can script Java.
JRuby offers a rapid MVC framework, and prefers convention over configuration.
So why do Java users want it?
- easy to learn
- less code
- features missing from Java (closures, open classes, literals for Arrays and duck typing)
It’s a better language for tying libraries together, and you can easily create domain specific languages (DSLs)to wrap libraries.
There’s also JRuby on Rails for Java developers, much less rails code than Java application config, and simple CRUD apps in minutes.
Am I sold? Not yet…then again I am biased. There’s more on DSL’s latter this week.