Using Groovy to test your Groovy assertions over Groovy code examples

…Because I just can’t think of a better title for an article that is so self describing. Hats off to Ted Naleid, I’ll definitely be paying return visits to his site. Many people won’t appreciate the sheer awesomeness of the idea Ted describes. Let me see if I can explain through colorful analogy. Say you’re making a garden. Go ahead, say it… and say it loud enough for a co-worker or passerby turn attention or raised eyebrow in your general direction. Now why would you, an accomplished software designer or general director of technology or whatever your current IT status happens to be (I know you work in IT or else you wouldn’t be reading), why would you suddenly take up gardening in the middle of the work day? Simple! You’re eager to figure out where my idiotic rambling is going to take you. At any rate, I’ll stop embarrassing you long enough to arrive at some sort of tangible conclusion. But before I get back on track, say you’re also a fan of Martha Stewart. Say it out loud as you did earlier and hold your hand in a dainty position slightly bent at the wrist with a pinky extended outward causing even more attention to be directed toward your cubicle. (That’s not as relevant but it sure makes for an interesting exercise in blog reading and I’d love to hear your results at the end of my contorted writing.)

Now as a gardener, fan of Martha, you wish to grow cabbage, tomatoes, and turnip. Pretend now, if you will, that you can use the very tomatoes you grow in your garden to grow the turnip. Pretend further that the turnip could be used to grow the cabbage. Now let’s say that the cabbage is what we used initially to grow the turnip! What we’ve managed to do is create our own self feeding self nourishing garden! Wouldn’t Martha be proud? Now before you contact Mrs. Stewart for air time and/or collaborative television time in our make believe world let’s come up with a name for our phenomenon. Recycled gardening? Veggie Groomed Veggies? Organically grown organics grown from organics grown organically (…from other organ… you get the point, right)? Recursive Horticulture? Got your name picked? Make note of it for the comment section.

Terrible analogies aside, the same idea expressed in our gardening adventure is what Mr. Ted outlined on his blog. He just didn’t get all apron and potted plant about it. Anytime you can use code you’ve written to describe the very code you’ve just written then you’ve done, as Bush says to Brown, “A heck of a job!” Anytime you can use that very same self-describing code to validate the code itself then you’ve done your country an honorable service. Then when you graduate to the next level and use these very same programming exercises to extract your self-describing self-validating examples from the text of an article used to display how John Blaze you are… I dunno… there’s no words, analogies, or urban slang capable of painting such a picture of finesse. Well done Mr. Naleid! Well done…

To find out what the above madness is all about click here and read on. It’s an article on using the Groovy programming language to extract from and article and execute mini Groovy programming examples that also double as mini one line unit tests proving to both the reader and author that the programming logic is correct.

2 thoughts on “Using Groovy to test your Groovy assertions over Groovy code examples

  1. I think the book “Groovy In Action” also used a technique to always have its code examples automatically executable.

  2. Yes it does. GnA is one of my favorite books and it is the first place I learned about the technique. Ted’s example reminded me of that and it includes the source code to parse and run the source snippets. You’re right however, in that all the credit should not go to Ted. Deirk is the man… at least until I learn if/who he stole his style from.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s