views:

102

answers:

4

I'm thinking of refactoring a somewhat large Java based application. There are some parts of it that should be able to run at a pretty decent speed, so I thought about keeping those in pure Java ... and the rest in JRuby. Do you think it would be worth doing this "refactoring"?

A: 

Do you hope to run the code through a scripting interface (such as the JSR223 API)? If so, and your logic changes often, this may be valuable.

Otherwise, I don't think it would be worth it. My experience trying something similar in Scala was that doing a straight-forward port, you end up writing Java code in Ruby (or in your case, Scala). The only reason it might be worth it is if you are trying to take advantage of some feature of JRuby that would make the problem inherently easier, or if you're just practicing your coding skills.

James Kingsbery
A: 

A thing I have had to consider is that mixing languages makes the maintainance burden exponentially bigger since future programmers need to know All the languages involved plus the bridges between Them. If you all have the full skill set, great, otherwise Think twice. Your code Will live longer than you Think

Thorbjørn Ravn Andersen
How many languages are you using already? Ant build.xml or Maven POM, Spring beans XML, HTML, CSS, JavaScript, probably SQL or a variant of it. Use the tool that fits the job best.
Nick Sieger
These languages are usually quite separate parts (you rarely mix SQL with CSS) causing the integration to be less complex. In any way in order to be able to maintain such an application you will need to master more technologies than one written in pure Java. More technologies means more learning. In my experience.
Thorbjørn Ravn Andersen
+1  A: 

Perhaps Groovy would be a better choice than Ruby, since Groovy is a super-set of Java.

Zombies
+1  A: 

Absolutely! There are already sufficient tools to do this: The org.jruby.embed API which shipped in 1.4, and jruby-rack, an add-on library which allows you to mount Ruby applications as servlets.

I'm playing around with mixed Java and JRuby in my fork of the spring-petclinic app. You can find an example of a jruby-rack configured servlet in there that mounts an embedded Rails application.

You can see an example of the embedding API in the net.caldersphere.webdemos.StartupScriptLauncher class in that project.

Feel free to contact me if you're interested in pushing these kinds of scenarios further.

Nick Sieger
What if I were to write JRuby, and use Java inter-op from there? Would it still be useful?
Geo