Get in the Groove.. Groovy Style

Groovy . besides the funky name is a really cool dynamic scripting language to learn. Let me ask you a question: Do you key in all your code in java ? if you answer ‘yes’ then you are 50% groovy expert already. otherwise, well its never too late to be productive. If you are like me coding  in java and following the ancient write –> compile –> execute cycle over and over again until you see what you want / your PM wanted . Then you walk proudly across the office corridor to the PM’s room and say : “This is what i was working on this week/month/year and there you go”.  This is a usual routine in software development. The sooner you can bring the smile on your manager’s face the sooner you will be appreciated. With groovy you can bring it on in hours/ days.

As much as i like java and appreciate its realization of OO concepts deep down there are things I hate in java. If you are thinking & coding in java 24×7 chances are, you will stumble upon those annoying things soon. One such annoyance: clashing of class names imported from different packages say java.util.List and java.awt.List . You may end up prefixing one of the class usage with package path. Welcome to groovy world. Here you will find that you can do something like,

import java.util.List as UtilList
import java.awt.List as AwtList
UtilList list=new ArrayList ()                                                                             
list<<1

Surprise,surprise this code actually runs if you run groovyc or groovy on the file (although it might output empty []). I am going to miss my late friend : “ public static void main“ .

If you are a python  programmer you may not be impressed by the above but guess what : your language doesn’t run on a JVM and embed with java code without compromising  performance greatly and don’t even get me started on Jython.

Surprisingly you will notice that your code can be compiled to a corresponding java class file [ jad classFile   - to see the generated file ]. from that point on jvm sees everything as class. This gives enormous edge for groovy over other dynamic languages because undeniably a significant number of organizations use java for developing their products. You may not regret spending weekend learning groovy. I am sure most of the things you learn in groovy ( be it currying, meta programming ) will make you cry “ duh!! wish i had known this before” . Have fun groovying around :)

Leave a Reply