In this post, Glen Stampoultzis posts a very interesting and clever sequence of steps by which he converts a piece of Java code into idiomatic Groovy code. I thought it was a nice article, so I'll do a very short spin on it: taking Glen's final Groovy code and converting it into idiomatic Ruby. (I'll probably get my pants flamed …
running intermediate steps
I have no experience of JRuby but it is worth noting that every version on the way from Java to Groovy was runnable on the JVM. This would, therefore, make a nice series of small refactorings to a codebase which has only recently embraced Groovy as well as Java
Ye, and here's the same in python:
def subn(n, list):
if not n : return []
if not list : return 
remainder = list[1:]
return [it+[list] for it in subn(n-1, remainder)] + subn(n, remainder)
4 lines, cleaner synthax. Ruby can suck it. :)
Groovy v Ruby
Nice article, but what I find ironic about this article is that it does more to promote Groovy then Ruby.
What this article is saying to me is that you can almost line by line write ruby like code using groovy.
If that is the case it leaves me with the question, why would any Java developer bother to learn Ruby over Groovy.
After all you can write almost the exactly the same efficient code in Groovy that you can in Ruby, but with Groovy you gain the benefit of it's excellent integration with Java, that is far superior to JRuby.
Java programmers aren't "afraid" or incapable of learning Ruby, any competent Java programmer should be able to easily learn Ruby or almost any language like Python, etc.
What Java programmers worry about is how do you move onto more efficient languages like Ruby, while still maintaining your investment and many years of experience of Java, it's many frameworks, all the thousands of lines of legacy Java libraries you have written and integrate with all you legacy J2EE apps.
The great thing about Groovy is that you have all the benefits of Ruby's terse code, while still being able to maintain complete compatibility with all your existing Java code and libraries.
As an example I'm currently writing many classes in Groovy, compiling them and then deploying them in our legacy Spring application server. Our legacy app server doesn't know anything about Groovy and it doesn't need to know, it just sees byte code files, brilliant.
Basically Groovy allows you to access the best of both worlds.
Ruby is a great language to learn if you are new to programming, but I've yet to hear a single good reason for an experienced Java programmer to move to Ruby over Groovy? What would the benefit be?
- Geek's Guide to Britain INSIDE GCHQ: Welcome to Cheltenham's cottage industry
- 'Catastrophic failure' of 3D-printed gun in Oz Police test
- Game Theory Is the next-gen console war already One?
- Apple cored: Samsung sells 10 million Galaxy S4 in a month
- BBC suspends CTO after it wastes £100m on doomed IT system