I am waiting for Scott Davis’ show to begin. He is still busy signing his book, Groovy Recipes :-) and I just noticed I don’t have that book yet… what a shame, have to order or get it today. Scott is also the creator of aboutGroovy.com, a news site dedicated purely to Groovy news.
Damn no Wifi in this room… what the hell is going on with JavaOne? I better keep writing this to Stickies instead of the online wordpress blog post page.
Scott makes a bold point that Groovy/Java Integration is seamless, really seamless. Mentioning the Foreword of Groovy in Action by James Gosling: smooth and efficient integration with Java. Other scripting languages got many syntactic mismatches… for Java Developers Groovy is painless.
Rest of the session will be live coding. He covers: Method Pointers, Operator Overloading, Closures, ExpandoMetaClass (invokeMethod,methodMissing)
Uses Textmate. Starts with a Hello World Java example. Javac’s it, runs it. Now the same in groovy. Of course that’s println ‘Hello Groovy’ :-) done. He talks about some more basics of Groovy like optional parenthesis.
Method Pointers
Make a great example of method pointers in Groovy and how it helps to create dsls.
songs = [1,2]
load = songs.&add
load 3
println songs
[1,2,3]
Moves on to GroovyBeans and all the stuff you don’t have to write… semicolons, return statements, gettter/setter. Also gives an example for GStrings, you should order one.
Closures & ExandoMetaClass
Jumping into a basic closure example and then comparing for-loop in Java to Groovy’s Integer.times() method that results in sth. like 7.times {println ‘hi’}. He also covers operator overloading, example with Date and using ++ to advance to the next day. He is now extending String with String.metaClass.methodName to add a shout() method that upperCases a String. Nice eye-opener I guess. So we moved into the next topic, ExpandoMetaClass (the coolest thing on earth).
He explains why this is a great feature for testing. You can just replace calls to real functionality with a fake method. He recommends to get started with Groovy with testing… Testing as an drug.
Jumping into the goodness of the GDK, quickly showing some examples (most for java.io.File).
Whoops. We missed the TestCase. Creating one. Extending form GroovyTestCase and testing his new Ipod class he used for the previous examples. We are adding the leftShit method to add Song objects to the Ipod via << new Song().
Scott now talks about invokeMethod / methodMissing. Grails GORM methods are a good example for the methodMissing. These methods don’t exist, but Grails then parses the method name and creates the queries accordingly.
That’s the end. Scott is a very enthusiastic speaker, great session. Hope to meet him later on and chat with him. I am off to upload that text and then head to the next sesion. I think it is a press only panel about dynamic languages. I hope Guillaume can be here as he was not confirmed.