Agile Coding Dojo #2
For this second event, Agile Vietnam chose to code in Groovy. Groovy, just like Java runs on the JVM. They invited me to present the simplicity of Groovy syntax over Java syntax. See the slides here.
At the end of the presentation, Hiep Le (the event organizer) asked me if there were situations where Java would be better than Groovy. Below is a my detailed comparison between the two languages.
Java VS Groovy
Strengths of Java
- Faster: That’s because Groovy does a lot of runtime change. This impacts performance of code. In fact, Groovy has been shown to better 2x-8x slower than Java.
- Better IDE and Tool support. This is important for two reasons:
- Better code completion
- Better debugger
- Better code analysis
- More developers: it’s harder to hire experienced Groovy programmers. In Vietnam, I have yet to meet someone who is coding in Groovy. Still, Groovy is the second most popular JVM language.
- Strict language: Java is more “friendly” for inexperienced developers. Groovy is dynamic and flexible: you can write the same code in many different ways. Of course, you can write Java looking code in Groovy; in a team however, it can be challenge to enforce consistent code.
- Java uses strong typing, Groovy uses duck typing. I personally think duck typing makes code less understandable.
- Java forces catching of almost exceptions, Groovy doesn’t force catching. Sometimes it’s ok not to catch exceptions. Most of the time it’s not. With Java, a young programmer is forced to deal with errors from the program. With Groovy, he doesn’t: this will eventually lead to problems.
- Easier to debug: Again, because Groovy does a runtime code changes, it’s hard for it to trace back runtime errors.
Strengths of Groovy
- Rapid development: Groovy code is easier to write. The Grails framework (Rails for Groovy) makes rapid development a breeze.
- Better maintainability: Groovy code is easier to read. From personal experience, converting Java code to Groovy saves 30-50% lines of code. Everyone loves savings.
- Great support for XML and JSON.
- Flexible syntax: you can adjust the complexity of the syntax with your needs. You can write simple Groovy syntax for simple scripts or testing. You can write Java looking code in Groovy for other situations.
It’s all about the situation
In general, between technology A and B, neither is better. Technology A is stronger in some situations, B is stronger in other situations. It’s important to make the right technology choice for the right situation.
So where would Java be best?
The answer is: I don’t know. I have worked on tech startups products for most of my career. Small team with very talented developers.The biggest strengths of Groovy is code maintainability and speed of development. Those strengths are great benefits in early stage product startups. The biggest weakness of Groovy is runtime performance. For apps that connect to the internet however, network performance will more of a priority.
One guess is that Java is probably better in complex desktop enterprise applications at a big company. But I haven’t worked on one of those for a long time.