SlideShare a Scribd company logo
1 of 57
Download to read offline
What’s new in Groovy 2.0?
          Guillaume Laforge
           Groovy Project Manager
           SpringSource / VMware
               @glaforge

1
Guillaume Laforge
    • Groovy Project Manager at VMware
      • Initiator of the Grails framework
      • Creator of the Gaelyk

    • Co-author of Groovy in Action

    • Follow me on...
      • My blog: http://glaforge.appspot.com
      • Twitter: @glaforge
      • Google+: http://gplus.to/glaforge
2
Groovy 2.0 bird’s eye view



    A more              Java 7       Static Type
                      Project Coin   Checking
    modular
                        Invoke        Static
    Groovy             Dynamic       Compilation
3
Groovy 2.0 bird’s eye view



    A more
    modular
    Groovy
4
Groovy Modularity
    • Groovy’s « all » JAR weighs in at 6 MB

    • Nobody needs everything
      – Template engine, Ant scripting, Swing UI building...

    • Provide a smaller core
      – and several smaller JARs per feature

    • Provide hooks for setting up DGM methods, etc.

5
The new JARs
    • A smaller JAR: 3MB

    • Modules
                    –   console        –   jsr-223     –   test
                    –   docgenerator   –   jmx         –   testng
                    –   groovydoc      –   sql         –   json
                    –   groovysh       –   swing       –   xml
                    –   ant            –   servlet
                    –   bsf            –   templates

6
Extension modules
    • Create your own module
      – contribute instance extension methods

          package	
  foo

          class	
  StringExtension	
  {
          	
  	
  	
  	
  static	
  introduces(String	
  self,	
  String	
  name)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  "Hi	
  ${name),	
  I’m	
  ${self}"
          	
  	
  	
  	
  }
          }

          //	
  usage:	
  "Guillaume".introduces("Cédric")


7
Extension modules
    • Create your own module
                                                                            Same structure
      – contribute instance extension methods                               as Categories
          package	
  foo

          class	
  StringExtension	
  {
          	
  	
  	
  	
  static	
  introduces(String	
  self,	
  String	
  name)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  "Hi	
  ${name),	
  I’m	
  ${self}"
          	
  	
  	
  	
  }
          }

          //	
  usage:	
  "Guillaume".introduces("Cédric")


7
Extension modules
    • Create your own module
      – contribute class extension methods

                       package	
  foo

                       class	
  StaticStringExtension	
  {
                       	
  	
  	
  	
  static	
  hi(String	
  self)	
  {
                       	
  	
  	
  	
  	
  	
  	
  	
  "Hi!"
                       	
  	
  	
  	
  }
                       }

                       //	
  usage:	
  String.hi()


8
Extension module descriptor
    • Descriptor in: META-INF/services/
      org.codehaus.groovy.runtime.ExtensionModule


          moduleName	
  =	
  stringExtensions
          moduleVersion	
  =	
  1.0
          //	
  comma-­‐separated	
  list	
  of	
  classes
          extensionClasses	
  =	
  foo.StringExtension
          //	
  comma-­‐separated	
  list	
  of	
  classes
          staticExtensionClasses	
  =	
  foo.StaticStringExtension



9
Groovy 2.0 bird’s eye view



     A more              Java 7       Static Type
                       Project Coin   Checking
     modular
                         Invoke        Static
     Groovy             Dynamic       Compilation
10
Groovy 2.0 bird’s eye view


                         Java 7
                       Project Coin

                         Invoke
                        Dynamic
11
Binary literals
     • We had decimal, octal and hexadecimal
       notations for number literals
     • We can now use binary
                                      int	
  x	
  =	
  0b10101111
       representations too            assert	
  x	
  ==	
  175
                                           	
  
                                           byte	
  aByte	
  =	
  0b00100001
                                           assert	
  aByte	
  ==	
  33
                                           	
  
                                           int	
  anInt	
  =	
  0b1010000101000101
                                           assert	
  anInt	
  ==	
  41285



12
Underscore in literals
     • Now we can also add underscores
       in number literals for more readability

            long	
  creditCardNumber	
  =	
  1234_5678_9012_3456L
            long	
  socialSecurityNumbers	
  =	
  999_99_9999L
            float	
  monetaryAmount	
  =	
  12_345_132.12
            long	
  hexBytes	
  =	
  0xFF_EC_DE_5E
            long	
  hexWords	
  =	
  0xFFEC_DE5E
            long	
  maxLong	
  =	
  0x7fff_ffff_ffff_ffffL
            long	
  alsoMaxLong	
  =	
  9_223_372_036_854_775_807L
            long	
  bytes	
  =	
  0b11010010_01101001_10010100_10010010

13
Multicatch
     • One block for multiple exception caught
       – rather than duplicating the block


           try	
  {
           	
  	
  	
  	
  /*	
  ...	
  */
           }	
  catch(IOException	
  |	
  NullPointerException	
  e)	
  {
           	
  	
  	
  	
  /*	
  one	
  block	
  to	
  treat	
  2	
  exceptions	
  */
           }



14
InvokeDynamic
     • Groovy 2.0 supports JDK 7’s invokeDynamic
       – compiler has a flag for compiling against JDK 7
       – might use the invokeDynamic backport for < JDK 7
     • Benefits
       – more runtime performance!
          • at least as fast as current « dynamic » Groovy
       – in the long run, will allow us to get rid of code!
          • call site caching, thanks to MethodHandles
          • metaclass registry, thanks to ClassValues
          • will let the JIT inline calls more easily

15
Groovy 2.0 bird’s eye view



     A more              Java 7       Static Type
                       Project Coin   Checking
     modular
                         Invoke        Static
     Groovy             Dynamic       Compilation
16
Groovy 2.0 bird’s eye view


                                  Static Type
                                  Checking
                                   Static
                                  Compilation
17
Static Type Checking
     • Goal: make the Groovy compiler « grumpy »!
       – and throw compilation errors (not at runtime)
     • Not everybody needs dynamic features all the time
       – think Java libraries scripting
     • Grumpy should...
       – tell you about your method or variable typos
       – complain if you call methods that don’t exist
       – shout on assignments of wrong types
       – infer the types of your variables
       – figure out GDK methods
