SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
to Infinity
                           and Beyond
mercredi 9 décembre 2009
Guillaume Laforge

       •Groovy Project Manager
               – working on Groovy since 2003
       • G2One ➜ SpringSource ➜ VMWare

       • Initiated the creation of Grails

       • Co-author of Groovy in Action

       • Speaker: JavaOne, QCon, Devoxx, JavaZone,
         SpringOne, JAX, DSL DevCon, Google I/O, and
         many more...

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   2
mercredi 9 décembre 2009
About the content

       • This presentation was prepared with the examples
         I’ve used in my article written for InfoQ
               – http://www.infoq.com/articles/groovy-1-6


       • And from the release notes I’ve prepared for
         Groovy 1.7
               – http://docs.codehaus.org/display/GROOVY/(draft)
                 +Groovy+1.7+release


       • For more information, don’t hesitate to read those
         two articles!


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   3
mercredi 9 décembre 2009
Groovy 1.7
                            for Christmas

                           • Groovy 1.7-RC-2
                             shall be released
                             today! (Dec. 9th)

                           • Groovy 1.7-final
                             should be with the
                             other presents under
                             your Christmas tree!
                             (Dec. 22nd)



mercredi 9 décembre 2009
Playing with Groovy

       • You can play with
         these examples
         within the
         Groovy Web Console
         hosted on
         Google App Engine
               – Uses Groovy 1.7-RC-1




               – http://groovyconsole.appspot.com

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   5
mercredi 9 décembre 2009
nd a
                   Ag e
                                                                                            • Past (Groovy 1.6)

                                                                                            • Present (Groovy 1.7)

                                                                                            • Future (Groovy 1.8+)




    Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   6
mercredi 9 décembre 2009
nd a
                   Ag e                                                                     • Past (Groovy 1.6)
                                                                                                    – Syntax enhancements
                                                                                                    – Compile-time metaprogramming
                                                                                                    – The Grape module system

                                                                                                    – Miscelanous
                                                                                                            •Runtime metaprogramming
                                                                                                             additions
                                                                                                            •Built-in JSR-223 scripting engine
                                                                                                            •JMX Builder
                                                                                                            •OSGi readiness




    Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.                7
mercredi 9 décembre 2009
Multiple assignments

       • Newly defined variables
               – def (a, b) = [1, 2]
                 assert a == 1 && b == 2

       • Typed variables
               – def (int a, int b) = [1, 2]

       • Assign to existing variables
               – def lat, lng
                 (lat, lng) = geocode(‘Paris’)

       • The classical ‘swap case’
               – (a, b) = [b, a]


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   8
mercredi 9 décembre 2009
More optional returns

       • Return value of last expression of the last if/else,
         try/catch, switch/case statement

       • def m1() { if (true) 1 else 0 }

       • def m2(b) {
             try {
                 if (b) throw new Exception()
                 1
             } catch(any) { 2 }
             finally { 3 }
         }
         assert m2(false) == 1 && m2(true) == 2
    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   9
mercredi 9 décembre 2009
Compile-time
      metaprogramming

       • With metaprogramming, Groovy’s able to modify
         the behaviour of programs... at runtime

       • Groovy 1.6 introduced AST Transformations
               – AST: Abstract Syntax Tree
               – Ability to change what’s being compiled at compile-time!
                      •No runtime impact!
                      •Lets you change the semantics of your programs!
                      •Nice way of implementing patterns and removing boiler-
                       plate technical code


       • Two kinds of transformations: global and local

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   10
mercredi 9 décembre 2009
AST Transformations
      in Groovy 1.6

       • Several transformations finds their way
               – @Singleton — okay, not really a pattern :-)
               – @Immutable, @Lazy, @Delegate
               – @Newify
               – @Category and @Mixin
               – @PackageScope
               – Swing’s @Bindable and @Vetoable
               – Grape’s @Grab


       • Let’s have a look at some of them



    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   11
