0
jeudi 16 décembre 2010
jeudi 16 décembre 2010
Statejeudi 16 décembre 2010                         of the   Union
Statejeudi 16 décembre 2010                         of the   Union
Guillaume Laforge / @glaforge       • Groovy Project Manager       • Head of Groovy Development         at SpringSource   ...
Agenda     •Past            – Groovy 1.6 flashback     •Present            – Groovy 1.7 novelties            – A few Groov...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
But first... some figures...          Downloads                      Moving Average (year)                                ...
Groovy 1.7.6 and 1.8-beta-3    Copyright 2010 SpringSource. Copying, publishing or distributing without express written pe...
looking into the Pastjeudi 16 décembre 2010
Big highlights of Groovy 1.6       • Greater compile-time and runtime performance       • Multiple assignments       • Opt...
Big highlights of Groovy 1.6       • Greater compile-time and runtime performance       • Multiple assignments       • Opt...
Multiple assignement                                         // multiple assignment                                       ...
More optional return                                      // optional return for if statements                            ...
AST Transformation (1/2)       • Groovy 1.6 introduced AST Transformations               – AST: Abstract Syntax Tree      ...
AST Transformations (2/2)       • Transformations introduced in 1.6               – @Singleton               – @Immutable,...
@Immutable       • To properly implement immutable classes               – No mutations — state musn’t change             ...
Grab a grape!       • Simple distribution and sharing of Groovy scripts       • Dependencies stored locally               ...
into the Present...jeudi 16 décembre 2010
Big highlights of Groovy 1.7       • Anonymous Inner Classes and Nested Classes       • Annotations anywhere       • Grape...
Big highlights of Groovy 1.7       • Anonymous Inner Classes and Nested Classes       • Annotations anywhere       • Grape...
AIC and NC       • Anonymous Inner Classes and Nested Classes    Copyright 2010 SpringSource. Copying, publishing or distr...
AIC and NC       • Anonymous Inner Classes and Nested Classes                                                 Fo rJ ava   ...
Annonymous Inner Classes                                      bo olean called = false                                     ...
Annonymous Inner Classes                                      bo olean called = false                                     ...
Nested Classes                                       class Environment {                                           static ...
Anotations almost anywhere       • You can put annotations               – on imports               – on packages         ...
Grape improvements (1/4)       • @Grab on import                       @Grab(group = net.sf.json‐lib,                     ...
Grape improvements (2/4)       • Shorter module / artifact / version parameter               – Example of an annotation on...
Grape improvements (3/4)       • Groovy 1.7 introduced Grab resolver               – For when you need to specify a specif...
Power Asserts (1/2)       • Much better assert statement!               – Invented and developed in the Spock framework   ...
Power Asserts (2/2)       • You’ll get a more comprehensible output    Copyright 2010 SpringSource. Copying, publishing or...
Easier AST Transformations       • AST Transformations are a very powerful feature       • But are still rather hard to de...
AST Viewer    Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohi...
AST Builder                // Ability to build AST parts                // ‐‐> from a String                new AstBui lde...
Customize the Groovy Truth!       • Ability to customize the truth by implementing a         boolean asBoolean() method   ...
Groovy 1.7.x changes       • Since Groovy 1.7.0...         Groovy 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5 and 1.7.6         have...
Grape improvements (4/4)       • Groovy 1.7.5 even further shrinks the grab resolver         definition:                  ...
Map improvements (1/2)       // map auto‐vification       def m =  [:].withDefault { key ‐> "Default" }       assert m[z] ...
Map improvements (2/2)              // before Map#withDefault()               def words = "one two two three three three"....
Map improvements (2/2)              //  after Map#withDefault()               def words = "one two two three three three"....
XML back to String       • Ability to retrieve the XML string from a node from         an XmlSlurper GPathResult          ...
Currying improvements           // right currying           def divide = { a, b ‐> a / b }           def halver = divide.r...
Date improvements           im port static java.util.Calendar.*           // convert to calendar           def cal = new D...
New String methods                      println """                                                                       ...
Map supports isCase()           def m = [a: 1, b: 2]           def val = a           switch (val) {               case m: ...
(G)String to Enum coercion                                   enum Color {                                       red, green...
...and beyond!jeudi 16 décembre 2010
Groovy 1.8 & beyond       • Still subject to discussion       • Always evolving roadmap       • Things may change!    Copy...
What’s cooking?jeudi 16 décembre 2010
What we’re working on       • More runtime performance improvements       • Closures               – annotation parameters...
jeudi 16 décembre 2010
Gjeudi 16 décembre 2010
jeudi 16 décembre 2010
jeudi 16 décembre 2010
An example, with Fibonacci    Copyright 2010 SpringSource. Copying, publishing or distributing without express written per...
An example, with Fibonacci                                                                                   • Known examp...
An example, with Fibonacci                                                                                   • Known examp...
An example, with Fibonacci                                                                                   • Known examp...
An example, with Fibonacci                                                                                   • Known examp...
An example, with Fibonacci                                                                                   • Known examp...
An example, with Fibonacci                                                                                   • Known examp...
Optimizations for int       • Currently, the optimizations cover most of native         operations on primitive ints      ...
Closure annotation parameters       • Groovy 1.5 brought Java 5 annotations       • What if... we could go beyond what Jav...
GContracts       • Closures are already allowed in the Groovy 1.7 Antlr         grammar               – André Steingreß cr...
Closure composition       • Functional flavor!                 def plus2  = { it + 2 }                 def times3 = { it *...
Closure memoization       • Memoization: remember the outcome of previous         (ideally side-effect free) invocations  ...
Closure trampoline       • No more infamous StackOvervlow errors for deeply         recursive algorithms               – i...
New AST xforms (1/2)       • Many new transformations coming up for         removing even more boiler plate code        @L...
New AST xforms (2/2)        @ThreadInterrupt                                                                      makes a ...
Java 7 / 8 / Project Coin       • Alignment with JDK 7 will come in Groovy 1.9       • JSR-292 InvokeDynamic       • Simpl...
Java 7 / 8 / Project Coin       • Alignment with JDK 7 will come in Groovy 1.9       • JSR-292 InvokeDynamic       • Simpl...
Java 7 / 8 / Project Coin       • Alignment with JDK 7 will come in Groovy 1.9       • JSR-292 InvokeDynamic       • Simpl...
Java 7 / 8 / Project Coin       • Alignment with JDK 7 will come in Groovy 1.9       • JSR-292 InvokeDynamic       • Simpl...
Java 7 / 8 / Project Coin       • Alignment with JDK 7 will come in Groovy 1.9       • JSR-292 InvokeDynamic       • Simpl...
Improved DSL support       • GEP-3: an extended command expression DSL               – Groovy Extension Proposal #3       ...
Before GEP-3       • The idea: extend command-expressions, beyond         top-level statements, for chained method calls  ...
With GEP-3       • The idea: extend command-expressions, beyond         top-level statements, for chained method calls    ...
With GEP-3       • The idea: extend command-expressions, beyond         top-level statements, for chained method calls    ...
The pattern       • A repetition of               – method name               – arguments (mix of named and normal)       ...
Summary     • No need to wait for Java 7, 8, 9...            – closures, properties, interpolated strings, extended       ...
Summary     • No need to wait for Java 7, 8, 9...            – closures, properties, interpolated strings, extended       ...
Summary     • No need to wait for Java 7, 8, 9...            – closures, properties, interpolated strings, extended       ...
d A                                        a n                   Q    Copyright 2010 SpringSource. Copying, publishing or ...
Picture credits             Myself http://www.flickr.com/photos/romainguy/783719255/sizes/l/in/photostream/             Bi...
Upcoming SlideShare
Loading in...5
×

Groovy, State of the Union - Groovy Grails eXchange 2010 - Guillaume Laforge

4,240

Published on

Keynote given at the Groovy / Grails eXchange conference in London

Published in: Technology
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,240
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
48
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "Groovy, State of the Union - Groovy Grails eXchange 2010 - Guillaume Laforge"

  1. 1. jeudi 16 décembre 2010
  2. 2. jeudi 16 décembre 2010
  3. 3. Statejeudi 16 décembre 2010 of the Union
  4. 4. Statejeudi 16 décembre 2010 of the Union
  5. 5. Guillaume Laforge / @glaforge • Groovy Project Manager • Head of Groovy Development at SpringSource • Initiator of the Grails framework • Founder of the Gaelyk toolkit • Co-author of Groovy in Action • Member of «Les Cast Codeurs» podcast • Speaker: JavaOne, QCon, JavaZone, Sun TechDays, Devoxx, The Spring Experience, SpringOne2GX, JAX, Dynamic Language World, IJTC, and more... Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2jeudi 16 décembre 2010
  6. 6. Agenda •Past – Groovy 1.6 flashback •Present – Groovy 1.7 novelties – A few Groovy 1.7.x refinements •Future – What’s cooking for 1.8 and beyond Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3jeudi 16 décembre 2010
  7. 7. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 50000 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  8. 8. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 50000 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  9. 9. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  10. 10. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  11. 11. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 G2One acquisition 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  12. 12. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 150000 100000 G2One acquisition 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  13. 13. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 Groovy 1.6 150000 100000 G2One acquisition 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  14. 14. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 Groovy 1.6 150000 100000 G2One acquisition 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  15. 15. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 Groovy 1.7 Groovy 1.6 150000 100000 G2One acquisition 50000 Groovy 1.5 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  16. 16. But first... some figures... Downloads Moving Average (year) Groovy downloads per month 200000 Groovy 1.7 Groovy 1.6 8 5 K 150000 100000 50000 Groovy 1.5 1 G2One acquisition 0 déc.-07 févr.-08 avr.-08 juin-08 août-08 oct.-08 janv.-09 mars-09 mai-09 juil.-09 sept.-09 nov.-09 janv.-10 mars-10 mai-10 juil.-10 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4jeudi 16 décembre 2010
  17. 17. Groovy 1.7.6 and 1.8-beta-3 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5jeudi 16 décembre 2010
  18. 18. looking into the Pastjeudi 16 décembre 2010
  19. 19. Big highlights of Groovy 1.6 • Greater compile-time and runtime performance • Multiple assignments • Optional return for if/else and try/catch/finally • Java 5 annotation definition • AST Transformations • The Grape module and dependency system • Various Swing related improvements • JMX Builder • Metaprogramming additions • JSR-223 scripting engine built-in • Out-of-the-box OSGi support Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7jeudi 16 décembre 2010
  20. 20. Big highlights of Groovy 1.6 • Greater compile-time and runtime performance • Multiple assignments • Optional return for if/else and try/catch/finally • Java 5 annotation definition • AST Transformations • The Grape module and dependency system • Various Swing related improvements • JMX Builder • Metaprogramming additions • JSR-223 scripting engine built-in • Out-of-the-box OSGi support Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8jeudi 16 décembre 2010
  21. 21. Multiple assignement // multiple assignment def (a, b) = [1, 2] assert a == 1 && b == 2 // with typed variables def (int c, String d) = [3, "Hi"] assert c == 3 && d == "Hi" def geocode(String place) { [48.8, 2.3] } def lat, lng // assignment to existing variables (lat, lng) = geocode(Paris) // classical variable swaping example (a, b) = [b, a] Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9jeudi 16 décembre 2010
  22. 22. More optional return // optional return for if statements def m1() {     if (true) 1     else 0 } assert m1() == 1 // optional return for try/catch/finally def m2(bool) {     try {         if (bool) throw new Exception()         1     } catch (any) { 2 }     finally { 3 } } assert m2(true) == 2 && m2(false) == 1 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10jeudi 16 décembre 2010
  23. 23. AST Transformation (1/2) • Groovy 1.6 introduced AST Transformations – AST: Abstract Syntax Tree • Ability to change what’s being compiled by the Groovy compiler... at compile time –No runtime impact! – Change the semantics of your programs! Even hijack the Groovy syntax! – Implementing recurring patterns in your code base – Remove boiler-plate code • Two kinds: global and local – triggered by annotations Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11jeudi 16 décembre 2010
  24. 24. AST Transformations (2/2) • Transformations introduced in 1.6 – @Singleton – @Immutable, @Lazy, @Delegate – @Newify – @Category, @Mixin – @PackageScope – Swing’s @Bindable and @Vetoable – Grape’s own @Grab Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12jeudi 16 décembre 2010
  25. 25. @Immutable • To properly implement immutable classes – No mutations — state musn’t change – Private final fields – Defensive copying of mutable components – Proper equals() / hashCode() / toString() for comparisons or as keys in maps @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 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13jeudi 16 décembre 2010
  26. 26. Grab a grape! • Simple distribution and sharing of Groovy scripts • Dependencies stored locally – Can even use your own local repositories @Grab(group   = org.mortbay.jetty,       module  = jetty‐embedded,       version = 6.1.0) def startServer() {     def srv = new Server(8080) SIONS)     def ctx = new Context(srv , "/", SES     ctx.resourceBase = "." ovy")      ctx.addServlet(GroovyServlet, "*.gro     srv.start() } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14jeudi 16 décembre 2010
  27. 27. into the Present...jeudi 16 décembre 2010
  28. 28. Big highlights of Groovy 1.7 • Anonymous Inner Classes and Nested Classes • Annotations anywhere • Grape improvements • Power Asserts • AST Viewer • AST Builder • Customize the Groovy Truth! • Rewrite of the GroovyScriptEngine • Groovy Console improvements • SQL support refinements Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 16jeudi 16 décembre 2010
  29. 29. Big highlights of Groovy 1.7 • Anonymous Inner Classes and Nested Classes • Annotations anywhere • Grape improvements • Power Asserts • AST Viewer • AST Builder • Customize the Groovy Truth! • Rewrite of the GroovyScriptEngine • Groovy Console improvements • SQL support refinements Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 17jeudi 16 décembre 2010
  30. 30. AIC and NC • Anonymous Inner Classes and Nested Classes Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18jeudi 16 décembre 2010
  31. 31. AIC and NC • Anonymous Inner Classes and Nested Classes Fo rJ ava ’n p aste c opy atib ility co mp sak e :-) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18jeudi 16 décembre 2010
  32. 32. Annonymous Inner Classes bo olean called = false Timer ti mer = new Timer() timer.schedule(n ew TimerTask() {     void run() {          called = true     } }, 0) sleep 100 assert called Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19jeudi 16 décembre 2010
  33. 33. Annonymous Inner Classes bo olean called = false Timer ti mer = new Timer() timer.schedule(n ew TimerTask() {     void run() {          called = true     } { called = true } }, 0) as TimerTask sleep 100 assert called Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19jeudi 16 décembre 2010
  34. 34. Nested Classes class Environment {     static class Production          extends Environment {}     static class Development          extends Environment {} } new Environment.Production() Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20jeudi 16 décembre 2010
  35. 35. Anotations almost anywhere • You can put annotations – on imports – on packages – on variable declarations • Examples with @Grab following... Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21jeudi 16 décembre 2010
  36. 36. Grape improvements (1/4) • @Grab on import @Grab(group = net.sf.json‐lib,       module = json‐lib,      version = 2.3,  classifier = jdk15) import net.sf.json.groovy.* assert new JsonSlurper().parseText( new JsonGroovyBuilder().json {     book(title: "Groovy in Action",          author: "Dierk König et al") }.toString ()).book.title == "Groovy in Action" Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 22jeudi 16 décembre 2010
  37. 37. Grape improvements (2/4) • Shorter module / artifact / version parameter – Example of an annotation on a variable declaration @Grab(net.sf.json‐lib:json‐lib:2.3:jdk15) () def builder = new net.sf.json.groovy.JsonGroovyBuilder def books = builder.books {     book(title: "Groovy in Action", author: "Dierk Koenig") } assert books.toString() ==     {"books":{"book":{"title":"Groovy in Action", +      "author":"Dierk Koenig"}}} Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 23jeudi 16 décembre 2010
  38. 38. Grape improvements (3/4) • Groovy 1.7 introduced Grab resolver – For when you need to specify a specific repository for a given dependency @GrabResolver(     name = restlet.org,     root = http://maven.restlet.org) @Grab(org.restlet:org.restlet:1.1.6) import org.restlet.Restlet Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 24jeudi 16 décembre 2010
  39. 39. Power Asserts (1/2) • Much better assert statement! – Invented and developed in the Spock framework • Given this script... def energy = 7200 * 10**15 + 1 def mass = 80 def celerity = 300000000 assert energy == mass * celerity ** 2 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 25jeudi 16 décembre 2010
  40. 40. Power Asserts (2/2) • You’ll get a more comprehensible output Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 26jeudi 16 décembre 2010
  41. 41. Easier AST Transformations • AST Transformations are a very powerful feature • But are still rather hard to develop – Need to know the AST API closely • To help with authoring your own transformations, we’ve introduced – the AST Viewer in the Groovy Console – the AST Builder Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 27jeudi 16 décembre 2010
  42. 42. AST Viewer Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 28jeudi 16 décembre 2010
  43. 43. AST Builder // Ability to build AST parts // ‐‐> from a String new AstBui lder().buildFromString( "Hello" ) // ‐‐> from code new AstBuilder().buildFromCode { "Hello" } // ‐‐> from a specification  { List<ASTNo de> nodes = new AstBuilder().buildFromSpec     block {         returnStatement {             constant "Hello"         }     } } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 29jeudi 16 décembre 2010
  44. 44. Customize the Groovy Truth! • Ability to customize the truth by implementing a boolean asBoolean() method class Predicate {     boolean value     boolean asBoolean() { value } } def tr uePred  = new Predicate(value: true) def fals ePred = new Predicate(value: false) assert truePred && !falsePred Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 30jeudi 16 décembre 2010
  45. 45. Groovy 1.7.x changes • Since Groovy 1.7.0... Groovy 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5 and 1.7.6 have been released already! • Here’s what’s new! Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 31jeudi 16 décembre 2010
  46. 46. Grape improvements (4/4) • Groovy 1.7.5 even further shrinks the grab resolver definition: @Gra bResolver(http://maven.restlet.org) @Grab(org.restlet:org.restlet:1.1.6) import org.restlet.Restlet Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 32jeudi 16 décembre 2010
  47. 47. Map improvements (1/2) // map auto‐vification def m =  [:].withDefault { key ‐> "Default" } assert m[z] == "Default"  assert m[a] == "Default" // default sort, sort with a comparator m.sort() m.sort({ a, b ‐> a <=> b } as Comparator) // max{} and min{} assert [a:  1, b: 2].max{ it.value }.value == 2 Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 33jeudi 16 décembre 2010
  48. 48. Map improvements (2/2) // before Map#withDefault() def words = "one two two three three three".split() def freq = [:] words.each {     if (it in freq)         freq[it] += 1     else         freq[it] = 1     } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 34jeudi 16 décembre 2010
  49. 49. Map improvements (2/2) //  after Map#withDefault() def words = "one two two three three three".split() def freq = [:].withDefault { k ‐> 0 } words.each {         freq[it] += 1 } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 35jeudi 16 décembre 2010
  50. 50. XML back to String • Ability to retrieve the XML string from a node from an XmlSlurper GPathResult def xml = """ <books>      <book isbn="12345">Groovy in Action</book> </books> """ def root = new XmlSlurper().parseText(xml) def someNode = root.book def bu ilder = new StreamingMarkupBuilder() assert build er.bindNode(someNode).toString() ==         "<book  isbn=12345>Groovy in Action</book>" Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 36jeudi 16 décembre 2010
  51. 51. Currying improvements // right currying def divide = { a, b ‐> a / b } def halver = divide.rcurry(2) assert halver(8) == 4   // currying n‐th parameter def jo inWithSeparator = { one, sep, two ‐>     one + sep + two } def joinWithComma =      jo inWithSeparator.ncurry(1, , ) assert joinWithComma(a, b) == a, b Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 37jeudi 16 décembre 2010
  52. 52. Date improvements im port static java.util.Calendar.* // convert to calendar def cal = new Date().toCalendar()   // update a date (or a calendar) cal.set(year: cal[YEAR] + 1) cal[MONTH] = MARCH // create a ne w date (or a calendar) from one def nextYear = c al.updated(year: cal[YEAR] + 1) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 38jeudi 16 décembre 2010
  53. 53. New String methods println """ println """     def method() {     |def method() {         return bar     |    return bar     }     |} """.stripIndent() """.stripMargin(|) // string "translation" (UNIX tr) assert hello.tr(z‐a, Z‐A) == HELLO  WAAAA! asse rt Hello World!.tr(a‐z, A) == HAAAA 2d! assert Hell o World!.tr(lloo, 1234) == He224 W4r // capitalize the first letter assert h.capitalize() == H assert hello.capitalize() == Hello rld asse rt hello world.capitalize() == Hello wo mmand) // tab/space (un)expansion (UNIX expand co 7 8         assert 1234567t8t .expand() == 123456 assert     x    .unexpand() ==     xt  Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 39jeudi 16 décembre 2010
  54. 54. Map supports isCase() def m = [a: 1, b: 2] def val = a switch (val) {     case m: "key in map"; break     // equival ent to // case { val in m }: ...     default: "not in map" } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 40jeudi 16 décembre 2010
  55. 55. (G)String to Enum coercion enum Color {     red, green, blue } // coercion with as def r = "red" as Color // implicit coercion Color b = "blue" // with GStrings too def g = "${green}" as Color Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 41jeudi 16 décembre 2010
  56. 56. ...and beyond!jeudi 16 décembre 2010
  57. 57. Groovy 1.8 & beyond • Still subject to discussion • Always evolving roadmap • Things may change! Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 43jeudi 16 décembre 2010
  58. 58. What’s cooking?jeudi 16 décembre 2010
  59. 59. What we’re working on • More runtime performance improvements • Closures – annotation parameters composition, memoization, and trampoline • Native JSON support – builder and parser • New AST transformations • Gradle build • Modularizing Groovy • Align with JDK 7 / Java 7 / Project Coin • Enhanced DSL support Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 45jeudi 16 décembre 2010
  60. 60. jeudi 16 décembre 2010
  61. 61. Gjeudi 16 décembre 2010
  62. 62. jeudi 16 décembre 2010
  63. 63. jeudi 16 décembre 2010
  64. 64. An example, with Fibonacci Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  65. 65. An example, with Fibonacci • Known example of worst case performance for Groovy Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  66. 66. An example, with Fibonacci • Known example of worst case performance for Groovy Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  67. 67. An example, with Fibonacci • Known example of worst case performance for Groovy • Groovy 1.7.5 vs Java – 25131ms / 1110ms –22x slower! Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  68. 68. An example, with Fibonacci • Known example of worst case performance for Groovy • Groovy 1.7.5 vs Java – 25131ms / 1110ms –22x slower! Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  69. 69. An example, with Fibonacci • Known example of worst case performance for Groovy • Groovy 1.7.5 vs Java – 25131ms / 1110ms –22x slower! • Groovy 1.8-beta-3 vs Java – 1871ms / 1110ms –only 68% slower Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  70. 70. An example, with Fibonacci • Known example of worst case performance for Groovy 13 x • Groovy 1.7.5 vs Java – 25131ms / 1110ms –22x slower! • Groovy 1.8-beta-3 vs Java – 1871ms / 1110ms –only 68% slower Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 48jeudi 16 décembre 2010
  71. 71. Optimizations for int • Currently, the optimizations cover most of native operations on primitive ints – Be careful, your mileage may vary • To come next – optimizations for doubles – improving array accesses – then other primitives optimizations – and mixed cases of primitives Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 49jeudi 16 décembre 2010
  72. 72. Closure annotation parameters • Groovy 1.5 brought Java 5 annotations • What if... we could go beyond what Java offered? – In 1.7, we can put annotations on packages, imports and variable declarations – But annotations are still limited in terms of parameters they allow • Here comes closure annotation parameters! – Groovy 1.8 will give us the ability to access annotation with closure parameters at runtime Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 50jeudi 16 décembre 2010
  73. 73. GContracts • Closures are already allowed in the Groovy 1.7 Antlr grammar – André Steingreß created GContracts, a «design by contract» module // a class invariant @Invar iant({ name.size() > 0 && age > ageLimit() }) class Person { String name; int age }   // a method pre‐condition @Requires({ message != null }) void greet(String message) { ... }   // a method post‐condition @Ensures({ returnResult % 2 == 0 }) int evenResult() { ... } Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 51jeudi 16 décembre 2010
  74. 74. Closure composition • Functional flavor! def plus2  = { it + 2 } def times3 = { it * 3 }   def composed1 = plus2 << times3 assert composed1(3) == 11 assert composed1(4) == plus2(times3(4))   def composed2 = times3 << plus2 assert composed2(3) == 15 assert composed2(5) == times3(plus2(5))   // reverse composition assert composed1(3) == (times3 >> plus2)(3) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 52jeudi 16 décembre 2010
  75. 75. Closure memoization • Memoization: remember the outcome of previous (ideally side-effect free) invocations def c = { a, b ‐> sleep 1000; a + b }.memoize() assert c(1, 2) == 3 // after 1000ms assert c(1, 2) == 3 // return immediately   // other forms: // at least 10 invocations cached def cAtLeast = { ... }.memoizeAtLeast(10) // at most 10 invocations cached def cAtMost = { ... }.memoizeAtMost(10) // between 10 and 20 invocations cached def cAtLeast = { ... }.memoizeBetween(10, 20) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 53jeudi 16 décembre 2010
  76. 76. Closure trampoline • No more infamous StackOvervlow errors for deeply recursive algorithms – if you use closure trampolines explicitely def fact fact = { int n, BigInteger accu ‐>     n > 1 ? fact.trampoline(n ‐ 1, n * accu) : accu }.trampoline() def factorial = { int n ‐> fact(n, 1G) } assert factorial(1)    == 1 assert factorial(3)    == 6 assert factorial(1000) == 402387260077... Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 54jeudi 16 décembre 2010
  77. 77. New AST xforms (1/2) • Many new transformations coming up for removing even more boiler plate code @Log inject a logger in your classes @Field creates a field in your scripts @PackageScope improvements (methods & fields) @Synchronized providing safer synchronization semantics @InheritConstructor ex. when extending Exception @IndexedProperties JavaBeans indexed property support @AutoClone automatic cloning of your beans @AutoExternalizable automatic externalization of your beans Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 55jeudi 16 décembre 2010
  78. 78. New AST xforms (2/2) @ThreadInterrupt makes a script interruptible @TimedInterrupt interrupt after a period of time @ConditionalInterrupt interrupt with a custom condition @Canonical adds equals, hashCode, toString, ctor - @EqualsAndHashCode just equals and hashCode - @ToString just toString - @TupleConstructor adds a «tuple» constructor Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 56jeudi 16 décembre 2010
  79. 79. Java 7 / 8 / Project Coin • Alignment with JDK 7 will come in Groovy 1.9 • JSR-292 InvokeDynamic • Simple Closures (8) • Proposals from Project Coin – Strings in switch (7) – Automatic Resource Management (7) – Improved generics type inference (diamond <>) (7) – Simplified varargs method invocation (7) – Better integral literals (7) – Language support for collections (8?) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 57jeudi 16 décembre 2010
  80. 80. Java 7 / 8 / Project Coin • Alignment with JDK 7 will come in Groovy 1.9 • JSR-292 InvokeDynamic • Simple Closures (8) • Proposals from Project Coin – Strings in switch (7) – Automatic Resource Management (7) – Improved generics type inference (diamond <>) (7) – Simplified varargs method invocation (7) – Better integral literals (7) – Language support for collections (8?) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 57jeudi 16 décembre 2010
  81. 81. Java 7 / 8 / Project Coin • Alignment with JDK 7 will come in Groovy 1.9 • JSR-292 InvokeDynamic • Simple Closures (8) • Proposals from Project Coin – Strings in switch (7) – Automatic Resource Management (7) – Improved generics type inference (diamond <>) (7) – Simplified varargs method invocation (7) – Better integral literals (7) – Language support for collections (8?) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 57jeudi 16 décembre 2010
  82. 82. Java 7 / 8 / Project Coin • Alignment with JDK 7 will come in Groovy 1.9 • JSR-292 InvokeDynamic • Simple Closures (8) • Proposals from Project Coin – Strings in switch (7) – Automatic Resource Management (7) – Improved generics type inference (diamond <>) (7) – Simplified varargs method invocation (7) – Better integral literals (7) – Language support for collections (8?) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 57jeudi 16 décembre 2010
  83. 83. Java 7 / 8 / Project Coin • Alignment with JDK 7 will come in Groovy 1.9 • JSR-292 InvokeDynamic • Simple Closures (8) • Proposals from Project Coin – Strings in switch (7) – Automatic Resource Management (7) – Improved generics type inference (diamond <>) (7) – Simplified varargs method invocation (7) – Better integral literals (7) – Language support for collections (8?) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 57jeudi 16 décembre 2010
  84. 84. Improved DSL support • GEP-3: an extended command expression DSL – Groovy Extension Proposal #3 • Command expressions – basically top-level statements without parens – combine named and non-named arguments in the mix •for nicer Domain-Specific Languages – (methodName arguments)* Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 58jeudi 16 décembre 2010
  85. 85. Before GEP-3 • The idea: extend command-expressions, beyond top-level statements, for chained method calls • Before send("Hello").to("Graeme") check(that: margherita).tastes(good) sell(100.shares).of(MSFT) take(2.pills).of(chloroquinine).after(6.hours) wait(10.minutes).and(execute {  }) blend(red, green).of(acrylic) Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 59jeudi 16 décembre 2010
  86. 86. With GEP-3 • The idea: extend command-expressions, beyond top-level statements, for chained method calls • After send "Hello"  to "Graeme" check that: margherita  tastes good sell 100.shares  of MSFT take 2.pills  of chloroquinine  after 6.hours wait 10.minutes  and execute {  } blend red, green  of acrylic Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 60jeudi 16 décembre 2010
  87. 87. With GEP-3 • The idea: extend command-expressions, beyond top-level statements, for chained method calls • After Less & co pare send "Hello"  to "Graeme" check that: margherita  tastes good mm ns sell 100.shares  of MSFT as take 2.pills  of chloroquinine  after 6.hours wait 10.minutes  and execute {  } blend red, green  of acrylic Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 60jeudi 16 décembre 2010
  88. 88. The pattern • A repetition of – method name – arguments (mix of named and normal) check  that: margherita  tastes  good method method named parameter parameter name name Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 61jeudi 16 décembre 2010
  89. 89. Summary • No need to wait for Java 7, 8, 9... – closures, properties, interpolated strings, extended annotations, metaprogramming, [YOU NAME IT]... Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 62jeudi 16 décembre 2010
  90. 90. Summary • No need to wait for Java 7, 8, 9... – closures, properties, interpolated strings, extended annotations, metaprogramming, [YOU NAME IT]... ’s s till Gro ovy novat ive in 20 03! si nce Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 62jeudi 16 décembre 2010
  91. 91. Summary • No need to wait for Java 7, 8, 9... – closures, properties, interpolated strings, extended annotations, metaprogramming, [YOU NAME IT]... ’s s till Gro ovy novat ive in 20 03! si nce Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 62jeudi 16 décembre 2010
  92. 92. d A a n Q Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited.jeudi 16 décembre 2010
  93. 93. Picture credits Myself http://www.flickr.com/photos/romainguy/783719255/sizes/l/in/photostream/ Big hat http://cdn.plussizecostumesupercenter.com/csc_inc/images/items/343x432/47703.jpg RIP http://gipsydan.files.wordpress.com/2009/11/rip.jpg House / past: http://www.flickr.com/photos/jasonepowell/3680030831/sizes/o/ Present clock: http://www.flickr.com/photos/38629278@N04/3784344944/sizes/o/ Future: http://www.flickr.com/photos/befuddledsenses/2904000882/sizes/l/ Cooking: http://www.flickr.com/photos/eole/449958332/sizes/l/ Snail http://www.freakingnews.com/images/app_images/snail-0.jpg Usein bolt record http://www.phombo.com/sports/usain-bolt-beijing-2008-olympics/17450/full/popular/ Fibonacci figure http://cnx.org/content/m22060/latest/graphics1.jpg Fibonacci face http://www.robinkelly.co.nz/site/acupil/images/lfib.jpg Puzzle: http://www.everystockphoto.com/photo.php?imageId=263521 Light bulb: https://newsline.llnl.gov/retooling/mar/03.28.08_images/lightBulb.png Check mark: http://www.lnl.infn.it/~epics/WikiDumps/localhost/600px-symbol_ok.svg.png Puzzle: http://www.everystockphoto.com/photo.php?imageId=263521 Light bulb: https://newsline.llnl.gov/retooling/mar/03.28.08_images/lightBulb.png Green leaf: http://www.flickr.com/photos/epsos/3384297473/ Trafic light: http://rihancompany.com/var/243/35581-Traffic%20light%20drawing.jpg Butt kick: http://www.brentcsutoras.com/wp-content/uploads/2009/12/kick-ass-1.jpg Copyright 2010 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 64jeudi 16 décembre 2010
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×