Still Life
Dads cooking Saturday afternoon. Sports report on the radio, Newcastle win, bliss.
Groovy and Closures
Groovy and Grails (Ruby too) make a big thing of closures. A closure is defined, slightly unhelpfully, as:
A Groovy closure is like a “code block” or a method pointer. It is a piece of code that is defined and then executed at a later point.
If you are not use to them they can be tricky to grasp but they are hugely powerful and in many cases make code easier to read. See my cheesey code to print out the files in a directory:

This is using the Groovy eclipse plugin of course
The only problem with closures is that they are manna are from heaven to the lets-write-the-code-in-least-amount-of-lines-brigade. You know the sort of people, they chain a load of functions and objects together in one line and then stick a regular expression on the end. The technical term for these people, I believe, is bastards.
Sexy mobile groovers
- Taken at 7:25 PM on April 04, 2008 - cameraphone upload by ShoZu
Over the Air
Sweating at the back of the Google Gears pres.
Hanging with the Paxmo possie
- Taken at 4:38 PM on April 04, 2008 - cameraphone upload by ShoZu
Theatre of dreams!
- Taken at 11:53 AM on March 29, 2008 - cameraphone upload by ShoZu
Groovy and Ruby
Up till now I have used Ruby for the odd scripting job, just to get into the language as it were. One script I use regularly is a one that opens a url a 100 times and sleeps for a few seconds in between. Here is the Ruby code:
require 'net/http'
require 'uri'
response = ''
for i in 0 ... 100
puts(i)
url = URI.parse('http://localhost:8080/frontier/batchProcess.html')
res = Net::HTTP.start(url.host, url.port) {|http|
response=http.get('/frontier/batchProcess.html')
}
puts(response)
sleep(10);
end
as I have gone all Groovy, I decided to re-write this in Groovy. It is very similar but slightly more familiar for us Java herberts:
println "start"
for(i in 1..100) {
url = new URL("http://localhost:8080/frontier/batchProcess.html")
s = url.getText()
println s
println "sleeping ${i}"
sleep(2000)
}
println "stop"
I think that familiarity could be key.
Finally, I had some friends over on the week and they spotted my “Groovy Programming book”. Oh how they laughed and pointed at me. Sigh.
Glastonbury 2008 - The Field of Avalon
Festival Ukes will be at the Glastonbury Festival again this year. We have moved and now will be in the Field of Avalon.
Lets hope it doesn’t ming down with rain again.
;-)
Grails Object Relational Mapping
“Stone me! that’s a boring blog title, can’t we have more stuff about Ukuleles or pictures of pints of beer” I hear you cry.
Well no.
Grails has a nice way of mapping domain objects together, see these objects for a pretend GTD app:
class Project {
String description
String type
Integer priority
Date dueDatestatic hasMany = [ nextActions:NextAction]
static constraints = {
description(nullable:false,length:1..50)
type(inList:[”Home”,”Work”])
type(nullable:false)
}}
class NextAction {String description
String context
String notes
Integer prioritystatic constraints = {
description(blank:false,length:5..30)
context(nullable:false,blank:false,inList:[”email”,”errand”])
}static belongsTo = Project
}
Hopefully you can easily see the magic here. The hasMany and belongsTo settings join these two objects together in one to many relationship. Better still when you run the Grails app it auto generates the database schema for these objects and an intermediate table to join em - possibly a bit too normalized for me but still.
Even better, if I choose to add a new property to one of the classes the application relaunches after I make the save and the new column is added to the database schema.
Oooo its like magic.
Sure beats the make change, add some xml, recompile, look out of window and restart context hell of normal Java development. Sigh.
Books, Mac and Light Sabre
I’ve got the Groovy book, the Grails book, the MacBook and the light sabre …… and yeah a light sabre.
Ruby on Rants
Bloke behind the Mongrel servery thing for Ruby goes nutty rant loontastic.
I have a big soft spot for people who swear a lot.



