You can do that in Groovy…


So I’m in the middle of some iPhone work… knee-deep in some tricky ObjC code where I have to use a Log file to gather timings, yuk! The last thing on any sane developer’s mind would be the Groovy programming language. But this story isn’t about your average iPhone/Mac engineer. Hi, I’m Cliff. You’re here because you didn’t think you could do that in Groovy. “Do what in Groovy?”, you might ask. “Wash your delicates without ruining them.” I might respond. Then you might twist you face/nose or grimace or show some look of confusion. ‘Sall good. I’m known for blurting out things that make absolutely no sense to any body outside of my own skull. I’m also known for laughing out of place and making jokes that nobody else considers comical. I’m used to the blank stares and awkward silence at the tail end of what was my funniest punch line yet. Keep reading and you too can learn the intense look of disapproval. Keep coming back and you might even eventually learn to appreciate my writing, love me, and possibly become addicted to what most would consider egg-headed prose.

Back to our story. So then I copy/paste some cryptic log output into TextMate. Listen close because this is where the story gets all gravy. I’m looking at this garble of percent signs and numbers that used to be a series of URLs before they became URL encoded. (Why would anyone URLEncode a URL? That’s just as dumb as wetting your water… eating your mouth… lathering your bar of soap! Don’t worry. There’s a perfectly invalid reason why I do most of the backward things I try not to do.) I need to visually compare the results of what my log message spit back to me with some earlier text I copied/pasted into text mate. The question to be answered is, “do deese URLs be duh same as dose URLs? Duuuuhhh…” In a perfect world I’d be able to click a button and have a 35 pixel wide line stretch across the screen. Its reddish or greenish hue would tell the tale of failure or success respectively. We don’t live in a perfect world. Instead we live in a world where engineers find it far more productive to perform the mundane visual analysis of log files than to click little happy/angry buttons that make frogs dance or croak in response to the overall question, “did I finish my task?” (Wouldn’t a dancing/croaking frog be a really nice extension to a xUnit runner? Do they have such a thing? Maybe somebody can make one for xCode.)

Back to the story again. In order to answer my “do deese URLs…” question I need to unravel the work that my “alls yuh haff tuh do is…” programming logic balled up into a knot. That’s when it dawns on me. I’m in text mate right? Right! I know Groovy pretty well right? Yes. I’m familiar enough with the JDK to know how to untwist a string of URL encoded text right? You bet’cha! And doesn’t the Groovy bundle in TextMate have one of those Run-My-Selected-Snippet thing-a-ma-bobbers? Are you following where this is going? That’s right! I was going to rewrite the entire iPhone application in Groovy using the run selected code snippet bundle feature for unit testing! …No that wasn’t where I was going… not yet at least. I figured I could copypast the URL in my Untitled TextMate document and paste it into a clean area of whitespace. I was then going to surround it with an ad-hoc Groovy call:
println URLDecoder.decode(‘ ‘)

For those rare moments when the Java-side of your brain wants to run something through the JVM for identification/validation/verification remember… you can do that in Groovy. And if you happen to be lucky enough to run on a Mac with TextMate installed, Groovy is right at your finger tips!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s