Why Grails?

Yoram Gondwe
Developer Circle Lusaka
3 min readMar 7, 2019

Grails is a popular open source web application framework. That is based on the Groovy programming language and the Java Virtual Machine (JVM). Grails has gained appraisal in the software community due to its smart features and ease of use. It is also widely used by some of the worlds biggest brands that have built their products on Grails i.e Netflix, Disney, LinkedIn, Sky, MTV…etc

Understanding Grails further

Grails has been built on some strong shoulders, it is based on trusted and tested frameworks such as the Spring framework. From which it inherits a lot of functionality and plugins. This makes it easy for developers to switch to Grails with ease because it has been built on concepts they already understand.

Let’s look into some reasons why Grails is widely used :

Groovy Programming language

Groovy is a Java-syntax-compatible object-oriented programming language that is both a static and dynamic with features similar to those of Python, Ruby, and Perl. Groovy is considered more concise, expressive and DRY( Do Not Repeat Yourself ) in comparison to Java. This is my favorite part, developers can write less code for the same logic than in Java. Developers do not have to worry about annoying syntax errors such as the famous semicolon ;)} that is so hard to find in java code. This is because of how dynamic the language is, it is optional to use semicolons or declare the data type that you want to use by using keyword def.

Let's Look at some examples between Java and Groovy code:

Defining Methods:

//java codepublic void somthing (){// code does something }//Groovy code
def something(){
//code does something}

For Loops:

 // Java code
for(int i = 0; i < 3; i++) {
System.out.print(“ho “);}System.out.println(“Merry Groovy!”);//Groovy Codefor(i in 0..2) {print ‘ho ‘}println ‘Merry Groovy!’

Or

3.times{print ‘ho’} println ‘Merry Groovy ’

There are definitely more examples that we can use to show how easy it is to write code in Groovy. As we have seen Groovy has a much more simple way of implementing code than that of Java. Another added advantage is that Groovy is fully adaptable to Java Code, this means that you can have a mix of both Groovy and Java code in the same project.

Extensive Plugins

Grails offer over 700 plugins that are developed by the Grails core development team and other enthusiastic grails developers. These plugins improve integration and also heavily reduce the effort of developers when using these plugins.

For example, sending mail using a Grails plugin:

// a Grails Plugin mailService.mail{from ‘yourmail@domain.comto ‘recipient@domain.comsubject ‘Test Mail’text ‘ hello this is a test email’}

Minimal Server Restart

It’s every developer's nightmare to always have to restart their server to recompile after every change. However, that’s not a worry in Grails due to its ability to recompile at run time. Which significantly reduces development time for developers.

There are a few exceptions to when Grails needs a server restart. For example when changes are made to domains and the application.yml

Short learning curve

Developers find it very easy to switch to Grails and commence working, this is much easier for programmers who are familiar with the Java Programming language to adapt to. Simply Grails makes it super easy to write code and brings some excitement to writing web-based applications.

Conclusion

It's important to understand that when selecting a web application framework you must take into consideration how wide its community support. As well as factoring in the ease of use of the framework. Grails has proven to be a strong and versatile framework for building web applications. In my next article, we will look at setting up Grails and building a simple app in grails.

--

--