mercredi 9 décembre 2009
The @Singleton anti-pattern

       • The evil Java singleton
               – public class Evil {
                     public static final Evil instance =
                         new Evil();
                     privavte Evil() {}
                     Evil getInstance() { return instance; }
                 }
       • In Groovy now:
               – @Singleton class Evil {}


       • A lazy version also:
               – @Singleton(lazy = true) class Evil {}


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   12
mercredi 9 décembre 2009
@Immutable

       • To properly implement immutable classes
               – No mutators (state musn’t change)
               – Private final fields
               – Defensive copying of mutable components
               – Proper equals() / hashCode() / toString() for
                 comparisons, or for keys in maps, etc.

               – @Immutable class Coordinates {
                     Double lat, lng
                 }
                 def c1 = new Coordinates(lat: 48.8, lng: 2.5)
                 def c2 = new Coordinates(48.8, 2.5)
                 assert c1 == c2

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   13
mercredi 9 décembre 2009
@Lazy, not just for lazy dudes!

       • When you need to lazily evaluate or instantiate
         complex data structures for class fields, mark them
         with the @Lazy annotation

               – class Dude {
                     @Lazy pets = retrieveFromSlowDB()
                 }


       • Groovy will handle the boiler-plate code for you!




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   14
mercredi 9 décembre 2009
@Delegate
      Not just for managers!

       • You can delegate to fields of your class
               – Think multiple inheritance

               – class Employee {
                     def doTheWork() { "done" }
                 }
                 class Manager {
                     @Delegate Employee slave = new Employee()
                 }
                 def god = new Manager()
                 assert god.doTheWork() == "done"


       • Damn manager will get all the praise...

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   15
mercredi 9 décembre 2009
Grab a Grape

       • Groovy Advanced Packaging Engine
               – Helps you distribute scripts without dependencies
               – Just declare your dependencies with @Grab
                      •Will look for dependencies in Maven or Ivy repositories

               – @Grab(     group = 'org.mortbay.jetty',
                           module = 'jetty-embedded',
                          version = '6.1.0' )
                    def startServer() {
                        def srv = new Server(8080)
                        def ctx = new Context(srv , "/", SESSIONS)
                        ctx.resourceBase = "."
                        ctx.addServlet(GroovyServlet, "*.groovy")
                        srv.start()
                    }
    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   16
mercredi 9 décembre 2009
ExpandoMetaClass DSL

       • Before
               – Number.metaClass.multiply = { Amount amount ->
                         amount.times(delegate)
                 }
                 Number.metaClass.div = { Amount amount ->
                     amount.inverse().times(delegate)
                 }
       • In Groovy 1.6
               – Number.metaClass {
                     multiply { Amount amount ->
                         amount.times(delegate)
                     }
                     div { Amount amount ->
                         amount.inverse().times(delegate)
                     }
                 }
    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   17
mercredi 9 décembre 2009
Runtime mixins

       • Inject new behavior to types at runtime

               – class FlyingAbility {
                     def fly() { "I'm ${name} and I fly!" }
                 }

                    class JamesBondVehicle {
                        String getName() { "James Bond's vehicle" }
                    }

                    JamesBondVehicle.mixin FlyingAbility

                    assert new JamesBondVehicle().fly() ==
                        "I'm James Bond's vehicle and I fly!"


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   18
mercredi 9 décembre 2009
Miscelanous

       •JMX builder
               – A new builder for easily exposing, interacting with JMX
                 beans, listening to event, defining timers, etc.
       •OSGi
               – Groovy’s JAR is already OSGi compatible by sporting the
                 right attributes in the manifest
       •JSR-223
               – An implementation of the javax.script.* APIs is now part
                 of Groovy by default
       •Swing console
               – Customizable graphical representation of results
               – Clickable stacktraces and error messages
               – Drag’n Drop, code indentation, add JARs to the classpath
    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   19
mercredi 9 décembre 2009
nd a
                   Ag e                                                                     • Present (Groovy 1.7)
                                                                                                    – Inner classes
                                                                                                    – Annotations
                                                                                                    – Grape enhancements
                                                                                                    – Power asserts
                                                                                                    – AST viewer and AST builder
                                                                                                    – Customize the Groovy Truth




    Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.       20
