Monday, April 19, 2010

Grails Over Rails

After a few research around rapid application development tools and frameworks, I started to try Groovy and Grails. This just happened after a couple of weeks using of Ruby on Rails. Ruby on Rails has excited me when I knew Groovy and Grails. I have had some difficulties with Ruby on Rails at initiating days that I didn't touch them again during using of Groovy and Grails.

At first I needed to install Grails. This was as much easy as you imagine. Later, I have explained how I installed Ruby on Rails on Ubuntu Linux in the previous article in current web log that shows rails installation needs some struggles to the end of deployment. But, Grails installation is just like a piece of cake in my experience. There is a binary version that is available as a zipped file that just needs to download and extract it. Then you should set two environmental variable. I am using Grails on Ubuntu Linux. So I had to fix a stupid bug at first try. In fact, Groovy and Grails are more indicated for Java developers because they can leverage their knowledge on Java platform and they can also turn to Java whenever they feel so, since Groovy runs on top of JVM. After all you have Spring and Hibernate ready available. Grails is very easy to get started with for Java developers. Also, You'll be able to continue using the same libraries that you used to (among many other things). The wide and enriched Java libraries are mostly accessible to your Grails application. All the code you developed and bug fixed routines are reusable in the Groovy applications. So you wont repeat all you have done.

I think Grails follows Rails track but in a more organized way. The main different is Java compatibility of Grails I think. If you try to deploy a Rails application on a JEE application server you will find that there is not a straight forward procedure at all. I found that setting up the environment to develop Rails application needs gathering some very dependent components that you have to arrange them just like a puzzle and I don't know why they did not put them all in the same package!. In the opposite, Grails gives the same functionality by a more consistent and integrated solution. For making a war of the Grails application that you developed, this is enough to give it a "grails war" in the root folder of the application.

Furthermore I found Groovy scripts meaningful and more conceptual. This may be just because the background I had from Java. I know Ruby is so abstracted and sharp but I used to explain exactly what I need, even by using a bit more symbols and reserve words. I cant feel the Japanese culture of Ruby short hands!

Here is a piece of Groovy code:

class User {
String name
String email
String webpage
static constraints = {
name (blank:false, nullable:false, size:3..30, matches:"[a-zA-Z1-9_]+")
email (email:true)
webpage (url:true)
}

String toString(){
return name;
}
}

I have never seen any implementation of the validation routines as much simplified as Groovy codes. The "constraints" block has described validation rules clearly. Email and webpage validations are brilliant:

email (email:true)
webpage (url:true)

I think Grails accelerates the outlet of the development process for the everyone who needs to build Java compatible web applications using new generation of RAD tools and scripts.

During working with Grail I've used this article from Lars Vogel. This could be an easy tutorial that shows how Grails works.

1 comment: