May 13, 2009

RESTful Services In Groovy are Insanely Elegant

As a programmer, I long ago realized that you spend a disheartening (and often unaccounted-for) portion of your development cycle building the plumbing of the application.

One of the turn ons of using Grails / Groovy was the promise of avoiding the usual, tedious tasks of framework gluing, XML configurating, exception handling, and copy-and-pasting reams of useless, brittle boiler-plate code. As advertised, I’ve yet to touch a line of XML, and though I’ve been using Grails/Groovy for near-on two years, I’m still shocked by how little code it takes to do something useful. 

Look at this snapshot of my TwitpicsService class. I’m first making a call to an arbitrary image provider (via HTTP) to download the raw source image. Then I make a call to Twitpics REST service to upload the file back to them, essentially, the entire “Capture” functionality of Twitcaps is implemented in these few lines of code. 49 to be precise. And 12 of those are imports!

Screenshot of TwitpicsService class

If you’re a Java programmer and you’ve ever tried to do something similar (RESTful or not), you’d know that this same functionality could take many hundreds of lines more to implement in any sort of robust, unbreakable manner. 

I’m not usually one to evangelize a particular technology. I consider myself a sober technology generalist who’s always up for using the best tool for the task at hand.

The more I use Grails/Groovy, the more I find myself talking it up and recommending it to friends for just about any reason. I’ve been slinging code for well over a decade and, honestly, I’ve never had so much fun in the process.

Dynamic languages allow you to focus on coding the fun stuff, the purely functional bits that you had in mind at the genesis of your brilliant idea. Count me as a big fan.

  1. twitcaps posted this