18
Typos in a variable or method

                     import	
  groovy.transform.TypeChecked
                     	
  
                     void	
  method()	
  {}
                     	
  
                     @TypeChecked	
  test()	
  {
                     	
  	
  	
  	
  //	
  Cannot	
  find	
  matching	
  method	
  metthhoood()
                     	
  	
  	
  	
  metthhoood()
                     	
  
                     	
  	
  	
  	
  def	
  name	
  =	
  "Guillaume"
                     	
  	
  	
  	
  //	
  variable	
  naamme	
  is	
  undeclared
                     	
  	
  	
  	
  println	
  naamme
                     }



19
Typos in a variable or method

                      import	
  groovy.transform.TypeChecked
                      	
  
                      void	
  method()	
  {}
                      	
  
                      @TypeChecked	
  test()	
  {
                      	
  	
  	
  	
  //	
  Cannot	
  find	
  matching	
  method	
  metthhoood()
                      	
  	
  	
  	
  metthhoood()
                      	
  
                      	
  	
  	
  	
  def	
  name	
  =	
  "Guillaume"
     Compilation      	
  	
  	
  	
  //	
  variable	
  naamme	
  is	
  undeclared
          errors!     	
  	
  	
  	
  println	
  naamme
                      }



19
Typos in a variable or method

 Annotation can be at     import	
  groovy.transform.TypeChecked
                          	
  
  class or method level   void	
  method()	
  {}
                          	
  
                          @TypeChecked	
  test()	
  {
                          	
  	
  	
  	
  //	
  Cannot	
  find	
  matching	
  method	
  metthhoood()
                          	
  	
  	
  	
  metthhoood()
                          	
  
                          	
  	
  	
  	
  def	
  name	
  =	
  "Guillaume"
     Compilation          	
  	
  	
  	
  //	
  variable	
  naamme	
  is	
  undeclared
          errors!         	
  	
  	
  	
  println	
  naamme
                          }



19
Wrong assignments

           //	
  cannot	
  assign	
  value	
  of	
  type...	
  to	
  variable...
           int	
  x	
  =	
  new	
  Object()
           Set	
  set	
  =	
  new	
  Object()
           	
  
           def	
  o	
  =	
  new	
  Object()
           int	
  x	
  =	
  o
           	
  
           String[]	
  strings	
  =	
  ['a','b','c']
           int	
  str	
  =	
  strings[0]
           	
  
           //	
  cannot	
  find	
  matching	
  method	
  plus()
           int	
  i	
  =	
  0
           i	
  +=	
  '1'



20
Wrong assignments

           //	
  cannot	
  assign	
  value	
  of	
  type...	
  to	
  variable...
           int	
  x	
  =	
  new	
  Object()
           Set	
  set	
  =	
  new	
  Object()                                      Compilation
           	
                                                                      errors!
           def	
  o	
  =	
  new	
  Object()
           int	
  x	
  =	
  o
           	
  
           String[]	
  strings	
  =	
  ['a','b','c']
           int	
  str	
  =	
  strings[0]
           	
  
           //	
  cannot	
  find	
  matching	
  method	
  plus()
           int	
  i	
  =	
  0
           i	
  +=	
  '1'



20
Wrong return types
            //	
  checks	
  if/else	
  branch	
  return	
  values
            @TypeChecked
            int	
  method()	
  {
            	
  	
  	
  	
  if	
  (true)	
  {	
  'String'	
  }
            	
  	
  	
  	
  else	
  {	
  42	
  }
            }
            //	
  works	
  for	
  switch/case	
  &	
  try/catch/finally
            	
  
            //	
  transparent	
  toString()	
  implied
            @TypeChecked
            String	
  greeting(String	
  name)	
  {
            	
  	
  	
  	
  def	
  sb	
  =	
  new	
  StringBuilder()
            	
  	
  	
  	
  sb	
  <<	
  "Hi	
  "	
  <<	
  name
            }

21
Wrong return types
            //	
  checks	
  if/else	
  branch	
  return	
  values
            @TypeChecked
            int	
  method()	
  {
            	
  	
  	
  	
  if	
  (true)	
  {	
  'String'	
  }       Compilation
            	
  	
  	
  	
  else	
  {	
  42	
  }                     error!
            }
            //	
  works	
  for	
  switch/case	
  &	
  try/catch/finally
            	
  
            //	
  transparent	
  toString()	
  implied
            @TypeChecked
            String	
  greeting(String	
  name)	
  {
            	
  	
  	
  	
  def	
  sb	
  =	
  new	
  StringBuilder()
            	
  	
  	
  	
  sb	
  <<	
  "Hi	
  "	
  <<	
  name
            }

21
Type inference
             @TypeChecked	
  test()	
  {
             	
  	
  	
  	
  def	
  name	
  =	
  "	
  	
  Guillaume	
  	
  "
             	
  
             	
  	
  	
  	
  //	
  String	
  type	
  infered	
  (even	
  inside	
  GString)
             	
  	
  	
  	
  println	
  "NAME	
  =	
  ${name.toUpperCase()}"	
  
             	
  
             	
  	
  	
  	
  //	
  Groovy	
  GDK	
  method	
  support
             	
  	
  	
  	
  //	
  (GDK	
  operator	
  overloading	
  too)
             	
  	
  	
  	
  println	
  name.trim()
             	
  
             	
  	
  	
  	
  int[]	
  numbers	
  =	
  [1,	
  2,	
  3]
             	
  	
  	
  	
  //	
  Element	
  n	
  is	
  an	
  int
             	
  	
  	
  	
  for	
  (int	
  n	
  in	
  numbers)	
  {
             	
  	
  	
  	
  	
  	
  	
  	
  println	
  n
             	
  	
  	
  	
  }
             }

