Home » Author Archives: Alex Staveley

Author Archives: Alex Staveley

MongoDB and Grails

groovy-logo

So recently, I had a requirement to store unstructured JSON data that was coming back from a web service. The web service was returning back various soccer teams from around the world. Amongst the data contained in most of the soccer teams was a list of soccer players, who were part of the team. Some of the teams had 12 ...

Read More »

Grails tip: refactoring your URLs

grails-logo

On the current project I am working we use a lot of integration tests. For you non-Grails users out there, Integration tests test your Controller APIs, your Services and any persistence that might happen all very neatly. The only slice of the cake they don’t test from a back end perspective are your Grails filters for which you’d need something ...

Read More »

Groovy Closures: this, owner, delegate let’s make a DSL

groovy-logo

Groovy closures are super cool. To fully understand them, I think it’s really important to understand the meaning of this, owner and delegate. In general: this: refers to the instance of the class that the closure was defined in. owner: is the same as this, unless the closure was defined inside another closure in which case the owner refers to ...

Read More »

Good use of Closures

java-logo

Not long ago, in a blog post, I explained what Closure were in Groovy. This blog post will explain one good example of using them. I recently found myself having to write the same exception handling logic for a bunch of back-end Controller APIs which were serving AJAX requests. It was like this:         class ApiRugbyPlayerController { ...

Read More »

Closures in Groovy

groovy-logo

The simpliest explanation of a closure in Groovy is that it is anonymous function.                   def closure = { println "I am a closure" } closure() // Prints I am a closure Ok, so first point here is that I am a closure is not printed when the closure is defined but ...

Read More »

Groovy’s Smooth Operators

groovy-logo

Take a trip back to 1984.  Apple release the Macintosh, ‘The Final Battle‘ is about to commence in V and Scotland win the Five Nations completing a grand slam in the process.  Right in the middle of miners’ strike in the UK, English pop group Sade release the catchy number: Smooth Operator.  It was chart success in the UK and in ...

Read More »

Grails: Applying build information to your builds

grails-logo

Occasionally, when I buy some food I check the label to see how unhealthy it is in an effort to remind myself to eat better. I probably should do this more often but that’s another story. With software, I take a more strict approach. I like to know exactly what version of what I am using and if it pertains ...

Read More »

How could Scala do a merge sort?

scala-logo

Merge sort is a classical “divide and conquer” sorting algorithm. You should have to never write one because you’d be silly to do that when a standard library class already will already do it for you. But, it is useful to demonstrate a few characteristics of programming techniques in Scala. Firstly a quick recap on the merge sort. It is ...

Read More »

Scala pattern matching: A Case for new thinking?

scala-logo

The 16th President of the United States. Abraham Lincoln once said: ‘As our case is new we must think and act anew’. In software engineering things probably aren’t as dramatic as civil wars and abolishing slavery but we have interesting logical concepts concerning ‘case’. In Java the case statement provides for some limited conditional branching. In Scala, it is possible ...

Read More »

Scala: Collections 1

scala-logo

This post contains some info on Scala’s collections. Problem? We want a function that will take an List of Rugby players as input and return those players names that play for Leinster and can run the 100 meters from the fastest to the slowest. Step 1: Have a representation for a Rugby player. Ok so it’s obvious we want something ...

Read More »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close