Why I’m not using Groovy at work

Posted on December 14, 2009. Filed under: Grails, Groovy, Uncategorized | Tags: , , |

A disclaimer: this blog is based on my personal failures with getting Grails accepted in our company. So, no, this is not the holy grail into dropping your EJB, Struts or Java toolkit to get groovy with Grails, but maybe you can learn something on how NOT to do it, and post some comments on your experience.

2.5 Years ago, I got my first cup of Grails. It was some time before the Groovy/Grails Exchange 2007, which I visited consecutively. As a result of that visit, I had Graeme Rocher over to our company to give a presentation about Grails (almost 0.4 at that time), and I expected the rest to follow naturally (the rest being: drop all our Java development and take up Grails for all of our web development). I was a little naive in that, I experienced the couple of months after that. Not even did we not drop all our Java development: we dropped none, nor did we picked up any of the cool features Groovy or Grails offered. Instead, people went crazy with frameworks like Wicket, SEAM and other cool stuff, like..ehh…EJB’s…

However, in my spare time I never left Grails and I used it for a lot of prototype applications, especially because the ease of setting up a complete project with Spring/Hibernate integration, etc. And also because it’s just fun to use the power the Grails framework harnesses. Anyway, I never could convince people to seriously use it. I inspired some people to use it, but only for short periods. The lack of IDE support didn’t help in that, and with the thousands of frameworks around, you’ve got to make a choice somewhere. However, I haven’t given up on Grails, and I still try to use it as much as possible. So, when I started for myself in April as an independent (though I do favor certain technologies!) consultant, I thought: this is my chance! I can now focus on Grails technologies. However, even though I’m not quite inexperienced with Grails, I found it hard to find a good (well, any actually) project which was open to Grails, so I found a different project, in which I could focus on other things (like ATDD/TDD, XP, and other quality related things).

However, then, all of a sudden my manager showed some interest in Grails (might not be the best reason to use Grails btw, but it’s great that this is without any resistance!), and we decided to take on a project in Grails. There, the problems started. (Note: I don’t blame anyone in this, except myself: I should have used a different approach. That’s part of reason for writing this blog, to prevent you from making the same mistakes).

What I did first, was tell a little bit about Grails to explain the team how Grails works. That was actually my first mistake. I should have told them lots, lots, a little more, and everything again after that. I thought the transition would be easy, but they were struggling with the framework and the language. I didn’t expect this, to be honest. My expectation (and experience) is that Grails is easy to start with. Get a book, read the documentation, and your ready to go. We built a good prototype, got great feedback on it! However, the old habit kicked in.

Building Grails
First, we tried to build our Grails application with Maven. Bad idea, since it caused some nasty challenges, like getting the code coverage to appear, and getting come quality metrics with tools like CodeNarc. However, you’ll still have to do your (transitive?) dependency management, releasing of software, reports, etc, so there’s something to say for using Maven. It didn’t quite work for us, however, and we spent quite some time into bending it into something which worked for us, which failed. I still haven’t found a viable alternative to Maven. Gradle is nice, Ivy + Ant/Gant seem okay, but that’s not nowhere near the power (I wouldn’t say flexibility) I got with using Maven. I do not, however, make this a Maven vs Whatever Build Tool discussion. I just happen to like Maven for it’s reports, plugin integration, dependency support and modular structure.

Then I also had to overcome the resistance of some of our team members to dynamic languages. Some people prefer the (fake, IMO) safety a statically typed language provides with it’s compilation process. Well, there’s no helping you if you do an Integer.parseInt(“abc”) in your Java code: it will fail just as badly. At runtime. That’s why we write tests, to cover cases like this. This is true for Java, and it’s just as true for Groovy. However, there was still a lot of FUD about Groovy’s usage in bigger projects regarding refactoring, tool support, and even performance. Well, to be honest: I have no idea how easy it is to refactor Groovy code, but, with less code to write, there’s less to refactor. While this might be a bit short sighted, I feel it holds true for a lot of cases.

The tool support deserves a paragraph on it’s own. Eclipse + Groovy was not a good combination. At all. It was bad, worse, and even a bit worse than that. Even if you are the genius to get it to work (or would I say madmen, since a genius would choose a tool like NetBean or IntelliJ, or, heck, TextMate), you still wouldn’t be able to run a decent unit test in it. Did I mention refactoring? I didn’t, for a good reason: No Support For Refactoring. Let me rephrase that: No Support For Refactoring… in Eclipse. Then why choose Eclipse, and not a great tool like IntelliJ (I’m referring to the 8 release) or NetBeans you might ask. To be honest: I have no idea. I don’t use Eclipse. I’ve used IntelliJ for the last 5 years, and only recently I’m switching to SpringSource Tool Suite because of JetBrains’ ridiculous decision to not show module dependencies in the project view. I hope they get some rest after the release of IntelliJ 9, and see the light to put it back in. Until that period, STS is a really good substitute, and has excellent Groovy and Grails support, which is getting better each day!

