Dynamic Language Syntax

It’s late and I’m working on my 2nd Budweiser (16oz cans). I got no business posting some in depth technical artical. But I gotta tell you how easy it is to build a dynamic language with Groovy. Tonight I took literally 10 minutes to build a basic GSpec like example using the ExpandoMetaClass in Groovy 1.5. I know you don’t know what an expando meta class is. Neither do I. I just grabbed the example from the docs on the Groovy site and ran with it.

In this example I’m adding methods at runtime to a BarPatron object. The net result is an oogly behavior test that specifies that if you set a BarPtron’s favorite drink to a value then that value should be what you set it to. No lie, I put this together in 15 minutes after 2 Buds. And it’s now 11:25pm!

class BarPatron {
    def favoriteDrink

BarPatron.metaClass.invokeMethod = { String name, args ->
    if(name.toLowerCase().endsWith("shouldbe")) {
        def propertyName = name.substring(0, name.toLowerCase().indexOf("shouldbe"))
        assert args[0] == BarPatron.metaClass.getMetaProperty(propertyName).getProperty(delegate)
    def metaMethod = BarPatron.metaClass.getMetaMethod(name, args)
    def result
    if(metaMethod) result = metaMethod.invoke(delegate,args)
    else {
       result = "bar"

obj = new BarPatron()
obj.favoriteDrink = 'Bud Light'
obj.favoriteDrinkShouldBe 'Bud Light'

Now go over here

I did something very generous the a few weeks ago. I took note of how much Neopoleon.com had been suffering in the ratings department (using a highly accurate algorithm written in I think either Java or Groovy) and decided to route all of my incoming traffic to his site. Y’know… gotta help cuz out because his site’s like John Blaze and y’all just ain’t reckognizin’! I tried but for whatever reason my audience was being stubborn and they actually increased visitation to my pages by a whopping 0.5%! So then I was all like, “nah, not here, go over there” to the peoples and I don’t rememberize what actually happened because I stopped looking at my hit counter. I think they went over there. I dunno, I guess I gotta run one of my JUnit program things to do an assertVisitedRorySite() or something.

Today I’d like to make another traffic donation. This time it’s not because this other site is hurting. It’s actually a cool hang out spot. Y’all gotz to peep Astrid on the http://pocketsizedcinematographer.blogspot.com site. I found this spot a while ago reading Rory’s stuff. He was all like, “check out my girl Astrid” in one of his linky things. I hit the spot a few times with the Fox and then I was like, “Yeah I’m feelin’ this”. So head over to Astrid’s for a minute and drop a line. And if you’re into filmy type stuff then check the home page too. She got some John Blaze professional looking clips there.