Getting Started with Grails

Grails is an open-source, rapid web application development framework that provides a super-productive full-stack programming model based on the Groovy scripting language and built on top of Spring, Hibernate, and other standard Java frameworks.

At least that’s what the marketing hype says.

My take – Grails is an open-source answer to Rails for the Java Enterprise crowd.  It’s got all the flexibility of Ruby on Rails with the added benefit of being able to quickly leverage Java SDK resources from within the underlying language (called Groovy).  I’ve recently been working with Grails and a can say it’s an excellent platform for rapidly developing web front-ends that can work with your existing enterprise infrastructure.  Even better, it can work with almost seamlessly with your current/legacy Java application codebase.  But the trick to all of this is getting started.  The available documentation that you find online could be FAR better (and I’ll talk about that in other posts) but here are some resources and books that I’ve found to be excellent starting points.

Programming Groovy: Dynamic Productivity for the Java Developer

by Venkat Subramaniam

Vslg To become proficient at Grails, you need to understand the Groovy Programming language, it’s constructs, and it’s importance in contrast to the Java ecosphere. Dr. Subramaniam’s book provides an excellent foundation and starting point. I’ve kept the printed edition in my backpack with me and refer to it regularly. I’ve found the information and insights Dr. Subramaniam provides to be invaluable.You can order the printed and PDF book editions at the Pragmatic Programmer’s Website:


http://pragprog.com/book/vslg/programming-groovy

Getting Started with Grails, Second Edition

Scott Davis & Jason Rudolph

LandingPageCoverSo you’ve started reading about Groovy, but you need to find out more about Grails… This book is the next logical step in that progression. Davis’ and Rudolph’s book provides a step-by-step example showing how to create a basic application (called Racetrack) that takes you along the same development lines that the Depot application in the Dave Thomas/David Heinemeier Hansson Rails book does. You’ll learn how to leverage the underlying Hibernate layer via GORM (Grails Object Relational Mapping), connecting to external databases, the basics for developing robust MVC-based applications using GSP and Grails controllers, implementing basic security and user authentication, and working with the vast plugin library available to Grails developers. The best part is you can the book is in a “try before you buy” model. You can download the book for free from the InfoQ website, and if you find you like the book and find it useful, you can support the author’s efforts and buy a print version. I found the book valuable and was able to get a basic version of an application completed for a project in a day after working through the Racetrack example.

http://www.infoq.com/minibooks/grails-getting-started

The Groovy Language Homepage

Before you can do Grails – you need to get Groovy. Go here and get your Groove on.

http://groovy.codehaus.org/

The Grails Quick Start

Get grails direct from the source at Grails.org. If you want to spin up a Grails application and you are familiar with Ruby and Rails – this will get you going fast. Be sure to read the Installation section for getting the Grails environment configured and running before you use the Quick Start or you’ll get nowhere fast.

http://grails.org/Quick+Start

Seconds, Minutes, Hours – Converting Time Units in Ruby

I’m sure you’ve probably seen this question in your programming classes.. I decided I wanted to play with Ruby again and was remind of this problem, so thought it might be fun as a simple exercise to do this in Ruby.

The problem is to take a long integer and convert it to hours, minutes and seconds. This is a common issue in games, for example, where a countdown timer is represent internally in seconds. But players don’t want to see some huge number like 43678 seconds. They’d rather see 12:07:58 for hours, minutes and seconds. A couple of uses of the mod operator, and a couple of uses of the built-in formatter and you’re good to go.
Update: I wanted to clean up the code a bit more and put the ruby equivalent of a “main” via the __FILE__ check. This way you can just reuse the code via require if you so desire.

#!/usr/bin/env ruby

class TimeFormatter

  def format_time (timeElapsed) 

    @timeElapsed = timeElapsed

    #find the seconds
    seconds = @timeElapsed % 60

    #find the minutes
    minutes = (@timeElapsed / 60) % 60

    #find the hours
    hours = (@timeElapsed/3600)

    #format the time

    return hours.to_s + ":" + format("%02d",minutes.to_s) + ":" + format("%02d",seconds.to_s)
  end
end

