Java Developers! You Should Learn Groovy

I started playing  with Python, Scala,  Ruby and Groovy time to time a couple of years ago. The very first thing that really impressed me was their expressiveness.

java-groovy[1]I really like all of them languages,  but here in this post I’d like to emphasize the benefits of Groovy for Java developers since Groovy is the easiest to learn and  to make transition to a “Java.next()” language for them. 

Groovy is Expressive

Groovy is a very expressive language compared to Java. You can do more using less expressions. Expressions and syntax are very similar to Java, but they are shorter. Actually, some of them are like shortcuts for corresponding Java expressions.

Flat Learning Curve

It has a flat learning curve. It is very easy to understand the code and easy to write for a Java developer.

You can start with Java style coding in groovy  (removing semicolons from java code:) ), and make a smooth transition to groovy style by simply removed redundant keywords, and using shorter (Groovy) version of the expressions.

 “A Java developer embarking on a Groovy adventure will always have Java in mind, and will progressively learn Groovy, one feature at a time, becoming more productive and writing more idiomatic Groovy code. ” [2]

Similar to Java and Also Different from Java

Groovy compiles to Java classes and byte code therefore it can use all of Java platform.

Yes, Java developers, it is like Java you know, it is on JVM. You dont need to learn new environment, and new dynamics of a language.

It extends the JDK. You have all libraries and features from Java, and in addition it provides a number of features from languages such as Python and Ruby. Closures, metaprogramming and dynamic typing are just a few examples of those features.

It also supports DSLs, mini-languages aiming to represent constructs for a given domain.  It helps to make code easy to read and more maintainable.

Groovy has also nice collection processing features. It  eases the creation of collection proving a more natural way. Also,the code is definitely more readable.

Groovy is dynamic and optionally typed language. You can keep types if you want, and also can use dynamic typing. It is nice that you don’t have to worry about typing. I find it very powerful in scripting and writing some quick codes. However, in bigger and enterprise applications you should be careful. It is great that you can write very succinct code but the cost of not knowing what it is being passed back and forth can be sometimes not so nice.

More Productive

By doing more in smaller peice of code, it really feels more productive. For example, let’s say you have an idea and/or design and you just want to write code to implement it quickly. Instead of dealing with syntax of the language, you can concentrate more on the stuff that you are trying to solve.

Scripting Language

It can be used as a scripting language for the Java Platform, and it can be used to have some small hacks on the daily development.  It  is a nice alternative to shell scripting for developers with a Java background.

Warning: Power comes with responsibility

It is true that it is flexible and powerful language with many new feature such as dynamic typing, closures,etc… It can easily go in wrong direction, and you may end up with some maintainable and messy code.

Although Groovy is supported by IDEs such as Eclipse, and IntelliJ , it provides less information for IDE since it is dynamic. The compile time checking, code completion, and refactorings are limited compared to Java.

Conclusion

As conclusion, I strongly recommend Java developers to learn Groovy and start using it somewhere, either as scripting language to do some daily small hacks or in some part of your projects. You will really feel more productive and see the benefits.

Even if you don’t use it anywhere, it will give you a perspective and widen your vision.

And also please keep as a general rule in mind that all languages are like tools in your toolbox. Just use the most suitable one, which is not necessarily the most popular one, not necessarily the one you like most and not necessarily the one you know most. In short, as I said in this blog: No language fanatism!

Happy coding!

References

[1] http://groovy.codehaus.org/ (image)

[2] http://groovy.codehaus.org/Groovy+style+and+language+feature+guidelines+for+Java+developers

About these ads

3 thoughts on “Java Developers! You Should Learn Groovy

  1. Could you please tell me why I should learn Groovy but not Scala? Of course, I won’t expect an answer if you don’t know Scala as well as you know Groovy.

    • Thanks for the comment.

      In the post, I don’t say that you should learn Groovy instead of Scala. If you/they can learn Scala, which requires more time and effort to learn compared to Groovy for a Java developer,it is even better. But since Groovy is easier to learn and you can easily start using it in short time, I have recommended it to learn for Java developers

      By the way, I’m planning to write a similar post on Scala soon.

  2. the addition of language features supporting better code analysis (such as inner classes, the StringBuilder class, optional assertions, etc.), and optimizations in the Java virtual machine itself, such as HotSpot becoming the default for Sun’s JVM in 2000.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s