When I first saw Charles’ post I immediately saw it as a tool to help a friend of mine who is familiar with Groovy syntax understand Ruby syntax a little bit better. And I think Charles was attempting to show how powerful Ruby is as a language, and how easy it is to make the language read how you want it. I think it is importnat to note what Charles was attempting to do. He was not attempting to implement an interface so that it could be used from java, he was trying to make Ruby syntax look like Groovy syntax. This is important because if he wanted to implement the as method he could have done something as simple as this:
class ::Object def as(interface) self.class.class_eval do include interface end self end end
I didn’t actually test this code, but I can’t imagine I am too far off here. If this does work than you could very easily dynamically add an interface to a class.
x = myObject.as java.util.Iterator
And as long as myObject has a hasNext, and next method in it’s class definition then Java should be able to use the class just fine. I think it is also important to point out, that there is never a good reason to actually do what his example did in ruby. Unless you are sending the object out to Java you don’t need to implement the interface.
So in my opinion all the things that Graeme complained about were irrelevant in the context of Charles’ post. They are just the blatherings of someone who has a personal issue with someone else’s work for no apparently good reason. I think Charles said it best in his comment on Graeme’s blog
“Come on Graeme…Groovy’s doing fine. Take the high road and let the language live its own life. It will be better for it.”
I agree, Groovy is a good language, and has amazing qualities all on its own, just like Java, C#, Python, SmallTalk and the millions of other languages that exist. There is no need for a language war, especially a one-sided war. I don’t think anyone in the JRuby community is going around saying Groovy is a bad language and shouldn’t be used. In fact even though I am a huge advocate of Ruby and JRuby I supported the idea to look into Groovy and Grails first for our Java stack at work. We came to the conclusion to look into JRuby and Rails because although Groovy is a very mature well balanced language and great enhancement to the Java language, Grails does not seem to have the same level of polish and finesse that the Groovy language has accomplished.
At the end of the day, I applaud Charles for his openness and support for all languages on the JVM. I believe nothing but good things can come from the collaboration of the language implementors, including but not limited to better performance and improved language constructs. And I think it is important to note that my experience with the Groovy community has been nothing but good, current anomaly excluded.