Interview and Book Excerpt: Dave Klein's Grails A Quick-Start Guide
Grails A Quick-Start Guide book, by author Dave Klein, covers Grails web development framework which uses the principle of convention-over-configuration and simplifies the web development compared to the traditional Java based web application frameworks.
In the book, Dave explains how to use Grails by iteratively building a sample web application called TekDays.com. The discussion includes creating all the application architecture components in a typical web application, like the domain classes, controllers, and Groovy Server Pages (GSP) Views. He also discusses the integration of popular Java EE frameworks like Spring and Hibernate with Grails. Other topics covered in the book are Grails Security, Integration Testing, AJAX, Custom Tags and Plugins for Grails UI and Twitter website.
InfoQ spoke with Dave about his book, the main motivation for writing it and other topics. We are also making an excerpt (Chapter 3: Laying the Foundation; 1,098 KB PDF) from the Grails A Quick-Start Guide available for our readers.
InfoQ: What was the main motivation behind writing the Grails A Quick-Start Guide book?
Dave Klein (DK): The idea for the book came from my efforts in bringing co-workers up to speed in Grails. Although they picked it up fairly quickly, I could see that an up-to-date, entry level book would have been a help. But the motivation came from my desire to see more developers and companies adopt Grails. The first step to getting hooked on Grails is to use it, and I wanted to provide a book that would make it easier for people to jump in and take Grails for a spin.
InfoQ: What is the role of Grails framework in Enterprise Application Development space, especially in terms of scalability and performance?
DK: Grails is a great fit for any enterprise that is already using Java. Grails produces a standard JEE WAR that can be deployed to their existing application servers. Grails also integrates very nicely with the many Java libraries and frameworks that these enterprises are already using. There are Grails plugins that allow for easily adding features such as caching, clustering, security, search, web services, etc.
InfoQ: What do you think about the role of Grails as a Domain Driven Development (DDD) framework?
DK: Grails' dynamic and extensible scaffolding makes it easy to apply principles of DDD, without the limits and complexity of some DDD frameworks.
InfoQ: How do you compare Grails with other web frameworks such as Lift and Rails?
DK: Grails borrows many principles and ideas from Rails, as does Lift. But Grails isn't a "Rails Clone". There are many differences in the design, based on Grails' goal of complete and seamless integration with Java and existing Java frameworks, such as Spring and Hibernate. In the end, Grails brings the developer productivity that made Rails such a big success to Java developers with an extremely shallow learning curve.
InfoQ: What is the tool support for application development using Grails framework in terms of developer testing, debugging, refactoring, application profiling etc.
DK: Tool support for Groovy and Grails is constantly improving. With SpringSource putting resources behind the Eclipse plugin and IntelliJ IDEA continuing its excellent support, Grails developers can take advantage of code-completion, debugging, refactoring, etc. There are also Grails plugins that provide easy access to such powerful testing frameworks as Selenium and WebTest, as well as several home-grown Grails testing frameworks. Recently, we've also seen the rise of tools like the Spock testing framework and CodeNarc (the static analysis tool for Groovy and Java).
InfoQ: Can you share your thoughts about Meta Object Protocol (MOP) feature in Groovy?
DK: Groovy MOP is a powerful tool. Without it we would not have Grails: Groovy metaprogramming makes convention over configuration possible. Anyone building a Java-based framework should take a close look at Groovy's MOP.
Besides frameworks, metaprogramming is also helpful in testing. In fact, most of the time that I use metaprogramming on a daily basis is when I'm writing tests. It has almost completely removed the need for mock objects in most of my tests.
InfoQ: What role does Groovy play in creating the Domain Specific Languages (DSLs)?
DK: Groovy's methodMissing and propertyMissing make it easy to create DSLs for almost any purpose. Grails uses this feature to provide DSLs for ORM mapping, wiring Spring beans, and other configurations. Many Grails plugins also provide DSLs to interact with the libraries or frameworks they wrap. All of this is made not only possible but easy with Groovy.
InfoQ: What are some of the best practices and gotchas for the developers who are currently using or planning on using Grails in their applications?
DK: Grails makes it easy to implement a well-designed web application. But it also makes it easy to implement a poorly designed web application. So I would advise developers to resist the temptation to just throw something together, even though Grails makes it so easy to throw something together.
Keep your controllers lean. Move logic into domain classes or services. Keep code out of your views. Take a good look at custom GSP tags.
InfoQ: Are there any features that currently don't exist in Grails framework you would like see added?
DK: I would love to see more plugins - especially plugins that provide integration with other frameworks. The number of plugins is increasing, but there are still many more opportunities.
InfoQ: What do you see as the future of Groovy in general and Grails in particular?
DK: I think the future looks bright for both. Groovy will be around for as long as Java is around, and will continue to gain users as people realize how easy it is to integrate with their existing Java environment. Grails is currently the best web framework on the JVM, and it will continue to improve. Though I don't think any single framework will ever hold the spot that Struts did, I think Grails will become the leading JVM web framework.
InfoQ: What are your favorite IT and non-IT books?
DK: There are so many good IT books that this is a tough question, but my all-time favorites are Code Complete by Steve McConnell, The Pragmatic Programmer by Thomas and Hunt, and Fred Brooks' The Mythical Man-Month. In more recent reading, I have been enjoying the beta copy of Daniel Steinberg's Cocoa Programming and the early access edition of Griffon in Action.
My favorite non-IT book is the Bible, followed by John Bunyan's classic, Pilgrim's Progress.
InfoQ: Thank you Dave.
Keith Adams Dec 06, 2013