Can I get down now dad?

Tramps like us, baby we were born to code

Groovy and Closures

Groovy and Grails (Ruby too) make a big thing of closures. A closure is defined, slightly unhelpfully, as:

A Groovy closure is like a “code block” or a method pointer. It is a piece of code that is defined and then executed at a later point.

If you are not use to them they can be tricky to grasp but they are hugely powerful and in many cases make code easier to read. See my cheesey code to print out the files in a directory:


This is using the Groovy eclipse plugin of course

The only problem with closures is that they are manna are from heaven to the lets-write-the-code-in-least-amount-of-lines-brigade. You know the sort of people, they chain a load of functions and objects together in one line and then stick a regular expression on the end. The technical term for these people, I believe, is bastards.

36 Responses to “Groovy and Closures”

  1. Rob McDonagh Says:

    Bastards, indeed. Sometimes we call ‘em feckers, too. :D

  2. Biplob Says:

    My opinions:For muloceles with less than 9 bond closures: never reuseFor muloceles with more than 9 bond closures, but no more than 9 closures are interweaved/intermixed in any one group: reuse, but with the change over happening between groups (e.g. you might get 1-5 and then 1-6). Bonus points if there’s a large linear linker under the changeover.Cycle-of-cycle muloceles where everything is intermixed due only to a few large macrocycles: Use without reuse the low numbers for the macrocycle, and then reuse the remaining ones for the disconnected subgroups, as above.Large hairy muloceles where everything is intermixed and interconnected without an easy way of seperating them into sub-groups: Do whatever works. You’re unlikely to understand the structure without some SMILES -> Figure program anyway, so does it really matter?

  3. erectile Says:

    Help, I’ve been informed and I can’t become ignorant.

  4. auto insurance quotes Says:

    One or two to remember, that is.

  5. cialis Says:

    I thank you humbly for sharing your wisdom JJWY

  6. levitra discussion Says:

    Going to put this article to good use now.

  7. car insurance understanding Says:

    Thinking like that is really impressive

  8. auto insurance quotes Says:

    Finding this post solves a problem for me. Thanks!

  9. viagra online Says:

    A wonderful job. Super helpful information.

  10. cheap viagra without prescription Says:

    Just do me a favor and keep writing such trenchant analyses, OK?

  11. cialis sale Says:

    Pleasing you should think of something like that

  12. sildenafil Says:

    Impressive brain power at work! Great answer!

  13. where to buy cialis Says:

    Great hammer of Thor, that is powerfully helpful!

  14. buy viagra Says:

    Stellar work there everyone. I’ll keep on reading.

  15. car insurance quotes nj Says:

    Your answer was just what I needed. It’s made my day!

  16. car insurence Says:

    How neat! Is it really this simple? You make it look easy.

  17. levitra generic Says:

    I feel satisfied after reading that one.

  18. levitra cheap Says:

    Free info like this is an apple from the tree of knowledge. Sinful?

  19. buy cialis Says:

    Son of a gun, this is so helpful!

  20. pfizer viagra Says:

    I hate my life but at least this makes it bearable.

  21. cheap Viagra in Atlanta, GA Says:

    Thanks for sharing. Always good to find a real expert.

  22. online colleges Says:

    Good points all around. Truly appreciated.

  23. distance learning Says:

    That’s going to make things a lot easier from here on out.

  24. car insurance quotes Says:

    This is both street smart and intelligent.

  25. buy isotretinoin without prescription Says:

    That’s a brilliant answer to an interesting question

  26. buy valtrex without prescription Says:

    That kind of thinking shows you’re an expert

  27. whole GA life insurance quotes Says:

    If you want to get read, this is how you should write.

  28. cheap auto insurance Texas Says:

    Unbelievable how well-written and informative this was.

  29. Says:

    Finally! This is just what I was looking for.

  30. Says:

    That’s a slick answer to a challenging question

  31. Says:

    That’s a creative answer to a difficult question

  32. Says:

    Appreciation for this information is over 9000-thank you!

  33. cialis Says:

    In awe of that answer! Really cool!

  34. Says:

    Now I’m like, well duh! Truly thankful for your help.

  35. nhl 17 Says:

    say thanks to so a lota lot for your site it assists a lot

Leave a Reply

Couldn't find your convert utility. Check that you have ImageMagick installed.