if __FILE__ == $0
  formatter = TimeFormatter.new

  puts formatter.format_time(43678)
end

SQLite3 and ‘No Such File to Load’ errors

While I was playing with Rails 2.1 I decided to try the SQLite3 support that comes built into OS X instead of using MySQL. Upon trying to run a migrate command via rake I was created with:

	rake aborted!
	no such file to load -- sqlite3/database

After some digging around I found out that (for at least a few people) having the sqlite3-ruby-1.2.2 gem installed creates this problem… The following resolved it:

	gem uninstall sqlite3-ruby

	Select gem to uninstall:
	 1. sqlite3-ruby-1.2.1
	 2. sqlite3-ruby-1.2.2
	 3. All versions
	> 3

	daorriss$ sudo gem install sqlite3-ruby -v=1.2.1
	Building native extensions.  This could take a while...
	Successfully installed sqlite3-ruby-1.2.1
	1 gem installed
	Installing ri documentation for sqlite3-ruby-1.2.1...
	Installing RDoc documentation for sqlite3-ruby-1.2.1...

After that rake db:migrate worked without a hitch. But if anyone could tell me what could cause the problem with sqlite3-ruby-1.2.2 I’d appreciate it.. :)

Zed Shaw: Rails is a Ghetto

Mongrel Developer/Creator, Zed Shaw, cut loose on the Ruby and Rails communities in a recent posting to his website. He gives some interesting insights into who the major players are, and cuts through some of the hype surrounding rails.

While caustic in his delivery, he makes excellent points about the industry in general. If you’re a .NET developer – you won’t like the jabs in it. If you’re a VB.NET developer – find another blog – you shouldn’t be here anyway – much less reading Zed’s stuff. Most of what I write probably shoots right over your head, anyway.

But I digress.. while reading his rant, Zed got me thinking about Rails and the actual availability of work for Rails developers. Especially when he mentions the fun times he had with the Raymond James Vancouver offices (his mistake there was working for a company that deals in financial data – oh the stories I could tell about Actuaries). Anyway… the question I asked myself is simple enough – what if I actually needed to find a job doing Rails development in Seattle right now? I was rather disappointed to see in the midst of all of the Rails-hype that there are only three jobs involving Rails in the Seattle area at the time I write this (according to Monster.com). One of them is for a small dot-bomb shop, one is for Amazon (I’d rather eat hot lead then work at Amazon) and one is actually a System Administrator/Tech Support position and involves no development at all.

I was talking about this exact situation with one of my friends who works for a major software tools vendor (No, not Microsoft – my .NET developer friends know better than to try to sell me on their shallow J2EE ripoff). I was talking to him about that there’s all of this hype around Rails.. but I’m not seeing any real job demand for it. This wandered into the a discussion about biggest Rails Hypefest of them all – RailsConf. People come from miles around to get dipped in the Rails Kool-Aid and renew their momentum for the Rails Hype Machine. About how Rails is the Next Big Thing(sm).. about how Rails is the next Java only bigger and better!!

Now… lots of hype.. the “next big thing”… where have I heard this before..? Something about “Write Once, Run Anywhere”…

Anyway… What he said to me about RailsConf was what I had largely noticed. Most of the attendees are basically kids with little or no practical industry experience who think Ruby on Rails is the up and coming thing and want to ride that wave. And Zed’s right – there really are people in that community that are saying that if you love Visual Basic and ColdFusion then you should come over to Ruby on Rails. Why? Because the VB programmers got found out for the lousy coders they are and got rousted out of the J2EE developer community??

Don’t get me wrong… I love Rails… And Ruby is a fun language to code in. I still love Java and J2EE and I’m very proud of the work I’ve done in it. However, Java was hyped so badly when it came out that it really hurt the technology and my ability to evangelize it. So much so in fact that for a while I was having a hard time finding work. Worse yet, Sun still hasn’t learned their lessons and still tries to hype garbage technologies with little actual value. And Rails really has a ton of potential to be a “Next Big Thing”. But they need to do less hype and focus on keeping their community together and working on solid tools. Yes.. that includes learning to get along with the crazy brother that everyone hates, but everyone also knows is right.