22
Statically checked & dynamic methods
                @TypeChecked
                String	
  greeting(String	
  name)	
  {
                  	
  	
  	
  	
  //	
  call	
  method	
  with	
  dynamic	
  behavior
                  	
  	
  	
  	
  //	
  but	
  with	
  proper	
  signature
                	
  	
  	
  	
  generateMarkup(name.toUpperCase())
                }
                	
  
                //	
  usual	
  dynamic	
  behavior
                String	
  generateMarkup(String	
  name)	
  {
                	
  	
  	
  	
  def	
  sw	
  =	
  new	
  StringWriter()
                	
  	
  	
  	
  new	
  MarkupBuilder(sw).html	
  {
                	
  	
  	
  	
  	
  	
  	
  	
  body	
  {
                	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  div	
  name
                	
  	
  	
  	
  	
  	
  	
  	
  }
                	
  	
  	
  	
  }
                	
  	
  	
  	
  sw.toString()
                }


23
Instanceof checks
          @TypeChecked	
  
          void	
  test(Object	
  val)	
  {

          	
  	
  	
  	
  if	
  (val	
  instanceof	
  String)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  val.toUpperCase()
          	
  	
  	
  	
  }	
  else	
  if	
  (val	
  instanceof	
  Number)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  "X"	
  *	
  val.intValue()
          	
  	
  	
  	
  }
          }




24
Instanceof checks
          @TypeChecked	
  
          void	
  test(Object	
  val)	
  {

          	
  	
  	
  	
  if	
  (val	
  instanceof	
  String)	
  {                No need
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  val.toUpperCase()            for casts
          	
  	
  	
  	
  }	
  else	
  if	
  (val	
  instanceof	
  Number)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  "X"	
  *	
  val.intValue()
          	
  	
  	
  	
  }
          }




24
Instanceof checks
          @TypeChecked	
  
          void	
  test(Object	
  val)	
  {

          	
  	
  	
  	
  if	
  (val	
  instanceof	
  String)	
  {                No need
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  val.toUpperCase()            for casts
          	
  	
  	
  	
  }	
  else	
  if	
  (val	
  instanceof	
  Number)	
  {
          	
  	
  	
  	
  	
  	
  	
  	
  println	
  "X"	
  *	
  val.intValue()
          	
  	
  	
  	
  }
          }


               Can call String#multiply(int)
               from the Groovy Development Kit
24
Lowest Upper Bound
     • Represents the lowest « super » type classes have in common
       – may be virtual (aka « non-denotable »)

                       @TypeChecked	
  test()	
  {
                       	
  	
  	
  	
  //	
  an	
  integer	
  and	
  a	
  BigDecimal
                       	
  	
  	
  	
  return	
  [1234,	
  3.14]
                       }




25
Lowest Upper Bound
     • Represents the lowest « super » type classes have in common
       – may be virtual (aka « non-denotable »)

                       @TypeChecked	
  test()	
  {
                       	
  	
  	
  	
  //	
  an	
  integer	
  and	
  a	
  BigDecimal
                       	
  	
  	
  	
  return	
  [1234,	
  3.14]
                       }


                                          Inferred return type:
                                          List<Number & Comparable>
25
Lowest Upper Bound
     • Represents the lowest « super » type classes have in common
       – may be virtual (aka « non-denotable »)

                       @TypeChecked	
  test()	
  {
                       	
  	
  	
  	
  //	
  an	
  integer	
  and	
  a	
  BigDecimal
                       	
  	
  	
  	
  return	
  [1234,	
  3.14]
                       }


                                          Inferred return type:
                                          List<Number & Comparable>
25
Flow typing
     • Static type checking shouldn’t complain even for bad coding
       practicies which work without type checks
          @TypeChecked	
  test()	
  {
          	
  	
  	
  	
  def	
  var	
  =	
  123	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  inferred	
  type	
  is	
  int
          	
  	
  	
  	
  int	
  x	
  =	
  var	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  var	
  is	
  an	
  int
          	
  	
  	
  	
  var	
  =	
  "123"	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  assign	
  var	
  with	
  a	
  String

          	
  	
  	
  	
  x	
  =	
  var.toInteger()	
  	
  	
  //	
  no	
  problem,	
  no	
  need	
  to	
  cast

          	
  	
  	
  	
  var	
  =	
  123
          	
  	
  	
  	
  x	
  =	
  var.toUpperCase()	
  //	
  error,	
  var	
  is	
  int!
          }

26
Gotcha: static checking vs dynamic
     • Type checking works at compile-time
       – adding @TypeChecked doesn’t change behavior
          • do not confuse with static compilation


     • Most dynamic features cannot be type checked
       – metaclass changes, categories
       – dynamically bound variables (ex: script’s binding)

     • However, compile-time metaprogramming works
       – as long as proper type information is defined

27
Gotcha: runtime metaprogramming

              @TypeChecked	
  
              void	
  test()	
  {
              	
  	
  	
  	
  Integer.metaClass.foo	
  =	
  {}
              	
  	
  	
  	
  123.foo()
              }




28
Gotcha: runtime metaprogramming

              @TypeChecked	
  
              void	
  test()	
  {
              	
  	
  	
  	
  Integer.metaClass.foo	
  =	
  {}
              	
  	
  	
  	
  123.foo()
              }

                                         Not allowed:
                                         metaClass property
                                         is dynamic

28
Gotcha: runtime metaprogramming

              @TypeChecked	
  
              void	
  test()	
  {
              	
  	
  	
  	
  Integer.metaClass.foo	
  =	
  {}
              	
  	
  	
  	
  123.foo()
              }


                 Method not              Not allowed:
                 recognized              metaClass property
                                         is dynamic

28
Gotcha: explicit type for closures

        @TypeChecked	
  test()	
  {
        	
  	
  	
  	
  ["a",	
  "b",	
  "c"].collect	
  {
        	
  	
  	
  	
  	
  	
  	
  	
  it.toUpperCase()	
  //	
  Not	
  OK
        	
  	
  	
  	
  }
        }


     • A « Groovy Enhancement Proposal » to address the issue


29
Gotcha: explicit type for closures

        @TypeChecked	
  test()	
  {
        	
  	
  	
  	
  ["a",	
  "b",	
  "c"].collect	
  {	
  String	
  it	
  -­‐>
        	
  	
  	
  	
  	
  	
  	
  	
  it.toUpperCase()	
  //	
  OK,	
  it’s	
  a	
  String
        	
  	
  	
  	
  }
        }


     • A « Groovy Enhancement Proposal » to address the issue


