Wednesday, December 8, 2010

More Groovy Weirdness

I love Groovy.  There is no telling how much time it has saved me in scripting simple tasks.  I do stumble over groovy sometimes though, and it seems it mostly relates to scoping rules.

I am the first to admit, I do not write scripts very 'Groovily'.  It looks more like Java that uses some nice closures when convenient (but, boy are those /really/ convenient).  So I am sure that if I stuck to a more Groove like style I would not run into these problems but today I wrote a simple script.  I put a bunch of variables at the top of the script and ran it and --- Whoops I tripped over a groovy.lang.MissingPropertyException: No such property:  for class exception.

Turns out, in a Groovy script, variables that are not defined within methods /cannot/ have either an explicit type or a def.  This is easy to fix, of course.  Just let Groovy handle the duck typing or turn the script into a class but still, a little surprising.

No comments:

Post a Comment