Friday, 30 October 2015

Java/Spring vs. Grails

I've just come off a project where I spent a year working with Grails. I remember when I joined the project I wasn't over the moon about the choice of technology, having worked with Grails and Groovy on and off a few times before and not loved it. However, I was looking forward to seeing a 'proper' project written in Grails and perhaps having my mind changed.

Here is a list of the things I liked and didn't like:

Default scaffolding

You can choose if a domain object should have the basic CRUD pages and actions available. There is also some amount of configurability if you'd like to deviate from the norm, but not as much as other frameworks I've seen (e.g. Django).

Useful collections code

In the Java world a lot of time is spent writing code to navigate and perform actions on collections. Groovy adds many useful methods onto the Collection interface such as each, find, and collect, so you can do things like this:

def list = [5, 10, 15, 20, 25, 30]
def result = list.find { it > 10 }


Plugins integrate very closely into your application to change the way that it runs or builds. For example, the HTML resources plugin can be added to make it easier to reference resources in your grails views, 

Testing tools

Spock is a unit testing tool that uses the dynamic nature of groovy to enforce all tests to declare given, when, and then sections. Combined with the fact that you can use spaces in test names, generally the unit tests were very easy to read.

Geb is for testing through the browser, and it's tests follow the same format as Spock tests but allow you to very easily interact with the browser using the page object pattern. Once again you end up with very clear tests.

Browser integration

I was using IntelliJ IDEA which is apparently the best IDE for grails but it was far from perfect. I'm not sure whether it was down to which version of Grails we were using, but running a unit test that might take less than 1 second in Java to run could take up to 10 seconds in Grails. At some points the IDE would decide that it needed to rebuild the whole project first, despite having only changed one line of a test.

Slow startup speed

Even for a simple 'Hello world!' application Grails takes 28 to startup on my machine, whereas a basic Spring Boot application takes 7 seconds. Enough said.

Flexibility breeds inconsistency

Grails does have multiple ways of doing the same thing, such as how you define a method in your controller or how you declare a variable. When I joined the team this had been taken full advantage of and there were many inconsistencies in the code base that we had to iron out.

Code generation

Of course it's better to generate code and config rather than write it yourself but why not do away with it altogether as in Spring Boot? My hello world app in Grails contains reams of configuration that I may want to tweak in the future, but until then it's just adding to the noise.

Overall Grails is a bit of a mixed bag for me, and I'd probably think twice before jumping onto another project with it. It has definitely got its plus points, but for now I'm going to look at some other frameworks to see if there's anything better.

No comments:

Post a Comment