29
Closure shared variables


                  @TypeChecked	
  test()	
  {
                  	
  	
  	
  	
  def	
  var	
  =	
  "abc"	
  	
  	
  	
  	
  	
  	
  
                  	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  Date()	
  }
                  	
  	
  	
  	
  if	
  (random)	
  cl()
                  	
  	
  	
  	
  var.toUpperCase()	
  	
  //	
  Not	
  OK!
                  }




30
Closure shared variables
                                                                var assigned in the closure:
                                                                « shared closure variable »
                  @TypeChecked	
  test()	
  {
                  	
  	
  	
  	
  def	
  var	
  =	
  "abc"	
  	
  	
  	
  	
  	
  	
  
                  	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  Date()	
  }
                  	
  	
  	
  	
  if	
  (random)	
  cl()
                  	
  	
  	
  	
  var.toUpperCase()	
  	
  //	
  Not	
  OK!
                  }




30
Closure shared variables
                                                                    var assigned in the closure:
                                                                    « shared closure variable »

     Impossible to    @TypeChecked	
  test()	
  {
     ensure the       	
  	
  	
  	
  def	
  var	
  =	
  "abc"	
  	
  	
  	
  	
  	
  	
  
                      	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  Date()	
  }
     assignment       	
  	
  	
  	
  if	
  (random)	
  cl()
     really happens   	
  	
  	
  	
  var.toUpperCase()	
  	
  //	
  Not	
  OK!
                      }




30
Closure shared variables
                                                                    var assigned in the closure:
                                                                    « shared closure variable »

     Impossible to    @TypeChecked	
  test()	
  {
     ensure the       	
  	
  	
  	
  def	
  var	
  =	
  "abc"	
  	
  	
  	
  	
  	
  	
  
                      	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  Date()	
  }
     assignment       	
  	
  	
  	
  if	
  (random)	
  cl()
     really happens   	
  	
  	
  	
  var.toUpperCase()	
  	
  //	
  Not	
  OK!
                      }


                       Only methods of the most specific compatible
                       type (LUB) are allowed by the type checker
30
Closure shared variables
            class	
  A	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  void	
  foo()	
  {}	
  }
            class	
  B	
  extends	
  A	
  {	
  void	
  bar()	
  {}	
  }

            @TypeChecked	
  test()	
  {
            	
  	
  	
  	
  def	
  var	
  =	
  new	
  A()
            	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  B()	
  }
            	
  	
  	
  	
  cl()
            	
  	
  	
  	
  var.foo()	
  	
  	
  //	
  OK!
            }




31
Closure shared variables
            class	
  A	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {	
  void	
  foo()	
  {}	
  }
            class	
  B	
  extends	
  A	
  {	
  void	
  bar()	
  {}	
  }

            @TypeChecked	
  test()	
  {
            	
  	
  	
  	
  def	
  var	
  =	
  new	
  A()
            	
  	
  	
  	
  def	
  cl	
  =	
  {	
  var	
  =	
  new	
  B()	
  }
            	
  	
  	
  	
  cl()
            	
  	
  	
  	
  var.foo()	
  	
  	
  //	
  OK!
            }


                      var is at least an instance of A

31
Static Compilation
     • Given your Groovy code can be type checked...
       we can as well compile it « statically »

       – ie. generate the same byte code as javac

     • Also interesting for those stuck in JDK < 7
       to benefit from performance improvements




32
Static Compilation: advantages
     • You gain:

       – Type safety
          • thanks to static type checking
              – static compilation builds upon static type checking
       – Faster code
          • as close as possible to Java’s performance
       – Code immune to « monkey patching »
          • metaprogramming badly used can interfere with framework code
       – Smaller bytecode size

33
Static Compilation: disadvantages
     • But you loose:

       – Dynamic features
          • metaclass changes, categories, etc.


       – Dynamic method dispatch
          • although as close as possible to « dynamic » Groovy




34
Statically compiled & dynamic methods
              @CompileStatic
              String	
  greeting(String	
  name)	
  {
                	
  	
  	
  	
  //	
  call	
  method	
  with	
  dynamic	
  behavior
                	
  	
  	
  	
  //	
  but	
  with	
  proper	
  signature
              	
  	
  	
  	
  generateMarkup(name.toUpperCase())
              }
              	
  
              //	
  usual	
  dynamic	
  behavior
              String	
  generateMarkup(String	
  name)	
  {
              	
  	
  	
  	
  def	
  sw	
  =	
  new	
  StringWriter()
              	
  	
  	
  	
  new	
  MarkupBuilder(sw).html	
  {
              	
  	
  	
  	
  	
  	
  	
  	
  body	
  {
              	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  div	
  name
              	
  	
  	
  	
  	
  	
  	
  	
  }
              	
  	
  	
  	
  }
              	
  	
  	
  	
  sw.toString()
              }


35
What about performance?
     • Comparisons between:

       – Java

       – Groovy static compilation (Groovy 2.0)
       – Groovy with primitive optimizations (Groovy 1.8+)
       – Groovy without optimizations (Groovy 1.7)




36
What about performance?

                                                     Pi (π)     Binary
                                       Fibonacci
                                                   quadrature   trees

                           Java        191 ms       97 ms       3.6 s
                         Static
         1.7 1.8 2.0




                       compilation     197 ms      101 ms       4.3 s
                         Primitive
                       optimizations   360 ms      111 ms       23.7 s
                         No prim.
                       optimizations   2590 ms     3220 ms      50.0 s

37
Summary: Groovy 2.0 themes
     • Modularity

     • Embark the JDK 7 enhancements
       – Project Coin
       – Invoke Dynamic

     • Static aspects
       – Static type checking
       – Static compilation

38
Thank you!




                                     rge          t
                              e Lafo evelopmen
                       aum ovy D
                  Guill f Gro
                         o
                  Head                     il.com
                                forge @gma
                   Em  ail: gla laforge          aforge
                           r: @g         s.to/gl t.com
                   Twitte +: http://gplu appspo
                            e            .
                    Googl ttp://glaforge
                    Blog: h