mercredi 9 décembre 2009
AIC and NC

       • AIC: Anonymous Inner Classes
         NC: Nested Classes

       • For Java-compatibility sake, we’re brining AIC / NC
         support into Groovy
               – copy’n paste compatibility? :-)


       • Not much to see beyond the usual standard Java
         AIC / NC concept




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   21
mercredi 9 décembre 2009
Annotations everywhere!

       • Groovy supports of annotations since Groovy 1.5
               – a couple minor differences, for instance for arrays


       • In Groovy 1.7, you can add annotations on
               – imports
               – packages
               – variable declarations


       • Handy for Grape!

       • Source-level annotations, available through the AST

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   22
mercredi 9 décembre 2009
Terser Grape

       • Ability to put the @Grab annotation on imports!
               – @Grab(group = 'net.sf.json-lib',
                      module = 'json-lib', version = '2.3',
                  classifier = 'jdk15')
                 import net.sf.json.groovy.*
                 def root = new JsonSlurper().parseText(...)


       • Put @Grab on variable declarations and use the
         shorter notation
               – @Grab('net.sf.json-lib:json-lib:2.3:jdk15')
                 def builder =
                     new net.sf.json.groovy.JsonGroovyBuilder()



    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   23
mercredi 9 décembre 2009
Grab resolver

       • Dependencies aren’t always available in Maven’s
         repository, so you may need to specify a different
         place to search libraries
               – before, one had to modify grapeConfig.xml


       • Groovy 1.7 introduces a Grape resolver
               – @GrabResolver(name = 'restlet.org',
                               root = 'http://maven.restlet.org')
                 @Grab(group = 'org.restlet',
                      module =' org.restlet', version='1.1.6')
                 import org.restlet.Restlet
                 // ...


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   24
mercredi 9 décembre 2009
Power Asserts

       • Enhanced assert statement and output
               – def energy = 7200 * 10**15 + 1
                 def mass = 80
                 def celerity = 300000000
                 assert energy == mass * celerity ** 2




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   25
mercredi 9 décembre 2009
AST transformations

       • With Groovy 1.6 came AST transformations

       • But...
               – you need a deep knowledge of the Groovy internals
               – it’s not easy to know what the AST looks like
               – writing transformations can be pretty verbose


       • Groovy 1.7 introduces
               – an AST viewer
               – an AST builder



    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   26
mercredi 9 décembre 2009
AST Viewer




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   27
mercredi 9 décembre 2009
AST Builder

       • Ability to build AST parts
               – from a String
                      •new AstBuilder().buildFromString(''' "Hello" ''')

               – from code
                      •new AstBuilder().buildFromCode { "Hello" }

               – from specification
                      •List<ASTNode> nodes
                           = new AstBuilder().buildFromSpec {
                           block {
                               returnStatement {
                                   constant "Hello"
                               }
                           }
                       }
    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   28
mercredi 9 décembre 2009
Customize the Groovy Truth!

       • Ability to customize the Groovy Truth by
         implementing of method boolean asBoolean()

       • Your own predicate
               – class Predicate {
                     boolean value
                     boolean asBoolean() { value }
                 }

                    assert new Predicate(value: true)
                    assert !new Predicate(value: false)




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   29
mercredi 9 décembre 2009
nd a
                   Ag e                                                                     • Future (Groovy 1.8+)
                                                                                                    – Extended annotations
                                                                                                    – DSL: command statements
                                                                                                      improvements
                                                                                                    – Pattern matching
                                                                                                    – Parser combinators
                                                                                                    – New MOP
                                                                                                    – JDK 7
                                                                                                            •Project Coin
                                                                                                            •Simple closures for Java
                                                                                                            •InvokeDynamic




    Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.                  30
mercredi 9 décembre 2009
Groovy 1.8
          and beyond...


       • Caution!

       • The following features are still
         subject to discussion, and may
         very well never see
         the light of day!




mercredi 9 décembre 2009
Groovy 1.8, end of 2010

       • Plan to provide various runtime improvements to
         make Groovy faster and faster

       • Make Groovy more modular
               – Probably using Grape’s module system
               – Breaking Groovy into smaller JARs
                      •not everybody needs everything (JMX, SQL, Swing...)

       • Align Groovy with JDK 7 / Java 7
               – Review project coin proposals where it makes sense
               – Incorporate / integrate with InvokeDynamic (JSR-292)
               – Interoperate with Java simple closures

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   32
mercredi 9 décembre 2009
Extended annotations

       • Go beyond Java 5,
         and let annotations support more type parameters
               – closures, lists, maps, ranges


       • Possible use cases
               – validation, pre- and post-conditions

               – @Validate({ name.size() > 4 })
                 String name

               – @PreCondition({ msg != null })
                 void outputToUpperCase(String msg) {
                     println msg.toUpperCase()
                 }

    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   33