The right approach?
So, if I would introduce Groovy or Grails again at my work, I would:
– Pick the right people. People who are not intimidated by a dynamic language, but who have the discipline to use it right.
– Pick the right people. People who are prepared to make a switch. To switch from IDE, switch from build tool, switch from language.
– Pick the right people. People who have the mentality to make it work, overcome challenges and share their findings.

It wasn’t intentional to put ‘Pick the right people’ there, but I think that this is the critical factor to make it work. Make it work from within the team, and make it work from outside of the team (IT operations, Management, etc). I’m looking forward into hearing your responses to this. I hope it doesn’t sound to bitter, cause I’m not. I just made the wrong choices with a partially not-suitable team. It’s my mistake, and I don’t blame anyone but me. I just hope people can learn from my experiences, and the post from Marc Palmer was just the right incentive to finish this post. I hope it helps!

Read Full Post | Make a Comment ( 12 so far )

Gr8 conference in Denmark, 2010

Posted on December 10, 2009. Filed under: Grails, Groovy |

At the 19th and 20th of May 2010,the GR8 conference will be held. From the website: “The GR8 Conference is an affordable conference dedicated to the Groovy dynamic language, the Grails web framework, the Griffon Swing framework, and other great technologies — hence the pun and code name GR8.”. The agenda is not officially known yet, but from good sources I have heard that (ofcourse) Guillaume Laforge will come, as well as know speakers like Andreas Almiray, Mr Haki (from the well known Groovy Goodness series, Sebastian Blank with his iWebkit plugin, Phillippe Delebarre, and many more. With a lineup like this, it’s a conference not to be missed, so checkout the site, which will be open for registration soon, and enjoy some Groovy and Grails quality time in Denmark!!

Read Full Post | Make a Comment ( None so far )

Converting Groovy Objects to JSON using Grails

Posted on February 14, 2009. Filed under: Grails, Groovy, Uncategorized | Tags: , , , |

Disclaimer: this might not be the best way to do it. I’m open for improvements, but it’s a way I’m using now, and it works pretty nice!

Currenly, I’m creating an application which does some JSON communication. Since Grails already has nice support for JSON, I wanted to reuse their libraries, but, at the moment, I don’t need a complete web Grails application. So, the plan was to reuse the JSON (deep) converters to convert my Groovy classes to JSON, and work with that. I created the following small test to try to accomplish what I wanted:

import grails.converters.JSON

class Person {
String name = "erik"
int age = 10

println new JSON(new Person()).toString()

Well, I don’t think I’d be writing this blog entry if things were really this easy. Executing the above code fails with a nasty NullPointerException:

Caught: org.apache.commons.lang.UnhandledException: java.lang.NullPointerException
	at testjson.main(testjson.groovy)

Why is this, you might ask. Well, it turns out the JSON converter is using a ConverterUtil class, which expects a GrailsApplication. When there’s no GrailsApplication, the code will fail with a NPE as a result. If you’d like to see this fixed: I’ve created a JIRA issue here.

However, I did came up with a workaround. It’s not perfect, but it works. Since the ConvertUtil is a sort of Singleton, you call it yourself, and set a DummyGrailsApplication instead. Well, instead of the dummy version, we can use a DefaultGrailsApplication instead. So, after our fix, the code looks like this:

import grails.converters.JSON
import org.codehaus.groovy.grails.commons.DefaultGrailsApplication
import org.codehaus.groovy.grails.web.converters.ConverterUtil

class Person {
String name = "erik"
int age = 10
ConverterUtil.getInstance().grailsApplication = new DefaultGrailsApplication()
println new JSON(new Person()).toString()

When running this, the following output is produced:


Which is exactly what we want!

Read Full Post | Make a Comment ( 4 so far )

IntelliJ JSON Formatter Plugin

Posted on February 5, 2009. Filed under: Grails, IntelliJ JSON Formatter Plugin | Tags: , , , , , |

I’ve just created my first IntelliJ plugin, a JSON formatter. Since I work a lot with Groovy and Grails, and Grails supports JSON so nicely, it’s sometimes necessary to debug the JSON code going back and from the client to the Grails backend. However, since the JSON code is stripped from whitespaces, it’s a bit harder to read than a nested structure. To format the JSON, you can use various websites , but it requires a context switch (from IDE to Webbrowser), plus it requires an Internet connection. To solve this, I created an IntelliJ JSON Formatter plugin, which nicely hooks into IntelliJ. To give you an idea of what the plugin looks like, please take a look at the following image:

IntelliJ JSON Formatter plugin

This images gives an impression of a formatted piece of JSON code, and also includes brace matching and coloring thanks to the RSyntaxTextArea. The JSON code is parsed with the help of the JSON tools from Berlios.

You can install the plugin by using IntelliJ’s integrated plugin manager. If you’ve used it, please give me some feedback! I’d like it!

Read Full Post | Make a Comment ( 11 so far )

Liked it here?
Why not try sites on the blogroll...