39
Questions & Answers
     • Got questions, really?
                                Q&A




40
Image credits
      •   Bugs bunny: http://storage.canalblog.com/63/56/517188/47634843.jpeg
      •   Pills: http://www.we-ew.com/wp-content/uploads/2011/01/plan-b-pills.jpg
      •   Chains: http://2.bp.blogspot.com/-GXDVqUYSCa0/TVdBsON4tdI/AAAAAAAAAW4/EgJOUmAxB28/s1600/breaking-chains5_copy9611.jpg
      •   Slurp: http://www.ohpacha.com/218-532-thickbox/gamelle-slurp.jpg
      •   Grumpy: http://mafeuilledechou.fr/__oneclick_uploads/2010/05/grumpy.jpg
      •   Modularity: http://php.jglobal.com/blog/wp-content/uploads/2009/11/modularity.jpg
      •   Agenda: http://www.plombiereslesbains.fr/images/stories/agenda.jpg
      •   Java 7: http://geeknizer.com/wp-content/uploads/java7.jpg
      •   Road Runner: http://newspaper.li/static/4ada046b7772f0612fec4e3840142308.jpg
      •   Porky: http://joshuadsandy.files.wordpress.com/2011/05/porky-pig-5.jpg
      •   Will E help: http://www.clipart-fr.com/data/clipart/looney/looney_004.jpg
      •   Coyote road runner: http://www.jenkle.com/wp-content/uploads/2010/12/coyote-wallpaper1.jpg
      •   Lube: http://images.motorcycle-superstore.com/ProductImages/OG/0000_Motul_Chain_Lube_Road_--.jpg




41

More Related Content

What's hot

GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf
 
Grooscript gr8conf
Grooscript gr8confGrooscript gr8conf
Grooscript gr8confGR8Conf
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292ytoshima
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Railselliando dias
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
groovy transforms
groovy transformsgroovy transforms
groovy transformsPaul King
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-UtilitiesMohammad Shaker
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsMohammad Shaker
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
 
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Johnny Sung
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Victor_Cr
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHoward Lewis Ship
 

What's hot (20)

GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 
Grooscript gr8conf
Grooscript gr8confGrooscript gr8conf
Grooscript gr8conf
 
Invokedynamic / JSR-292
Invokedynamic / JSR-292Invokedynamic / JSR-292
Invokedynamic / JSR-292
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Java Performance MythBusters
Java Performance MythBustersJava Performance MythBusters
Java Performance MythBusters
 
Getting rid of backtracking
Getting rid of backtrackingGetting rid of backtracking
Getting rid of backtracking
 
Runtime
RuntimeRuntime
Runtime
 
Clean code
Clean codeClean code
Clean code
 
Google Dart
Google DartGoogle Dart
Google Dart
 
groovy transforms
groovy transformsgroovy transforms
groovy transforms
 
C# Starter L03-Utilities
C# Starter L03-UtilitiesC# Starter L03-Utilities
C# Starter L03-Utilities
 
C# Starter L02-Classes and Objects
C# Starter L02-Classes and ObjectsC# Starter L02-Classes and Objects
C# Starter L02-Classes and Objects
 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
 
Clean code
Clean codeClean code
Clean code
 
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
Flutter 是什麼?用 Flutter 會省到時間嗎? @ GDG Devfest2020
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 

Viewers also liked

Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Guillaume 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 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
 
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume LaforgeGaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume LaforgeGuillaume 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
 

Viewers also liked (6)

Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012
 
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 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
 
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume LaforgeGaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge
Gaelyk quickie - GR8Conf Europe 2010 - Guillaume Laforge
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 

Similar to Groovy 2.0 webinar

Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouAndres Almiray
 
cdac@parag.gajbhiye@groovy metaprogrammning
cdac@parag.gajbhiye@groovy metaprogrammningcdac@parag.gajbhiye@groovy metaprogrammning
cdac@parag.gajbhiye@groovy metaprogrammningParag Gajbhiye
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneAndres Almiray
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
Infinum android talks_10_getting groovy on android
Infinum android talks_10_getting groovy on androidInfinum android talks_10_getting groovy on android
Infinum android talks_10_getting groovy on androidInfinum
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailszenMonkey
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGuillaume Laforge
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 
Make it test-driven with CDI!
Make it test-driven with CDI!Make it test-driven with CDI!
Make it test-driven with CDI!rafaelliu
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts S Akai
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyIván López Martín
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationPaolo Predonzani
 

Similar to Groovy 2.0 webinar (20)

Apache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and YouApache Groovy's Metaprogramming Options and You
Apache Groovy's Metaprogramming Options and You
 
cdac@parag.gajbhiye@groovy metaprogrammning
cdac@parag.gajbhiye@groovy metaprogrammningcdac@parag.gajbhiye@groovy metaprogrammning
cdac@parag.gajbhiye@groovy metaprogrammning
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Infinum android talks_10_getting groovy on android
Infinum android talks_10_getting groovy on androidInfinum android talks_10_getting groovy on android
Infinum android talks_10_getting groovy on android
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Metaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And GrailsMetaprogramming Techniques In Groovy And Grails
Metaprogramming Techniques In Groovy And Grails
 
From dot net_to_rails
From dot net_to_railsFrom dot net_to_rails
From dot net_to_rails
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
Exploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systemsExploring lambdas and invokedynamic for embedded systems
Exploring lambdas and invokedynamic for embedded systems
 
Make it test-driven with CDI!
Make it test-driven with CDI!Make it test-driven with CDI!
Make it test-driven with CDI!
 
Test Driven In Groovy
Test Driven In GroovyTest Driven In Groovy
Test Driven In Groovy
 
Jvm internals
Jvm internalsJvm internals
Jvm internals
 
Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts Method Shelters : Another Way to Resolve Class Extension Conflicts
Method Shelters : Another Way to Resolve Class Extension Conflicts
 