mercredi 9 décembre 2009
Command-expression
      based DSL

       • Groovy lets you omit parentheses for top-level
         expressions, and mix named and non-named
         arguments

       • Idea: extend to nested/chained expressions
               – send "Hello" to "Jochen"
                 send "Hello", from: "Guillaume" to "Jochen"
                 sell 100.shares of MSFT
                 take 2.pills of chloroquinine in 6.hours
                 every 10.minutes { }
                 given { } when { } then { }
                 blend red, green of acrylic



    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   34
mercredi 9 décembre 2009
Pattern matching

       • Structural pattern matching on PO(J|G)Os
       • First experiments will be done as module
               – if successful, likely integrated in core

       • term.match { // or match(term) {}
             Num(value) {}
             Plus(left, right) {}
             Num(value: 5) {}
             Num(value > 0) {}
             Plus(left: Plus(left: a, right: 2), right) {}
             Plus(left: a, right: b) | Minus(left: a, right: b) {}
             Object(left, right) {}
             nothing { }
         }



    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   35
mercredi 9 décembre 2009
Parser combinators

       • Same as pattern matching, experiments need to be
         done as a module, before possible integration in
         core
               – Also need Groovy modularity to be implemented


       • def language = grammar {
            digit: ~/[0-9]/
            letter: ~/[a-zA-Z]/
            identifier: letter + ( letter | digit ){n}
            number: digit{n}
         }
         grammar.parse(...)


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   36
mercredi 9 décembre 2009
nd a
                   Ag e
                                                                                            • Summary

                                                                                            • Questions & Answers




    Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   37
mercredi 9 décembre 2009
Summary

       • Groovy, still inovative, since 2003!
               – Newever versions always bring their share of new
                 features and libraries to simplify the life of the developer
               – And there’s more to come!


       • But Groovy’s more than just a language, it’s a very
         active and lively ecosystem with tons of great
         projects
               – Grails, Gradle, GPars, Spock, Gaelyk, etc...


       • Enjoy the conference!


    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   38
mercredi 9 décembre 2009
Questions & Answers




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.   39
mercredi 9 décembre 2009
Photo credits

       •     Buzz LightYear: http://bu77lightyear.files.wordpress.com/2008/09/buzzlightyear_high.jpg
       •     Christmas tree: http://www.thedailygreen.com/cm/thedailygreen/images/WT/christmas-tree-with-gifts-flipbook.jpg
       •     Caution: http://www.disastersuppliesusa.com/catalog/ee44.jpg
       •     Light bulb: https://newsline.llnl.gov/retooling/mar/03.28.08_images/lightBulb.png




    Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.        40
mercredi 9 décembre 2009

Weitere ähnliche Inhalte

Ähnlich wie Groovy, to Infinity and Beyond - Groovy/Grails eXchange 2009

Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Guillaume Laforge
 
Groovy overview, DSLs and ecosystem - Mars JUG - 2010
Groovy overview, DSLs and ecosystem - Mars JUG - 2010Groovy overview, DSLs and ecosystem - Mars JUG - 2010
Groovy overview, DSLs and ecosystem - Mars JUG - 2010Guillaume Laforge
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...Guillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
Groovy-Eclipse at Eclipsecon2010
Groovy-Eclipse at Eclipsecon2010Groovy-Eclipse at Eclipsecon2010
Groovy-Eclipse at Eclipsecon2010guest9ff00
 
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Guillaume Laforge
 
GR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrencyPaul King
 
Google Web Toolkit for the Enterprise Developer - JBoss World 2009
Google Web Toolkit for the Enterprise Developer - JBoss World 2009Google Web Toolkit for the Enterprise Developer - JBoss World 2009
Google Web Toolkit for the Enterprise Developer - JBoss World 2009Fred Sauer
 
