Groovy

So I can now say that I’ve had my first real project exposure to groovy!

groovy

In this instance it was occupying the space where AWK or SED scripts might have been found in the past. It seems to sit quite naturally here; extending what you might want to do from an ANT script in a consistent/familiar syntax.

It could do much more, pretty much whatever Java can, though I’m not sure I’d be comfortable extending it’s project footprint too much.

Personally, I like the in built mark-up support… (But I’m funny that way.)

import groovy.xml.MarkupBuilder 

def myXMLDoc = new MarkupBuilder(); 

myXMLDoc.customer { 
  title(id:"001", "Mr"); 
  forename("New"); 
  surname("Customer"); 
  address(type:"home"){ 
    number("295"); 
    addressLineOne("Fictitious Road"); 
    addressLineTwo(""); 
    town("Fake Town"); 
    county("Notashire"); 
    postCode("NO1 5NA"); 
  } 
}

The above, in what seems to be a convenient and concise format, gives the following structure:

<customer>
  <title id='001'>Mr</title> 
  <forename>New</forename> 
  <surname>Customer</surname> 
  <address type='home'> 
    <number>295</number> 
    <addressLineOne>Fictitious Road</addressLineOne> 
    <addressLineTwo></addressLineTwo> 
    <town>Fake Town</town> 
    <county>Notashire</county> 
    <postCode>NO1 5NA</postCode> 
  </address> 
</customer>

Whether this is truly useful or just an interesting diversion remains to be seen, at least for me. But, this is a great deal more workable than native Java alternatives.

The homepage for groovy can be found here and a first contact introduction to it can be found here.

comments powered by Disqus