"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog


Thursday, August 21, 2008


The same three of us have been programming in groovy in ernest for the first time. We've each dinked around a bit at one time or another previously.

Overall I like it. Especially closures and the syntax for block closures when the receiver's last argument is a closure. The spectrum from programming nearly all-like-java on one end of groovy style, and programming nearly all-like-lisp-and-smalltalk at the other end of groovy style flows more smoothly than I initially gave groovy's designers credit for a few years ago.

One quirk - bit me for a dozen minutes or so, the oddity/convenience that groovy wants the keys of a map to be strings. What bit me was the expression...

{ foo: bar}
where foo and bar are variables.

The "convenience" groovy provides is the interpretation of foo as a string, i.e. "foo". The value for the pair is still the result of evaluating bar. So you end up with the pair (if bar is the integer 1)... "foo" : 1

If foo has the value 3 and you'd like the pair to be... 3 : 1 then you have to put foo in parentheses to force evaluation...

{ (foo): bar}
That's the closest thing to a true quirk I've encountered. But for parameter lists, etc. the convenience does pay off in neatness. The result is a very smalltalk-ish keyword message send, and combined with the block closure syntax, is a pleasant and familiar style for smalltalk-lovers. (e.g. coding a seaside-ish web framework using paul-graham-ish closures rather than continuations would be very fitting in groovy.)

Meanwhile the other affect groovy has had is that now when I edit java code, I'm forever not using semicolons at the end of statements.

Oh, and the tools still really suck.


Ed said...

That's very Perly. In Perl the => is a synonym for "," designed to be used between keys and values in hashes; it converts any word to the left of it to a string.

Anonymous said...

Ed, but in Perl there's a meaningful difference between a => $b and $a => $b.

Ed said...

Yeah, in Perl, since "barewords" can't be ordinary variable names, you don't have that same jarring "why is it turning my variable into a string" effect. True.

rektide said...

groovy + maven made me nearly homicidal one late late night / early morning.

in the end i gave up. i just never saw the value add. i stopped using "def" after a week so i could interop better with java, and after that it just looked like java to me.

Patrick Logan said...

"groovy + maven made me nearly homicidal"

On the other hand, groovy + ant = gant, which is a really nice groovy-based build system.

Simple, can run the ant tasks but uses groovy the markupbuilder for writing groovy build files, and you can program it in groovy.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.