Django Deployment with Fabric
Django Deployment with FabricDjango Deployment with Fabric
Django Deployment with FabricJonas Nockert
 
GR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting GrailsGR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting GrailsGR8Conf
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeKlausBaumecker
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVMjexp
 

Ähnlich wie Groovy, to Infinity and Beyond - Groovy/Grails eXchange 2009 (20)

Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010Groovy 1 7 Update, past, present, future - S2G Forum 2010
Groovy 1 7 Update, past, present, future - S2G Forum 2010
 
Groovy overview, DSLs and ecosystem - Mars JUG - 2010
Groovy overview, DSLs and ecosystem - Mars JUG - 2010Groovy overview, DSLs and ecosystem - Mars JUG - 2010
Groovy overview, DSLs and ecosystem - Mars JUG - 2010
 
Groovy
GroovyGroovy
Groovy
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
RubyConf 2009
RubyConf 2009RubyConf 2009
RubyConf 2009
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...
Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at...
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
Groovy-Eclipse at Eclipsecon2010
Groovy-Eclipse at Eclipsecon2010Groovy-Eclipse at Eclipsecon2010
Groovy-Eclipse at Eclipsecon2010
 
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
 
Intro To Git
Intro To GitIntro To Git
Intro To Git
 
GR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk KönigGR8Conf 2009: Groovy Usage Patterns by Dierk König
GR8Conf 2009: Groovy Usage Patterns by Dierk König
 
groovy and concurrency
groovy and concurrencygroovy and concurrency
groovy and concurrency
 
Processing
ProcessingProcessing
Processing
 
Golang
GolangGolang
Golang
 
Google Web Toolkit for the Enterprise Developer - JBoss World 2009
Google Web Toolkit for the Enterprise Developer - JBoss World 2009Google Web Toolkit for the Enterprise Developer - JBoss World 2009
Google Web Toolkit for the Enterprise Developer - JBoss World 2009
 
Django Deployment with Fabric
Django Deployment with FabricDjango Deployment with Fabric
Django Deployment with Fabric
 
GR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting GrailsGR8Conf 2011: Adopting Grails
GR8Conf 2011: Adopting Grails
 
Adopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf EuropeAdopting Grails - GR8Conf Europe
Adopting Grails - GR8Conf Europe
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVM
 

Mehr von Guillaume Laforge

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Guillaume Laforge
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Guillaume Laforge
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Guillaume Laforge
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Guillaume Laforge
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Guillaume Laforge
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Guillaume Laforge
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGuillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Guillaume Laforge
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Guillaume Laforge
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Guillaume Laforge
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Guillaume Laforge
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Guillaume Laforge
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovyGuillaume Laforge
 

Mehr von Guillaume Laforge (20)

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013
 
Groovy 2 and beyond
Groovy 2 and beyondGroovy 2 and beyond
Groovy 2 and beyond
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012
 
Groovy 2.0 webinar
Groovy 2.0 webinarGroovy 2.0 webinar
Groovy 2.0 webinar
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012
 
JavaOne 2012 Groovy update
JavaOne 2012 Groovy updateJavaOne 2012 Groovy update
JavaOne 2012 Groovy update
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012
 
Whats new in Groovy 2.0?
Whats new in Groovy 2.0?Whats new in Groovy 2.0?
Whats new in Groovy 2.0?
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
 
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovy
 

Kürzlich hochgeladen

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

