Grails from a Django developer point of view
A Django developer
I have been writing Django apps for the last six years. It was my first and only development environment and I get really comfort with it. Writing Django apps is part of my DNA now, I shared some code with some open sources project, etc. Then one day I got a job opportunity as a Grails developer. As I need to get out of my comfort area, I decided to accept.
So I started writing grails apps three weeks ago. Things are pretty different at all levels. In this post I will try to explain the good things and the bad things from my point of view.
Grails is groovy
And groovy has some very interesting goodies. Probably the thing I like more is so called “safe navigation”. With this feature you can write really legible and compact code.
foo = None
if bar and bar.baz and bar.baz.qux and bar.baz.qux.nerf:
for = bar.baz.qux.nerf
becomes
foo = bar?.baz?.qux?.nerf
Another super-cool feature is the default constructor. It accepts a hash map to set the values of the instance member after instantiation, which is pretty handy. Let´s say you have a class like this
class Foo {
String bar
Integer baz
Date qux
Foo() {
qux = new Date()
}
}
Then you can instantiate that class passing values for every member (including “qux”) and it will be st
Foo bar = new Foo(bar: "Puturru", qux: new SimpleDate("dd/MM/yyyy").parse("22/02/1981"))
A similar behavior can be achieved in python using default values
class Foo:
def __init__(self, bar=None, baz=None, qux=datetime.datetime.now())
self.bar = bar
self.baz = baz
self.qux = qux
a = Foo(bar="Puturru", qux=datetime.datetime(1981, 02, 22)
There are many other cool features such as the elvis operator, the closures, and so.
Grails is a JVM language
Everybody knows that java is resource eager and groovy and grails are not singular. For me the most annoying thing is the time consuming. In the project I´m working on the full unit test suite takes about an hour to completed which is absolutely crazy, but even worst pass a simple unit test that test 2 + 2 equals to 4 takes 30s!. It´s really hard to do TDD (or something similar) in this environment.
Another annoying thing is the excess of modularization. In python more than one class can co-exists in the same file, thats the way people write python, however most grails developers come from Java world, and they are used to create a different file for every class, enum or trait they need, thus the projects have tons of files, although groovy can have more than one (public) class per file.