tags:

views:

389

answers:

2
+2  Q: 

Ruby to Groovy

I have a framework written in Ruby that needs to be converted into Groovy.
It does not use anything outside of core ruby, but a lot of meta programming.

Are all the same basic features supported by Groovy and is the changeover complicated?

+6  A: 

I suspect it might not be easy (depending on size, functionality etc.), and it's not so much of a translation as a rewrite. Whenever I find myself thinking of doing a rewrite, I refer myself to Joel's musings on this before going any further.

Why do you need to rework this in Groovy ? If you need the JVM (say, to integrate additional libraries/frameworks), have you looked at JRuby ? It might save you a lot of work and pain.

Brian Agnew
+1 for JRuby idea!
wuub
I have already tried it in JRuby + Swing, worked great, but am unfortunately not in a position to make the final language decision.
Also, converting framework to other language should be regarded as refactoring, and refactoring implies that you have a suit of unit tests! Don't start migration without having testing in place, because it's highly probable it won't work.There is a nice rantabout it here: http://hamletdarcy.blogspot.com/2009/06/forgotten-refactorings.html
wuub
I was going to point this out. Of course (normally) your unit tests are in the same language as your project. I'm not quite sure what you'd do in this situation...
Brian Agnew
Unless I can do a good job in selling JRuby instead of Groovy... Any advice?
Point your bosses to Joel's article above, and try and quantify the expenditure/effort in terms of a rewrite. I assume regression testing will be next to impossible given the language change, and since you're looking at a rewrite, the cost will be v. similar to the original *cumulative* cost of implementation so far. Plus (I guess?) you have Ruby experience and no Groovy experience ?
Brian Agnew
+3  A: 

Groovy and Ruby are not terribly different, but the metaprogramming aspect changes a bit.

Although I am not a Groovy expert, I can refer to you some pointers in the documentation (http://groovy.codehaus.org/Dynamic+Groovy):

Dynamic method calling:

# Ruby
an_instance.send("method_name")

// Groovy
anInstance."$methodName"()

Method missing:

# Ruby
def method_missing(meth, *args, &blk)
  # Some code
end

// Groovy
def methodMissing(String name, args) {
  // Some code
}

Adding methods to a class at runtime:

# Ruby
class SomeObject
  define_method :new_method do
    # Do something
  end
end

// Groovy
SomeObject.metaClass.newMethod = {->
  // Do something
}
pschneider