Groovy, to Infinity and Beyond - Groovy/Grails eXchange 2009

  • 1. to Infinity and Beyond mercredi 9 décembre 2009
  • 2. Guillaume Laforge •Groovy Project Manager – working on Groovy since 2003 • G2One ➜ SpringSource ➜ VMWare • Initiated the creation of Grails • Co-author of Groovy in Action • Speaker: JavaOne, QCon, Devoxx, JavaZone, SpringOne, JAX, DSL DevCon, Google I/O, and many more... Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2 mercredi 9 décembre 2009
  • 3. About the content • This presentation was prepared with the examples I’ve used in my article written for InfoQ – http://www.infoq.com/articles/groovy-1-6 • And from the release notes I’ve prepared for Groovy 1.7 – http://docs.codehaus.org/display/GROOVY/(draft) +Groovy+1.7+release • For more information, don’t hesitate to read those two articles! Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3 mercredi 9 décembre 2009
  • 4. Groovy 1.7 for Christmas • Groovy 1.7-RC-2 shall be released today! (Dec. 9th) • Groovy 1.7-final should be with the other presents under your Christmas tree! (Dec. 22nd) mercredi 9 décembre 2009
  • 5. Playing with Groovy • You can play with these examples within the Groovy Web Console hosted on Google App Engine – Uses Groovy 1.7-RC-1 – http://groovyconsole.appspot.com Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5 mercredi 9 décembre 2009
  • 6. nd a Ag e • Past (Groovy 1.6) • Present (Groovy 1.7) • Future (Groovy 1.8+) Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6 mercredi 9 décembre 2009
  • 7. nd a Ag e • Past (Groovy 1.6) – Syntax enhancements – Compile-time metaprogramming – The Grape module system – Miscelanous •Runtime metaprogramming additions •Built-in JSR-223 scripting engine •JMX Builder •OSGi readiness Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7 mercredi 9 décembre 2009
  • 8. Multiple assignments • Newly defined variables – def (a, b) = [1, 2] assert a == 1 && b == 2 • Typed variables – def (int a, int b) = [1, 2] • Assign to existing variables – def lat, lng (lat, lng) = geocode(‘Paris’) • The classical ‘swap case’ – (a, b) = [b, a] Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8 mercredi 9 décembre 2009
  • 9. More optional returns • Return value of last expression of the last if/else, try/catch, switch/case statement • def m1() { if (true) 1 else 0 } • def m2(b) { try { if (b) throw new Exception() 1 } catch(any) { 2 } finally { 3 } } assert m2(false) == 1 && m2(true) == 2 Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9 mercredi 9 décembre 2009
  • 10. Compile-time metaprogramming • With metaprogramming, Groovy’s able to modify the behaviour of programs... at runtime • Groovy 1.6 introduced AST Transformations – AST: Abstract Syntax Tree – Ability to change what’s being compiled at compile-time! •No runtime impact! •Lets you change the semantics of your programs! •Nice way of implementing patterns and removing boiler- plate technical code • Two kinds of transformations: global and local Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10 mercredi 9 décembre 2009
  • 11. AST Transformations in Groovy 1.6 • Several transformations finds their way – @Singleton — okay, not really a pattern :-) – @Immutable, @Lazy, @Delegate – @Newify – @Category and @Mixin – @PackageScope – Swing’s @Bindable and @Vetoable – Grape’s @Grab • Let’s have a look at some of them Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11 mercredi 9 décembre 2009
  • 12. The @Singleton anti-pattern • The evil Java singleton – public class Evil { public static final Evil instance = new Evil(); privavte Evil() {} Evil getInstance() { return instance; } } • In Groovy now: – @Singleton class Evil {} • A lazy version also: – @Singleton(lazy = true) class Evil {} Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12 mercredi 9 décembre 2009
  • 13. @Immutable • To properly implement immutable classes – No mutators (state musn’t change) – Private final fields – Defensive copying of mutable components – Proper equals() / hashCode() / toString() for comparisons, or for keys in maps, etc. – @Immutable class Coordinates { Double lat, lng } def c1 = new Coordinates(lat: 48.8, lng: 2.5) def c2 = new Coordinates(48.8, 2.5) assert c1 == c2 Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13 mercredi 9 décembre 2009
  • 14. @Lazy, not just for lazy dudes! • When you need to lazily evaluate or instantiate complex data structures for class fields, mark them with the @Lazy annotation – class Dude { @Lazy pets = retrieveFromSlowDB() } • Groovy will handle the boiler-plate code for you! Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14 mercredi 9 décembre 2009
  • 15. @Delegate Not just for managers! • You can delegate to fields of your class – Think multiple inheritance – class Employee { def doTheWork() { "done" } } class Manager { @Delegate Employee slave = new Employee() } def god = new Manager() assert god.doTheWork() == "done" • Damn manager will get all the praise... Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15 mercredi 9 décembre 2009
  • 16. Grab a Grape • Groovy Advanced Packaging Engine – Helps you distribute scripts without dependencies – Just declare your dependencies with @Grab •Will look for dependencies in Maven or Ivy repositories – @Grab( group = 'org.mortbay.jetty', module = 'jetty-embedded', version = '6.1.0' ) def startServer() { def srv = new Server(8080) def ctx = new Context(srv , "/", SESSIONS) ctx.resourceBase = "." ctx.addServlet(GroovyServlet, "*.groovy") srv.start() } Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 16 mercredi 9 décembre 2009
  • 17. ExpandoMetaClass DSL • Before – Number.metaClass.multiply = { Amount amount -> amount.times(delegate) } Number.metaClass.div = { Amount amount -> amount.inverse().times(delegate) } • In Groovy 1.6 – Number.metaClass { multiply { Amount amount -> amount.times(delegate) } div { Amount amount -> amount.inverse().times(delegate) } } Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 17 mercredi 9 décembre 2009
  • 18. Runtime mixins • Inject new behavior to types at runtime – class FlyingAbility { def fly() { "I'm ${name} and I fly!" } } class JamesBondVehicle { String getName() { "James Bond's vehicle" } } JamesBondVehicle.mixin FlyingAbility assert new JamesBondVehicle().fly() == "I'm James Bond's vehicle and I fly!" Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18 mercredi 9 décembre 2009
  • 19. Miscelanous •JMX builder – A new builder for easily exposing, interacting with JMX beans, listening to event, defining timers, etc. •OSGi – Groovy’s JAR is already OSGi compatible by sporting the right attributes in the manifest •JSR-223 – An implementation of the javax.script.* APIs is now part of Groovy by default •Swing console – Customizable graphical representation of results – Clickable stacktraces and error messages – Drag’n Drop, code indentation, add JARs to the classpath Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19 mercredi 9 décembre 2009
  • 20. nd a Ag e • Present (Groovy 1.7) – Inner classes – Annotations – Grape enhancements – Power asserts – AST viewer and AST builder – Customize the Groovy Truth Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20 mercredi 9 décembre 2009
  • 21. AIC and NC • AIC: Anonymous Inner Classes NC: Nested Classes • For Java-compatibility sake, we’re brining AIC / NC support into Groovy – copy’n paste compatibility? :-) • Not much to see beyond the usual standard Java AIC / NC concept Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21 mercredi 9 décembre 2009
  • 22. Annotations everywhere! • Groovy supports of annotations since Groovy 1.5 – a couple minor differences, for instance for arrays • In Groovy 1.7, you can add annotations on – imports – packages – variable declarations • Handy for Grape! • Source-level annotations, available through the AST Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 22 mercredi 9 décembre 2009
  • 23. Terser Grape • Ability to put the @Grab annotation on imports! – @Grab(group = 'net.sf.json-lib', module = 'json-lib', version = '2.3', classifier = 'jdk15') import net.sf.json.groovy.* def root = new JsonSlurper().parseText(...) • Put @Grab on variable declarations and use the shorter notation – @Grab('net.sf.json-lib:json-lib:2.3:jdk15') def builder = new net.sf.json.groovy.JsonGroovyBuilder() Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 23 mercredi 9 décembre 2009
  • 24. Grab resolver • Dependencies aren’t always available in Maven’s repository, so you may need to specify a different place to search libraries – before, one had to modify grapeConfig.xml • Groovy 1.7 introduces a Grape resolver – @GrabResolver(name = 'restlet.org', root = 'http://maven.restlet.org') @Grab(group = 'org.restlet', module =' org.restlet', version='1.1.6') import org.restlet.Restlet // ... Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 24 mercredi 9 décembre 2009
  • 25. Power Asserts • Enhanced assert statement and output – def energy = 7200 * 10**15 + 1 def mass = 80 def celerity = 300000000 assert energy == mass * celerity ** 2 Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 25 mercredi 9 décembre 2009
  • 26. AST transformations • With Groovy 1.6 came AST transformations • But... – you need a deep knowledge of the Groovy internals – it’s not easy to know what the AST looks like – writing transformations can be pretty verbose • Groovy 1.7 introduces – an AST viewer – an AST builder Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 26 mercredi 9 décembre 2009
  • 27. AST Viewer Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 27 mercredi 9 décembre 2009
  • 28. AST Builder • Ability to build AST parts – from a String •new AstBuilder().buildFromString(''' "Hello" ''') – from code •new AstBuilder().buildFromCode { "Hello" } – from specification •List<ASTNode> nodes = new AstBuilder().buildFromSpec { block { returnStatement { constant "Hello" } } } Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 28 mercredi 9 décembre 2009
  • 29. Customize the Groovy Truth! • Ability to customize the Groovy Truth by implementing of method boolean asBoolean() • Your own predicate – class Predicate { boolean value boolean asBoolean() { value } } assert new Predicate(value: true) assert !new Predicate(value: false) Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 29 mercredi 9 décembre 2009
  • 30. nd a Ag e • Future (Groovy 1.8+) – Extended annotations – DSL: command statements improvements – Pattern matching – Parser combinators – New MOP – JDK 7 •Project Coin •Simple closures for Java •InvokeDynamic Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 30 mercredi 9 décembre 2009
  • 31. Groovy 1.8 and beyond... • Caution! • The following features are still subject to discussion, and may very well never see the light of day! mercredi 9 décembre 2009
  • 32. Groovy 1.8, end of 2010 • Plan to provide various runtime improvements to make Groovy faster and faster • Make Groovy more modular – Probably using Grape’s module system – Breaking Groovy into smaller JARs •not everybody needs everything (JMX, SQL, Swing...) • Align Groovy with JDK 7 / Java 7 – Review project coin proposals where it makes sense – Incorporate / integrate with InvokeDynamic (JSR-292) – Interoperate with Java simple closures Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 32 mercredi 9 décembre 2009
  • 33. Extended annotations • Go beyond Java 5, and let annotations support more type parameters – closures, lists, maps, ranges • Possible use cases – validation, pre- and post-conditions – @Validate({ name.size() > 4 }) String name – @PreCondition({ msg != null }) void outputToUpperCase(String msg) { println msg.toUpperCase() } Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 33 mercredi 9 décembre 2009
  • 34. Command-expression based DSL • Groovy lets you omit parentheses for top-level expressions, and mix named and non-named arguments • Idea: extend to nested/chained expressions – send "Hello" to "Jochen" send "Hello", from: "Guillaume" to "Jochen" sell 100.shares of MSFT take 2.pills of chloroquinine in 6.hours every 10.minutes { } given { } when { } then { } blend red, green of acrylic Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 34 mercredi 9 décembre 2009
  • 35. Pattern matching • Structural pattern matching on PO(J|G)Os • First experiments will be done as module – if successful, likely integrated in core • term.match { // or match(term) {} Num(value) {} Plus(left, right) {} Num(value: 5) {} Num(value > 0) {} Plus(left: Plus(left: a, right: 2), right) {} Plus(left: a, right: b) | Minus(left: a, right: b) {} Object(left, right) {} nothing { } } Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 35 mercredi 9 décembre 2009
  • 36. Parser combinators • Same as pattern matching, experiments need to be done as a module, before possible integration in core – Also need Groovy modularity to be implemented • def language = grammar { digit: ~/[0-9]/ letter: ~/[a-zA-Z]/ identifier: letter + ( letter | digit ){n} number: digit{n} } grammar.parse(...) Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 36 mercredi 9 décembre 2009
  • 37. nd a Ag e • Summary • Questions & Answers Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 37 mercredi 9 décembre 2009
  • 38. Summary • Groovy, still inovative, since 2003! – Newever versions always bring their share of new features and libraries to simplify the life of the developer – And there’s more to come! • But Groovy’s more than just a language, it’s a very active and lively ecosystem with tons of great projects – Grails, Gradle, GPars, Spock, Gaelyk, etc... • Enjoy the conference! Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 38 mercredi 9 décembre 2009
  • 39. Questions & Answers Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 39 mercredi 9 décembre 2009
  • 40. Photo credits • Buzz LightYear: http://bu77lightyear.files.wordpress.com/2008/09/buzzlightyear_high.jpg • Christmas tree: http://www.thedailygreen.com/cm/thedailygreen/images/WT/christmas-tree-with-gifts-flipbook.jpg • Caution: http://www.disastersuppliesusa.com/catalog/ee44.jpg • Light bulb: https://newsline.llnl.gov/retooling/mar/03.28.08_images/lightBulb.png Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 40 mercredi 9 décembre 2009