Groovy!
Groovy!Groovy!
Groovy!
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Embedding Groovy in a Java Application
Embedding Groovy in a Java ApplicationEmbedding Groovy in a Java Application
Embedding Groovy in a Java Application
 

More from Guillaume 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
 
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 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
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovyGuillaume Laforge
 
Groovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGroovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume LaforgeGroovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Guillaume Laforge
 
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011Guillaume Laforge
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume Laforge
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume LaforgeGroovy and Gaelyk - Lausanne JUG 2011 - Guillaume Laforge
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume LaforgeGuillaume Laforge
 

More from Guillaume Laforge (20)

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
 
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 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...
 
Cloud foundry intro with groovy
Cloud foundry intro with groovyCloud foundry intro with groovy
Cloud foundry intro with groovy
 
Groovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGroovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume Laforge
 
Groovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume LaforgeGroovy DSLs - S2GForum London 2011 - Guillaume Laforge
Groovy DSLs - S2GForum London 2011 - Guillaume Laforge
 
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
Gaelyk - Guillaume Laforge - GR8Conf Europe 2011
 
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011
Groovy 1.8 update - Guillaume Laforge - GR8Conf Europe 2011
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume Laforge
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume Laforge
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume LaforgeGroovy and Gaelyk - Lausanne JUG 2011 - Guillaume Laforge
Groovy and Gaelyk - Lausanne JUG 2011 - Guillaume Laforge
 

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Groovy 2.0 webinar

  • 1. What’s new in Groovy 2.0? Guillaume Laforge Groovy Project Manager SpringSource / VMware @glaforge 1
  • 2. Guillaume Laforge • Groovy Project Manager at VMware • Initiator of the Grails framework • Creator of the Gaelyk • Co-author of Groovy in Action • Follow me on... • My blog: http://glaforge.appspot.com • Twitter: @glaforge • Google+: http://gplus.to/glaforge 2
  • 3. Groovy 2.0 bird’s eye view A more Java 7 Static Type Project Coin Checking modular Invoke Static Groovy Dynamic Compilation 3
  • 4. Groovy 2.0 bird’s eye view A more modular Groovy 4
  • 5. Groovy Modularity • Groovy’s « all » JAR weighs in at 6 MB • Nobody needs everything – Template engine, Ant scripting, Swing UI building... • Provide a smaller core – and several smaller JARs per feature • Provide hooks for setting up DGM methods, etc. 5
  • 6. The new JARs • A smaller JAR: 3MB • Modules – console – jsr-223 – test – docgenerator – jmx – testng – groovydoc – sql – json – groovysh – swing – xml – ant – servlet – bsf – templates 6
  • 7. Extension modules • Create your own module – contribute instance extension methods package  foo class  StringExtension  {        static  introduces(String  self,  String  name)  {                "Hi  ${name),  I’m  ${self}"        } } //  usage:  "Guillaume".introduces("Cédric") 7
  • 8. Extension modules • Create your own module Same structure – contribute instance extension methods as Categories package  foo class  StringExtension  {        static  introduces(String  self,  String  name)  {                "Hi  ${name),  I’m  ${self}"        } } //  usage:  "Guillaume".introduces("Cédric") 7
  • 9. Extension modules • Create your own module – contribute class extension methods package  foo class  StaticStringExtension  {        static  hi(String  self)  {                "Hi!"        } } //  usage:  String.hi() 8
  • 10. Extension module descriptor • Descriptor in: META-INF/services/ org.codehaus.groovy.runtime.ExtensionModule moduleName  =  stringExtensions moduleVersion  =  1.0 //  comma-­‐separated  list  of  classes extensionClasses  =  foo.StringExtension //  comma-­‐separated  list  of  classes staticExtensionClasses  =  foo.StaticStringExtension 9
  • 11. Groovy 2.0 bird’s eye view A more Java 7 Static Type Project Coin Checking modular Invoke Static Groovy Dynamic Compilation 10
  • 12. Groovy 2.0 bird’s eye view Java 7 Project Coin Invoke Dynamic 11
  • 13. Binary literals • We had decimal, octal and hexadecimal notations for number literals • We can now use binary int  x  =  0b10101111 representations too assert  x  ==  175   byte  aByte  =  0b00100001 assert  aByte  ==  33   int  anInt  =  0b1010000101000101 assert  anInt  ==  41285 12
  • 14. Underscore in literals • Now we can also add underscores in number literals for more readability long  creditCardNumber  =  1234_5678_9012_3456L long  socialSecurityNumbers  =  999_99_9999L float  monetaryAmount  =  12_345_132.12 long  hexBytes  =  0xFF_EC_DE_5E long  hexWords  =  0xFFEC_DE5E long  maxLong  =  0x7fff_ffff_ffff_ffffL long  alsoMaxLong  =  9_223_372_036_854_775_807L long  bytes  =  0b11010010_01101001_10010100_10010010 13
  • 15. Multicatch • One block for multiple exception caught – rather than duplicating the block try  {        /*  ...  */ }  catch(IOException  |  NullPointerException  e)  {        /*  one  block  to  treat  2  exceptions  */ } 14
  • 16. InvokeDynamic • Groovy 2.0 supports JDK 7’s invokeDynamic – compiler has a flag for compiling against JDK 7 – might use the invokeDynamic backport for < JDK 7 • Benefits – more runtime performance! • at least as fast as current « dynamic » Groovy – in the long run, will allow us to get rid of code! • call site caching, thanks to MethodHandles • metaclass registry, thanks to ClassValues • will let the JIT inline calls more easily 15
  • 17. Groovy 2.0 bird’s eye view A more Java 7 Static Type Project Coin Checking modular Invoke Static Groovy Dynamic Compilation 16
  • 18. Groovy 2.0 bird’s eye view Static Type Checking Static Compilation 17
  • 19. Static Type Checking • Goal: make the Groovy compiler « grumpy »! – and throw compilation errors (not at runtime) • Not everybody needs dynamic features all the time – think Java libraries scripting • Grumpy should... – tell you about your method or variable typos – complain if you call methods that don’t exist – shout on assignments of wrong types – infer the types of your variables – figure out GDK methods 18
  • 20. Typos in a variable or method import  groovy.transform.TypeChecked   void  method()  {}   @TypeChecked  test()  {        //  Cannot  find  matching  method  metthhoood()        metthhoood()          def  name  =  "Guillaume"        //  variable  naamme  is  undeclared        println  naamme } 19
  • 21. Typos in a variable or method import  groovy.transform.TypeChecked   void  method()  {}   @TypeChecked  test()  {        //  Cannot  find  matching  method  metthhoood()        metthhoood()          def  name  =  "Guillaume" Compilation        //  variable  naamme  is  undeclared errors!        println  naamme } 19
  • 22. Typos in a variable or method Annotation can be at import  groovy.transform.TypeChecked   class or method level void  method()  {}   @TypeChecked  test()  {        //  Cannot  find  matching  method  metthhoood()        metthhoood()          def  name  =  "Guillaume" Compilation        //  variable  naamme  is  undeclared errors!        println  naamme } 19
  • 23. Wrong assignments //  cannot  assign  value  of  type...  to  variable... int  x  =  new  Object() Set  set  =  new  Object()   def  o  =  new  Object() int  x  =  o   String[]  strings  =  ['a','b','c'] int  str  =  strings[0]   //  cannot  find  matching  method  plus() int  i  =  0 i  +=  '1' 20
  • 24. Wrong assignments //  cannot  assign  value  of  type...  to  variable... int  x  =  new  Object() Set  set  =  new  Object() Compilation   errors! def  o  =  new  Object() int  x  =  o   String[]  strings  =  ['a','b','c'] int  str  =  strings[0]   //  cannot  find  matching  method  plus() int  i  =  0 i  +=  '1' 20
  • 25. Wrong return types //  checks  if/else  branch  return  values @TypeChecked int  method()  {        if  (true)  {  'String'  }        else  {  42  } } //  works  for  switch/case  &  try/catch/finally   //  transparent  toString()  implied @TypeChecked String  greeting(String  name)  {        def  sb  =  new  StringBuilder()        sb  <<  "Hi  "  <<  name } 21
  • 26. Wrong return types //  checks  if/else  branch  return  values @TypeChecked int  method()  {        if  (true)  {  'String'  } Compilation        else  {  42  } error! } //  works  for  switch/case  &  try/catch/finally   //  transparent  toString()  implied @TypeChecked String  greeting(String  name)  {        def  sb  =  new  StringBuilder()        sb  <<  "Hi  "  <<  name } 21
  • 27. Type inference @TypeChecked  test()  {        def  name  =  "    Guillaume    "          //  String  type  infered  (even  inside  GString)        println  "NAME  =  ${name.toUpperCase()}"            //  Groovy  GDK  method  support        //  (GDK  operator  overloading  too)        println  name.trim()          int[]  numbers  =  [1,  2,  3]        //  Element  n  is  an  int        for  (int  n  in  numbers)  {                println  n        } } 22
  • 28. Statically checked & dynamic methods @TypeChecked String  greeting(String  name)  {        //  call  method  with  dynamic  behavior        //  but  with  proper  signature        generateMarkup(name.toUpperCase()) }   //  usual  dynamic  behavior String  generateMarkup(String  name)  {        def  sw  =  new  StringWriter()        new  MarkupBuilder(sw).html  {                body  {                        div  name                }        }        sw.toString() } 23
  • 29. Instanceof checks @TypeChecked   void  test(Object  val)  {        if  (val  instanceof  String)  {                println  val.toUpperCase()        }  else  if  (val  instanceof  Number)  {                println  "X"  *  val.intValue()        } } 24
  • 30. Instanceof checks @TypeChecked   void  test(Object  val)  {        if  (val  instanceof  String)  { No need                println  val.toUpperCase() for casts        }  else  if  (val  instanceof  Number)  {                println  "X"  *  val.intValue()        } } 24
  • 31. Instanceof checks @TypeChecked   void  test(Object  val)  {        if  (val  instanceof  String)  { No need                println  val.toUpperCase() for casts        }  else  if  (val  instanceof  Number)  {                println  "X"  *  val.intValue()        } } Can call String#multiply(int) from the Groovy Development Kit 24
  • 32. Lowest Upper Bound • Represents the lowest « super » type classes have in common – may be virtual (aka « non-denotable ») @TypeChecked  test()  {        //  an  integer  and  a  BigDecimal        return  [1234,  3.14] } 25
  • 33. Lowest Upper Bound • Represents the lowest « super » type classes have in common – may be virtual (aka « non-denotable ») @TypeChecked  test()  {        //  an  integer  and  a  BigDecimal        return  [1234,  3.14] } Inferred return type: List<Number & Comparable> 25
  • 34. Lowest Upper Bound • Represents the lowest « super » type classes have in common – may be virtual (aka « non-denotable ») @TypeChecked  test()  {        //  an  integer  and  a  BigDecimal        return  [1234,  3.14] } Inferred return type: List<Number & Comparable> 25
  • 35. Flow typing • Static type checking shouldn’t complain even for bad coding practicies which work without type checks @TypeChecked  test()  {        def  var  =  123                  //  inferred  type  is  int        int  x  =  var                      //  var  is  an  int        var  =  "123"                      //  assign  var  with  a  String        x  =  var.toInteger()      //  no  problem,  no  need  to  cast        var  =  123        x  =  var.toUpperCase()  //  error,  var  is  int! } 26
  • 36. Gotcha: static checking vs dynamic • Type checking works at compile-time – adding @TypeChecked doesn’t change behavior • do not confuse with static compilation • Most dynamic features cannot be type checked – metaclass changes, categories – dynamically bound variables (ex: script’s binding) • However, compile-time metaprogramming works – as long as proper type information is defined 27
  • 37. Gotcha: runtime metaprogramming @TypeChecked   void  test()  {        Integer.metaClass.foo  =  {}        123.foo() } 28
  • 38. Gotcha: runtime metaprogramming @TypeChecked   void  test()  {        Integer.metaClass.foo  =  {}        123.foo() } Not allowed: metaClass property is dynamic 28
  • 39. Gotcha: runtime metaprogramming @TypeChecked   void  test()  {        Integer.metaClass.foo  =  {}        123.foo() } Method not Not allowed: recognized metaClass property is dynamic 28
  • 40. Gotcha: explicit type for closures @TypeChecked  test()  {        ["a",  "b",  "c"].collect  {                it.toUpperCase()  //  Not  OK        } } • A « Groovy Enhancement Proposal » to address the issue 29
  • 41. Gotcha: explicit type for closures @TypeChecked  test()  {        ["a",  "b",  "c"].collect  {  String  it  -­‐>                it.toUpperCase()  //  OK,  it’s  a  String        } } • A « Groovy Enhancement Proposal » to address the issue 29
  • 42. Closure shared variables @TypeChecked  test()  {        def  var  =  "abc"                      def  cl  =  {  var  =  new  Date()  }        if  (random)  cl()        var.toUpperCase()    //  Not  OK! } 30
  • 43. Closure shared variables var assigned in the closure: « shared closure variable » @TypeChecked  test()  {        def  var  =  "abc"                      def  cl  =  {  var  =  new  Date()  }        if  (random)  cl()        var.toUpperCase()    //  Not  OK! } 30
  • 44. Closure shared variables var assigned in the closure: « shared closure variable » Impossible to @TypeChecked  test()  { ensure the        def  var  =  "abc"                      def  cl  =  {  var  =  new  Date()  } assignment        if  (random)  cl() really happens        var.toUpperCase()    //  Not  OK! } 30
  • 45. Closure shared variables var assigned in the closure: « shared closure variable » Impossible to @TypeChecked  test()  { ensure the        def  var  =  "abc"                      def  cl  =  {  var  =  new  Date()  } assignment        if  (random)  cl() really happens        var.toUpperCase()    //  Not  OK! } Only methods of the most specific compatible type (LUB) are allowed by the type checker 30
  • 46. Closure shared variables class  A                      {  void  foo()  {}  } class  B  extends  A  {  void  bar()  {}  } @TypeChecked  test()  {        def  var  =  new  A()        def  cl  =  {  var  =  new  B()  }        cl()        var.foo()      //  OK! } 31
  • 47. Closure shared variables class  A                      {  void  foo()  {}  } class  B  extends  A  {  void  bar()  {}  } @TypeChecked  test()  {        def  var  =  new  A()        def  cl  =  {  var  =  new  B()  }        cl()        var.foo()      //  OK! } var is at least an instance of A 31
  • 48. Static Compilation • Given your Groovy code can be type checked... we can as well compile it « statically » – ie. generate the same byte code as javac • Also interesting for those stuck in JDK < 7 to benefit from performance improvements 32
  • 49. Static Compilation: advantages • You gain: – Type safety • thanks to static type checking – static compilation builds upon static type checking – Faster code • as close as possible to Java’s performance – Code immune to « monkey patching » • metaprogramming badly used can interfere with framework code – Smaller bytecode size 33
  • 50. Static Compilation: disadvantages • But you loose: – Dynamic features • metaclass changes, categories, etc. – Dynamic method dispatch • although as close as possible to « dynamic » Groovy 34
  • 51. Statically compiled & dynamic methods @CompileStatic String  greeting(String  name)  {        //  call  method  with  dynamic  behavior        //  but  with  proper  signature        generateMarkup(name.toUpperCase()) }   //  usual  dynamic  behavior String  generateMarkup(String  name)  {        def  sw  =  new  StringWriter()        new  MarkupBuilder(sw).html  {                body  {                        div  name                }        }        sw.toString() } 35
  • 52. What about performance? • Comparisons between: – Java – Groovy static compilation (Groovy 2.0) – Groovy with primitive optimizations (Groovy 1.8+) – Groovy without optimizations (Groovy 1.7) 36
  • 53. What about performance? Pi (π) Binary Fibonacci quadrature trees Java 191 ms 97 ms 3.6 s Static 1.7 1.8 2.0 compilation 197 ms 101 ms 4.3 s Primitive optimizations 360 ms 111 ms 23.7 s No prim. optimizations 2590 ms 3220 ms 50.0 s 37
  • 54. Summary: Groovy 2.0 themes • Modularity • Embark the JDK 7 enhancements – Project Coin – Invoke Dynamic • Static aspects – Static type checking – Static compilation 38
  • 55. Thank you! rge t e Lafo evelopmen aum ovy D Guill f Gro o Head il.com forge @gma Em ail: gla laforge aforge r: @g s.to/gl t.com Twitte +: http://gplu appspo e . Googl ttp://glaforge Blog: h 39
  • 56. Questions & Answers • Got questions, really? Q&A 40
  • 57. Image credits • Bugs bunny: http://storage.canalblog.com/63/56/517188/47634843.jpeg • Pills: http://www.we-ew.com/wp-content/uploads/2011/01/plan-b-pills.jpg • Chains: http://2.bp.blogspot.com/-GXDVqUYSCa0/TVdBsON4tdI/AAAAAAAAAW4/EgJOUmAxB28/s1600/breaking-chains5_copy9611.jpg • Slurp: http://www.ohpacha.com/218-532-thickbox/gamelle-slurp.jpg • Grumpy: http://mafeuilledechou.fr/__oneclick_uploads/2010/05/grumpy.jpg • Modularity: http://php.jglobal.com/blog/wp-content/uploads/2009/11/modularity.jpg • Agenda: http://www.plombiereslesbains.fr/images/stories/agenda.jpg • Java 7: http://geeknizer.com/wp-content/uploads/java7.jpg • Road Runner: http://newspaper.li/static/4ada046b7772f0612fec4e3840142308.jpg • Porky: http://joshuadsandy.files.wordpress.com/2011/05/porky-pig-5.jpg • Will E help: http://www.clipart-fr.com/data/clipart/looney/looney_004.jpg • Coyote road runner: http://www.jenkle.com/wp-content/uploads/2010/12/coyote-wallpaper1.jpg • Lube: http://images.motorcycle-superstore.com/ProductImages/OG/0000_Motul_Chain_Lube_Road_--.jpg 41