SlideShare una empresa de Scribd logo
1 de 85
Descargar para leer sin conexión
Practical Domain-Specific
 Languages with Groovy

All the techniques to create your own DSLs

          Guillaume Laforge
      Head of Groovy Development
Guillaume Laforge

• Groovy Project Manager
• JSR-241 Spec Lead
• Head of Groovy Development
  at SpringSource
• Initiator of the Grails framework

• Co-author of Groovy in Action

• Speaker: JavaOne, QCon, JavaZone, Sun TechDays,
  Devoxx, The Spring Experience, JAX, Dynamic
  Language World, IJTC, and more...

                                          3
A few words about Groovy

• Groovy is a dynamic language for the JVM
  – with a Meta Object Protocol
  – compiles directly to bytecode, seamless Java interop
• Open Source ASL 2 project hosted at Codehaus
• Relaxed grammar derived from Java 5
  – + borrowed good ideas from Ruby, Python, Smalltalk
• Fast... for a dynlang on the JVM
• Closures, properties, optional typing, BigDecimal
  by default, nice wrapper APIs, and more...




                                                   4
nd a
Ag e
       • The context and
         the usual issues we face
       • Some real-life examples of
         Domain-Specific Languages
       • Groovy’s DSL capabilities
       • Integrating a DSL
         in your application
       • Considerations to remember
         when designing your own DSL


                                5
The context
Subject Matter Experts,
  Business analysts...
Developer producing
           LOLCODE



HAI
CAN HAS STDIO?
I HAS A VAR
IM IN YR LOOP
   UP VAR!!1
   VISIBLE VAR
   IZ VAR BIGGER THAN 10?
KTHXBYE
IM OUTTA YR LOOP
KTHXBYE
Lots of languages...
And in the end...
...nobody understands each other
Expressing requirements...




                             11
DSL: a potential solution?

• Use a more expressive language than a general purpose one

• Share a common metaphore of understanding between
  developers and subject matter experts

• Have domain experts help with the design of the business
  logic of an application

• Avoid cluttering business code with too much boilerplate
  technical code

• Cleanly separate business logic from application code

• Let business rules have their own lifecycle




                                                      12
Towards more readability (1)




                               13
Towards more readability (1)




                               13
Towards more readability (1)




                               20%




                               13
Towards more readability (2)




                               14
Towards more readability (2)




                               14
Towards more readability (2)




                          80%

                                14
nd a
Ag e
       • The context and
         the usual issues we face
       • Some real-life examples of
         Domain-Specific Languages
       • Groovy’s DSL capabilities
       • Integrating a DSL
         in your application
       • Considerations to remember
         when designing your own DSL


                               15
A collection of DSLs


• In our everyday life, we’re surrounded by DSLs



  – Technical dialects

  – Notations

  – Business languages




                                             16
Technical dialects




                     17
SQL
^[w-.]+@([w-]){2,4}$




                          19
Notations




            20
1. e4 e5
2. Nf3 Nc6
3. Bb5 a6
L2 U F-1 B L2 F B -1 U L2
Visual!
Business languages




                     24
Real-life Groovy examples

• Anti-malaria drug resistance simulation
• Human Resources employee skills representation
• Insurance policies risk calculation engine
• Loan acceptance rules engine for a financial
  platform
• Mathematica-like lingua for nuclear safety
  simulations
• Market data feeds evolution scenarios

• and more...


                                           25
nd a
Ag e
       • The context and
         the usual issues we face
       • Some real-life examples of
         Domain-Specific Languages
       • Groovy’s DSL capabilities
       • Integrating a DSL
         in your application
       • Considerations to remember
         when designing your own DSL


                               26
A flexible & malleable syntax

• No need to write full-blown classes, use scripts
• Optional typing (def)
  – in scripts, you can even omit the def keyword
• Native syntax constructs
• Parentheses & semi-colons are optional
• Named arguments
• BigDecimal by default for decimal numbers
• Closures for custom control structures
• Operator overloading



                                                    27
Scripts vs classes

• Hide all the boilerplate technical code
  – an end-user doesn’t need to know about classes


  – public class Rule {
        public static void main(String[] args) {
            System.out.println(“Hello”);
        }
    }

  – println “Hello”




                                                 28
Optional typing

• No need to bother with types or even generics
  – unless you want to!
• Imagine an interest rate lookup table method
  returning some generified type:

  –Rate<LoanType, Duration, BigDecimal>[]
        lookupTable() { ... }
   def table = lookupTable()

• No need to repeat the horrible generics type info!



                                              29
Native syntax constructs

• Lists
  – [Monday, Tuesday, Wednesday]

• Maps
  – [CA: ‘California’, TX: ‘Texas’]

• Ranges
  – def bizDays = Monday..Friday
  – def allowedAge = 18..65
  – You can create your own custom ranges




                                            30
Optional parens & semis

• Make statements and expressions
  look more like natural languages



  – move(left);

  – move left




                                     31
Named arguments

• In Groovy you can mix named and unnamed
  arguments for method parameters
    – named params are actually put in a map parameter
    – plus optional parens & semis

•     take 1.pill,
       of: Chloroquinine,
    after: 6.hours
• Corresponds to a method signature like:
    –def take(Map m, MedicineQuantity mq)


                                                  32
BigDecimal by default

• Main reason why financial institutions often decide
  to use Groovy for their business rules!
  – Although these days rounding issues are overrated!

• Java vs Groovy for a simple interpolation equation

• BigDecimal uMinusv = c.subtract(a);
  BigDecimal vMinusl = b.subtract(c);
  BigDecimal uMinusl = a.subtract(b);
  return e.multiply(uMinusv)
              .add(d.multiply(vMinusl))
              .divide(uMinusl, 10, BigDecimal.ROUND_HALF_UP);

• (d * (b - c) + e * (c - a)) / (a - b)



                                                     33
Custom control structures
Thanks to closures

• When closures are last, they can be put “out” of
  the parentheses surrounding parameters

• unless (account.balance > 100.euros,
      { account.debit 100.euros })

• unless (account.balance > 100.euros) {
      account.debit 100.euros
  }

• Signature def unless(boolean b, Closure c)


                                              34
Operator overloading

a + b    a.plus(b)
a - b    a.minus(b)          • Currency amounts
a * b    a.multiply(b)        – 15.euros + 10.dollars
a / b    a.divide(b)
a % b    a.modulo(b)         • Distance handling
a ** b   a.power(b)           – 10.kilometers - 10.meters
a | b    a.or(b)
a & b    a.and(b)            • Workflow, concurrency
a ^ b    a.xor(b)             – taskA | taskB & taskC
a[b]     a.getAt(b)
a << b   a.leftShift(b)      • Credit an account
a >> b   a.rightShift(b)      – account << 10.dollars
+a       a.positive()           account += 10.dollars
-a       a.negative()           account.credit 10.dollars
~a       a.bitwiseNegate()

                                                   35
Groovy’s dynamic heart:

The MOP!
MetaObject Protocol
Groovy’s MOP

• All the accesses to methods, properties,
  constructors, operators, etc. can be intercepted
  thanks to the MOP
• While Java’s behavior is hard-wired at compile-
  time in the class
• Groovy’s runtime behavior is adaptable at
  runtime through the metaclass.
• Different hooks for changing the runtime behavior
  – GroovyObject, custom MetaClass implementation,
    categories, ExpandoMetaClass




                                                37
GroovyObject

• All instances of classes created in Groovy
  implement the GroovyObject interface:

  –getProperty(String name)
  –setProperty(String name, Object value)
  –invokeMethod(String name, Object[]
   params)
  –getMetaClass()
  –setMetaClass(MetaClass mc)

• A GO can have “pretended” methods and properties


                                               38
MetaClass

• The core of Groovy’s MOP system
  –invokeConstructor()
  –invokeMethod() and invokeStaticMethod()
  –invokeMissingMethod()
  –getProperty() and setProperty()
  –getAttribute() and setAttribute()
  –respondsTo() and hasProperty()
• MetaClasses can change the behavior of existing
  third-party classes — even from the JDK


                                            39
ExpandoMetaClass

• A DSL for MetaClasses!
• MoneyAmount.metaClass.constructor = { ... }
  Number.metaClass.getDollars = { ... }
  Distance.metaClass.toMeters = { ... }
  Distance.metaClass.static.create = { ... }
• To avoid repetition of Type.metaClass, you can pass
  a closure to metaClass { ... }
• The delegate variable in closure represents the
  current instance, and it the default parameter




                                             40
The Builder pattern
The Groovy MarkupBuilder

• def mkp = new MarkupBuilder()
  mkp.html {
      head {
          title “Groovy in Action”
      }
      body {
          div(width: ‘100’) {
              p(class: ‘para) {
                  span “Best book ever!”
              }
          }
      }
  }
                                     42
A builder for HR

• softskills {
      ideas {
          capture 2
          formulate 3
      }
      ...
  }
  knowhow {
      languages {
          java 4
          groovy 5
      }
      ...
  }


                        43
A builder for HR

• softskills {
      ideas {
          capture 2
          formulate 3
      }
      ...
  }
  knowhow {
      languages {
          java 4
          groovy 5
      }
      ...
  }


                        43
Builders

• Builders are...
  – a mechanism for creating any tree-structered graph
  – the realization of the GoF builder pattern at the syntax
    level in Groovy
  – simply a clever use of chained method invocation,
    closures, parentheses omission, and use of the
    GroovyObject methods


• Existing builders
  – XML, Object graph, Swing, Ant, JMX, and more...




                                                     44
The clever trick

• GroovyObject#invokeMethod() is used to catch all
  non-existing method calls in the context of the
  builder
• The nesting of closures visually shows the level of
  nesting / depth in the tree
• builder.m1(attr1:1, attr2:2, { builder.m2(...,
  {...}) } becomes equivalent to
 builder.m1(attr1:1, attr2:2) { m2(...) {...} }
 thanks to parens omission




                                               45
Adding properties to numbers

• Three possible approaches

  – create a Category
    •a category is a kind of decorator for default MCs


  – create a custom MetaClass
    •a full-blown MC class to implement and to set on the
     POGO instance


  – use ExpandoMetaClass
    •friendlier DSL approach but with a catch



                                                         46
With a Category

• class DistanceCategory {
      static Distance getMeters(Integer self) {
          new Distance(self, Unit.METERS)
      }
  }

 use(DistanceCategory) {
     100.meters
 }

• Interesting scope: thread-bound & lexical
• But doesn’t work across the hierarchy of classes
  – ie. subclasses won’t benefit from the new property


                                                   47
With an ExpandoMetaClass

• Number.metaClass.getMeters = {->
      new Distance(delegate, Unit.METERS)
  }

 100.meters

• Works for the class hierarchy for POJOs, and a flag
  exists to make it work for POGOs too
• But the catch is it’s really a global change, so
  beware EMC enhancements collisions




                                              48
Compile-time metaprogramming

• Groovy 1.6 introduced AST Transformations
• Compile-time == No runtime performance penalty!




                 Transformation


                                          49
AST Transformations

• Two kinds of transformations


  – Global transformations
    •applicable to all compilation units


  – Local transformations
    •applicable to marked program elements
    •using specific marker annotations




                                             50
Example #1: @Singleton

• Let’s revisit this evil (anti-)pattern
   !   public class Evil {
           public static final Evil instance = new Evil
       ();
           private Evil () {}
           Evil getInstance() { return instance; }
       }


• In Groovy
   !   @Singleton class Evil {}

• Also a “lazy” version
   !   @Singleton(lazy = true) class Evil {}


                                                  51
Example #2: @Delegate
Not just for managers!

• You can delegate to fields of your classes
  – class Employee {
        def doTheWork() { “done” }
    }
    class Manager {
        @Delegate
        Employee slave = new Employee()
    }
    def god = new Manager()
    assert god.doTheWork() == “done”

• Damn manager who will get all the praise...


                                                52
Global transformations

• Implement ASTTransformation
• Annotate the transfo specifying a compilation phase

• @GroovyASTTransformation(phase=CompilePhase.CONVERSION)
  public class MyTransformation
      implements ASTTransformation {
      public void visit(ASTNode[] nodes, SourceUnit unit)
      { ... }
  }

• For discovery, create the file META-INF/services/
 org.codehaus.groovy.transform.ASTTransformation
• Add the fully qualified name of the class in that file


                                                53
Local transformations

• Same approach as Globale transformations
• But you don’t need the META-INF file
• Instead create an annotation to specify on which
  element the transformation should apply

• @Retention(RetentionPolicy.SOURCE)
  @Target([ElementType.METHOD])
  @GroovyASTTransformationClass(
      ["fqn.MyTransformation"])
  public @interface WithLogging {...}



                                             54
Example: the Spock framework

• Changing the semantics of the original code
• But keeping a valid Groovy syntax
• @Speck
  class HelloSpock {
      def "can you figure out what I'm up to?"()
  {
          expect:
          name.size() == size

          where:
          name << ["Kirk", "Spock", "Scotty"]
          size << [4, 5, 6]
     }
 }
                                                55
nd a
Ag e
       • The context and
         the usual issues we face
       • Some real-life examples of
         Domain-Specific Languages
       • Groovy’s DSL capabilities
       • Integrating a DSL
         in your application
       • Considerations to remember
         when designing your own DSL


                               56
Various integration mechanisms

• Java 6’s javax.script.* APIs (aka JSR-223)
• Spring’s language namespace
• Groovy’s own mechanisms

• But a key idea is to externalize those DSL programs
  – DSL programs can have their own lifecycle
  – no need to redeploy an application because of a rule
    change
  – business people won’t see the technical code




                                                   57
Java 6’s javax.script.* API

• Groovy 1.6 provides its own implementation of the
  javax.script.* API

• ScriptEngineManager mgr =
          new ScriptEngineManager();
  ScriptEngine engine =
          mgr.getEngineByName(“Groovy”);

 String result = (String)engine.eval(“2+3”);




                                            58
Spring’s lang namespace

• POGOs (Plain Old Groovy Objects) can be pre-
  compiled as any POJO and used interchangeably
  with POJOs in a Spring application
• But Groovy scripts & classes can be loaded at
  runtime through the <lang:groovy/> namespace
  and tag
• Reloadable on change
• Customizable through a custom MetaClass

• <lang:groovy id="events"
      script-source="classpath:dsl/
  eventsChart.groovy"
      customizer-ref="eventsMetaClass" />

                                            59
Groovy’s own mechanisms

• Eval
  – for evaluating simple expressions


• GroovyShell
  – for more complex scripts and DSLs


• GroovyClassLoader
  – the most powerful mechanism




                                        60
Eval


• Simple mechanism to evaluate math-like formulas

• Eval.me (           ‘3*4’)
  Eval.x (1,          ‘3*x + 4’)
  Eval.xy (1, 2,      ‘x + y’)
  Eval.xyz(1, 2, 3,   ‘x * y - z’)




                                           61
GroovyShell


• A Binding provides a context of execution
  – can implement lazy evaluation if needed


• A base script class can be specified

• def binding = new Binding()
  binding.mass = 22.3
  binding.velocity = 10.6
  def shell = new GroovyShell(binding)
  shell.evaluate(“mass * velocity ** 2 / 2”)


                                              62
GroovyClassLoader

• Most powerful mechanism
 – could also visit or change the AST
 – scripts & classes can be loaded from elsewhere
 – more control on compilation

• GroovyClassLoader gcl =
          new GroovyClassLoader();
  Class clazz = gcl.parseClass(
          new File(“f.groovy”));
  GroovyObject instance =
          (GroovyObject)clazz.newInstance();
  instance.setMetaClass(customMC);


                                                    63
Externalize business rules

• Although Groovy DSLs can be embedded in normal
  Groovy classes, you should externalize them
• Store them elsewhere
  – in a database, an XML file, etc.
• Benefits
  – Business rules are not entangled
    in technical application code
  – Business rules can have their own lifecycle, without
    requiring application redeployments




                                                  64
nd a
Ag e
       • The context and
         the usual issues we face
       • Some real-life examples of
         Domain-Specific Languages
       • Groovy’s DSL capabilities
       • Integrating a DSL
         in your application
       • Considerations to remember
         when designing your own DSL


                               65
Start small, with key concepts
Beware overengineering!
Grow your language progressively
Get your hands dirty
Play with the end-users
Let your DSL fly,
it’s not yours,
it’s theirs!
Tight feedback loop
Iterative process
Stay humble.
You can’t get it right the first time.
Don’t design alone at your desk
Involve the end users from the start
Playing it safe
in a sandbox
Various levels of               sandboxing



• Groovy supports the usual Java Security Managers

• Use metaprogramming tricks to prevent calling /
  instantiating certain classes

• Create a special GroovyClassLoader AST code
  visitor to filter only the nodes of the AST you want
  to keep
  – ArithmeticShell in Groovy’s samples



                                               73
Test, test, test!



• Don’t just test for nominal cases
  – Explicitly test for errors!


• Ensure end-users get meaningful error
  messages




                                          74
nd a
Ag e

       • Summary

       • Questions & Answers




                               75
Summary

• Groovy’s a great fit for Domain-Specific Languages
  – Malleable & flexible syntax
  – Full object-orientation


• Metaprogramming capabilities
  – Runtime metaprogramming
  – Compile-time metaprogramming


• Groovy’s very often used for mission-critical DSLs




                                              76
?
I kan haz my cheezburgr naw?
 Or do ya reely haz keshtionz?
Appendix




           78
• http://www.flickr.com/photos/wheatfields/420088151/sizes/l/
• http://www.flickr.com/photos/therefromhere/518053737/sizes/l/
• http://www.flickr.com/photos/romainguy/230416692/sizes/l/
• http://www.flickr.com/photos/addictive_picasso/2874279971/sizes/l/
• http://www.flickr.com/photos/huangjiahui/3127634297/sizes/l/
• http://www.flickr.com/photos/25831000@N08/3064515804/sizes/o/
• http://www.flickr.com/photos/lanier67/3147696168/sizes/l/
• http://www.flickr.com/photos/ktb/4916063/sizes/o/
• http://www.flickr.com/photos/nathonline/918128338/sizes/l/
• http://www.flickr.com/photos/kevinsteele/39300193/sizes/l/
• http://commons.wikimedia.org/wiki/File:Brueghel-tower-of-babel.jpg
• http://commons.wikimedia.org/wiki/File:Platypus.jpg
• http://www.flickr.com/photos/joaomoura/2317171808/sizes/l/
• http://www.flickr.com/photos/wiccked/132687067/
• http://www.flickr.com/photos/xcbiker/386876546/sizes/l/
• http://www.flickr.com/photos/pietel/152403711/sizes/o/


                                                                       79
• http://www.flickr.com/photos/forezt/192554677/sizes/o/
• http://keremkosaner.files.wordpress.com/2008/04/
  softwaredevelopment.gif
• http://www.jouy.inra.fr
• http://www.flickr.com/photos/ejpphoto/408101818/sizes/o/
• http://www.flickr.com/photos/solaro/2127576608/sizes/l/
• http://www.flickr.com/photos/biggreymare/2846899405/sizes/l/
• http://www.flickr.com/photos/timsamoff/252370986/sizes/l/
• http://www.flickr.com/photos/29738009@N08/2975466425/sizes/l/
• http://www.flickr.com/photos/howie_berlin/180121635/sizes/o/
• http://www.flickr.com/photos/yogi/1281980605/sizes/l/
• http://www.flickr.com/photos/dorseygraphics/1336468896/sizes/l/




                                                                    80

Más contenido relacionado

La actualidad más candente

Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015Charles Nutter
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Ken Kousen
 
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
 
Indic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndicThreads
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеSergey Platonov
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Guillaume Laforge
 
Make Testing Groovy
Make Testing GroovyMake Testing Groovy
Make Testing GroovyPaul King
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinKai Koenig
 
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
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot WorldSchalk Cronjé
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 

La actualidad más candente (20)

Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013
 
Groovy 2.0 webinar
Groovy 2.0 webinarGroovy 2.0 webinar
Groovy 2.0 webinar
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
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
 
Indic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvmIndic threads pune12-polyglot & functional programming on jvm
Indic threads pune12-polyglot & functional programming on jvm
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 
Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007Groovy Update - JavaPolis 2007
Groovy Update - JavaPolis 2007
 
Make Testing Groovy
Make Testing GroovyMake Testing Groovy
Make Testing Groovy
 
Google Dart
Google DartGoogle Dart
Google Dart
 
Little Helpers for Android Development with Kotlin
Little Helpers for Android Development with KotlinLittle Helpers for Android Development with Kotlin
Little Helpers for Android Development with Kotlin
 
Return of c++
Return of c++Return of c++
Return of c++
 
Dart
DartDart
Dart
 
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
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 

Destacado

Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShift
Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShiftUltimate DevOps - Jenkins Enterprise & Red Hat OpenShift
Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShiftAndy Pemberton
 
Jenkins Pipeline - Seville JAM
Jenkins Pipeline - Seville JAMJenkins Pipeline - Seville JAM
Jenkins Pipeline - Seville JAMamunizmartin
 
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and MaintenanceJUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and MaintenanceCloudBees
 
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...Lucidworks
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Longericlongtx
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)CloudBees
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache GroovyBuilding an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache Groovyjgcloudbees
 
CI and CD with Jenkins
CI and CD with JenkinsCI and CD with Jenkins
CI and CD with JenkinsMartin Málek
 
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSBamdad Dashtban
 

Destacado (10)

Groovy DSL
Groovy DSLGroovy DSL
Groovy DSL
 
Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShift
Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShiftUltimate DevOps - Jenkins Enterprise & Red Hat OpenShift
Ultimate DevOps - Jenkins Enterprise & Red Hat OpenShift
 
Jenkins Pipeline - Seville JAM
Jenkins Pipeline - Seville JAMJenkins Pipeline - Seville JAM
Jenkins Pipeline - Seville JAM
 
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and MaintenanceJUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
 
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...
Building a Solr Continuous Delivery Pipeline with Jenkins: Presented by James...
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
 
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache GroovyBuilding an Extensible, Resumable DSL on Top of Apache Groovy
Building an Extensible, Resumable DSL on Top of Apache Groovy
 
CI and CD with Jenkins
CI and CD with JenkinsCI and CD with Jenkins
CI and CD with Jenkins
 
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWSAutomated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
Automated Deployment Pipeline using Jenkins, Puppet, Mcollective and AWS
 

Similar a GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge

Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyGuillaume Laforge
 
GR8Conf 2011: STS DSL Support
GR8Conf 2011: STS DSL SupportGR8Conf 2011: STS DSL Support
GR8Conf 2011: STS DSL SupportGR8Conf
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the CloudJim Driscoll
 
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
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020rodburns
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentAkihiro Ikezoe
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studypeter_ibuildings
 
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
 
Go: What's Different ?
Go: What's Different ?Go: What's Different ?
Go: What's Different ?Tarun Vashisth
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
Cloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onCloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onPatrick Chanezon
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mSteve Elliott
 
Idiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSIdiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSAndrea Saltarello
 
Infrastructure for cloud_computing
Infrastructure for cloud_computingInfrastructure for cloud_computing
Infrastructure for cloud_computingJULIO GONZALEZ SANZ
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQLDon Demcsak
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovySeeyoung Chang
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part IIEugene Lazutkin
 

Similar a GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge (20)

Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in Groovy
 
GR8Conf 2011: STS DSL Support
GR8Conf 2011: STS DSL SupportGR8Conf 2011: STS DSL Support
GR8Conf 2011: STS DSL Support
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
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
 
Pulsar
PulsarPulsar
Pulsar
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
cadec-2017-golang
cadec-2017-golangcadec-2017-golang
cadec-2017-golang
 
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
SC20 SYCL and C++ Birds of a Feather 19th Nov 2020
 
Incremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend DevelopmentIncremental DOM and Recent Trend of Frontend Development
Incremental DOM and Recent Trend of Frontend Development
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-study
 
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
 
Go: What's Different ?
Go: What's Different ?Go: What's Different ?
Go: What's Different ?
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
Cloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made onCloud is such stuff as dreams are made on
Cloud is such stuff as dreams are made on
 
Java jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3mJava jdk-update-nov10-sde-v3m
Java jdk-update-nov10-sde-v3m
 
Idiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRSIdiomatic Domain Driven Design: implementing CQRS
Idiomatic Domain Driven Design: implementing CQRS
 
Infrastructure for cloud_computing
Infrastructure for cloud_computingInfrastructure for cloud_computing
Infrastructure for cloud_computing
 
Intro to Big Data and NoSQL
Intro to Big Data and NoSQLIntro to Big Data and NoSQL
Intro to Big Data and NoSQL
 
Dsl로 만나는 groovy
Dsl로 만나는 groovyDsl로 만나는 groovy
Dsl로 만나는 groovy
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 

Más de GR8Conf

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle GR8Conf
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerGR8Conf
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyGR8Conf
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with GebGR8Conf
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidGR8Conf
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the DocksGR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsGR8Conf
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applicationsGR8Conf
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3GR8Conf
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGR8Conf
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEBGR8Conf
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCGR8Conf
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshopGR8Conf
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spockGR8Conf
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedGR8Conf
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGR8Conf
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and GroovyGR8Conf
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineGR8Conf
 

Más de GR8Conf (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developer
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with Geb
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and Android
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the Docks
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloud
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPC
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshop
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spock
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem Revisited
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examples
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 

Último

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge

  • 1.
  • 2. Practical Domain-Specific Languages with Groovy All the techniques to create your own DSLs Guillaume Laforge Head of Groovy Development
  • 3. Guillaume Laforge • Groovy Project Manager • JSR-241 Spec Lead • Head of Groovy Development at SpringSource • Initiator of the Grails framework • Co-author of Groovy in Action • Speaker: JavaOne, QCon, JavaZone, Sun TechDays, Devoxx, The Spring Experience, JAX, Dynamic Language World, IJTC, and more... 3
  • 4. A few words about Groovy • Groovy is a dynamic language for the JVM – with a Meta Object Protocol – compiles directly to bytecode, seamless Java interop • Open Source ASL 2 project hosted at Codehaus • Relaxed grammar derived from Java 5 – + borrowed good ideas from Ruby, Python, Smalltalk • Fast... for a dynlang on the JVM • Closures, properties, optional typing, BigDecimal by default, nice wrapper APIs, and more... 4
  • 5. nd a Ag e • The context and the usual issues we face • Some real-life examples of Domain-Specific Languages • Groovy’s DSL capabilities • Integrating a DSL in your application • Considerations to remember when designing your own DSL 5
  • 7. Subject Matter Experts, Business analysts...
  • 8. Developer producing LOLCODE HAI CAN HAS STDIO? I HAS A VAR IM IN YR LOOP UP VAR!!1 VISIBLE VAR IZ VAR BIGGER THAN 10? KTHXBYE IM OUTTA YR LOOP KTHXBYE
  • 10. And in the end... ...nobody understands each other
  • 12. DSL: a potential solution? • Use a more expressive language than a general purpose one • Share a common metaphore of understanding between developers and subject matter experts • Have domain experts help with the design of the business logic of an application • Avoid cluttering business code with too much boilerplate technical code • Cleanly separate business logic from application code • Let business rules have their own lifecycle 12
  • 19. nd a Ag e • The context and the usual issues we face • Some real-life examples of Domain-Specific Languages • Groovy’s DSL capabilities • Integrating a DSL in your application • Considerations to remember when designing your own DSL 15
  • 20. A collection of DSLs • In our everyday life, we’re surrounded by DSLs – Technical dialects – Notations – Business languages 16
  • 22. SQL
  • 24. Notations 20
  • 25. 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6
  • 26. L2 U F-1 B L2 F B -1 U L2
  • 29. Real-life Groovy examples • Anti-malaria drug resistance simulation • Human Resources employee skills representation • Insurance policies risk calculation engine • Loan acceptance rules engine for a financial platform • Mathematica-like lingua for nuclear safety simulations • Market data feeds evolution scenarios • and more... 25
  • 30. nd a Ag e • The context and the usual issues we face • Some real-life examples of Domain-Specific Languages • Groovy’s DSL capabilities • Integrating a DSL in your application • Considerations to remember when designing your own DSL 26
  • 31. A flexible & malleable syntax • No need to write full-blown classes, use scripts • Optional typing (def) – in scripts, you can even omit the def keyword • Native syntax constructs • Parentheses & semi-colons are optional • Named arguments • BigDecimal by default for decimal numbers • Closures for custom control structures • Operator overloading 27
  • 32. Scripts vs classes • Hide all the boilerplate technical code – an end-user doesn’t need to know about classes – public class Rule { public static void main(String[] args) { System.out.println(“Hello”); } } – println “Hello” 28
  • 33. Optional typing • No need to bother with types or even generics – unless you want to! • Imagine an interest rate lookup table method returning some generified type: –Rate<LoanType, Duration, BigDecimal>[] lookupTable() { ... } def table = lookupTable() • No need to repeat the horrible generics type info! 29
  • 34. Native syntax constructs • Lists – [Monday, Tuesday, Wednesday] • Maps – [CA: ‘California’, TX: ‘Texas’] • Ranges – def bizDays = Monday..Friday – def allowedAge = 18..65 – You can create your own custom ranges 30
  • 35. Optional parens & semis • Make statements and expressions look more like natural languages – move(left); – move left 31
  • 36. Named arguments • In Groovy you can mix named and unnamed arguments for method parameters – named params are actually put in a map parameter – plus optional parens & semis • take 1.pill, of: Chloroquinine, after: 6.hours • Corresponds to a method signature like: –def take(Map m, MedicineQuantity mq) 32
  • 37. BigDecimal by default • Main reason why financial institutions often decide to use Groovy for their business rules! – Although these days rounding issues are overrated! • Java vs Groovy for a simple interpolation equation • BigDecimal uMinusv = c.subtract(a); BigDecimal vMinusl = b.subtract(c); BigDecimal uMinusl = a.subtract(b); return e.multiply(uMinusv) .add(d.multiply(vMinusl)) .divide(uMinusl, 10, BigDecimal.ROUND_HALF_UP); • (d * (b - c) + e * (c - a)) / (a - b) 33
  • 38. Custom control structures Thanks to closures • When closures are last, they can be put “out” of the parentheses surrounding parameters • unless (account.balance > 100.euros, { account.debit 100.euros }) • unless (account.balance > 100.euros) { account.debit 100.euros } • Signature def unless(boolean b, Closure c) 34
  • 39. Operator overloading a + b a.plus(b) a - b a.minus(b) • Currency amounts a * b a.multiply(b) – 15.euros + 10.dollars a / b a.divide(b) a % b a.modulo(b) • Distance handling a ** b a.power(b) – 10.kilometers - 10.meters a | b a.or(b) a & b a.and(b) • Workflow, concurrency a ^ b a.xor(b) – taskA | taskB & taskC a[b] a.getAt(b) a << b a.leftShift(b) • Credit an account a >> b a.rightShift(b) – account << 10.dollars +a a.positive() account += 10.dollars -a a.negative() account.credit 10.dollars ~a a.bitwiseNegate() 35
  • 40. Groovy’s dynamic heart: The MOP! MetaObject Protocol
  • 41. Groovy’s MOP • All the accesses to methods, properties, constructors, operators, etc. can be intercepted thanks to the MOP • While Java’s behavior is hard-wired at compile- time in the class • Groovy’s runtime behavior is adaptable at runtime through the metaclass. • Different hooks for changing the runtime behavior – GroovyObject, custom MetaClass implementation, categories, ExpandoMetaClass 37
  • 42. GroovyObject • All instances of classes created in Groovy implement the GroovyObject interface: –getProperty(String name) –setProperty(String name, Object value) –invokeMethod(String name, Object[] params) –getMetaClass() –setMetaClass(MetaClass mc) • A GO can have “pretended” methods and properties 38
  • 43. MetaClass • The core of Groovy’s MOP system –invokeConstructor() –invokeMethod() and invokeStaticMethod() –invokeMissingMethod() –getProperty() and setProperty() –getAttribute() and setAttribute() –respondsTo() and hasProperty() • MetaClasses can change the behavior of existing third-party classes — even from the JDK 39
  • 44. ExpandoMetaClass • A DSL for MetaClasses! • MoneyAmount.metaClass.constructor = { ... } Number.metaClass.getDollars = { ... } Distance.metaClass.toMeters = { ... } Distance.metaClass.static.create = { ... } • To avoid repetition of Type.metaClass, you can pass a closure to metaClass { ... } • The delegate variable in closure represents the current instance, and it the default parameter 40
  • 46. The Groovy MarkupBuilder • def mkp = new MarkupBuilder() mkp.html { head { title “Groovy in Action” } body { div(width: ‘100’) { p(class: ‘para) { span “Best book ever!” } } } } 42
  • 47. A builder for HR • softskills { ideas { capture 2 formulate 3 } ... } knowhow { languages { java 4 groovy 5 } ... } 43
  • 48. A builder for HR • softskills { ideas { capture 2 formulate 3 } ... } knowhow { languages { java 4 groovy 5 } ... } 43
  • 49. Builders • Builders are... – a mechanism for creating any tree-structered graph – the realization of the GoF builder pattern at the syntax level in Groovy – simply a clever use of chained method invocation, closures, parentheses omission, and use of the GroovyObject methods • Existing builders – XML, Object graph, Swing, Ant, JMX, and more... 44
  • 50. The clever trick • GroovyObject#invokeMethod() is used to catch all non-existing method calls in the context of the builder • The nesting of closures visually shows the level of nesting / depth in the tree • builder.m1(attr1:1, attr2:2, { builder.m2(..., {...}) } becomes equivalent to builder.m1(attr1:1, attr2:2) { m2(...) {...} } thanks to parens omission 45
  • 51. Adding properties to numbers • Three possible approaches – create a Category •a category is a kind of decorator for default MCs – create a custom MetaClass •a full-blown MC class to implement and to set on the POGO instance – use ExpandoMetaClass •friendlier DSL approach but with a catch 46
  • 52. With a Category • class DistanceCategory { static Distance getMeters(Integer self) { new Distance(self, Unit.METERS) } } use(DistanceCategory) { 100.meters } • Interesting scope: thread-bound & lexical • But doesn’t work across the hierarchy of classes – ie. subclasses won’t benefit from the new property 47
  • 53. With an ExpandoMetaClass • Number.metaClass.getMeters = {-> new Distance(delegate, Unit.METERS) } 100.meters • Works for the class hierarchy for POJOs, and a flag exists to make it work for POGOs too • But the catch is it’s really a global change, so beware EMC enhancements collisions 48
  • 54. Compile-time metaprogramming • Groovy 1.6 introduced AST Transformations • Compile-time == No runtime performance penalty! Transformation 49
  • 55. AST Transformations • Two kinds of transformations – Global transformations •applicable to all compilation units – Local transformations •applicable to marked program elements •using specific marker annotations 50
  • 56. Example #1: @Singleton • Let’s revisit this evil (anti-)pattern ! public class Evil { public static final Evil instance = new Evil (); private Evil () {} Evil getInstance() { return instance; } } • In Groovy ! @Singleton class Evil {} • Also a “lazy” version ! @Singleton(lazy = true) class Evil {} 51
  • 57. Example #2: @Delegate Not just for managers! • You can delegate to fields of your classes – class Employee { def doTheWork() { “done” } } class Manager { @Delegate Employee slave = new Employee() } def god = new Manager() assert god.doTheWork() == “done” • Damn manager who will get all the praise... 52
  • 58. Global transformations • Implement ASTTransformation • Annotate the transfo specifying a compilation phase • @GroovyASTTransformation(phase=CompilePhase.CONVERSION) public class MyTransformation implements ASTTransformation { public void visit(ASTNode[] nodes, SourceUnit unit) { ... } } • For discovery, create the file META-INF/services/ org.codehaus.groovy.transform.ASTTransformation • Add the fully qualified name of the class in that file 53
  • 59. Local transformations • Same approach as Globale transformations • But you don’t need the META-INF file • Instead create an annotation to specify on which element the transformation should apply • @Retention(RetentionPolicy.SOURCE) @Target([ElementType.METHOD]) @GroovyASTTransformationClass( ["fqn.MyTransformation"]) public @interface WithLogging {...} 54
  • 60. Example: the Spock framework • Changing the semantics of the original code • But keeping a valid Groovy syntax • @Speck class HelloSpock { def "can you figure out what I'm up to?"() { expect: name.size() == size where: name << ["Kirk", "Spock", "Scotty"] size << [4, 5, 6] } } 55
  • 61. nd a Ag e • The context and the usual issues we face • Some real-life examples of Domain-Specific Languages • Groovy’s DSL capabilities • Integrating a DSL in your application • Considerations to remember when designing your own DSL 56
  • 62. Various integration mechanisms • Java 6’s javax.script.* APIs (aka JSR-223) • Spring’s language namespace • Groovy’s own mechanisms • But a key idea is to externalize those DSL programs – DSL programs can have their own lifecycle – no need to redeploy an application because of a rule change – business people won’t see the technical code 57
  • 63. Java 6’s javax.script.* API • Groovy 1.6 provides its own implementation of the javax.script.* API • ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine engine = mgr.getEngineByName(“Groovy”); String result = (String)engine.eval(“2+3”); 58
  • 64. Spring’s lang namespace • POGOs (Plain Old Groovy Objects) can be pre- compiled as any POJO and used interchangeably with POJOs in a Spring application • But Groovy scripts & classes can be loaded at runtime through the <lang:groovy/> namespace and tag • Reloadable on change • Customizable through a custom MetaClass • <lang:groovy id="events" script-source="classpath:dsl/ eventsChart.groovy" customizer-ref="eventsMetaClass" /> 59
  • 65. Groovy’s own mechanisms • Eval – for evaluating simple expressions • GroovyShell – for more complex scripts and DSLs • GroovyClassLoader – the most powerful mechanism 60
  • 66. Eval • Simple mechanism to evaluate math-like formulas • Eval.me ( ‘3*4’) Eval.x (1, ‘3*x + 4’) Eval.xy (1, 2, ‘x + y’) Eval.xyz(1, 2, 3, ‘x * y - z’) 61
  • 67. GroovyShell • A Binding provides a context of execution – can implement lazy evaluation if needed • A base script class can be specified • def binding = new Binding() binding.mass = 22.3 binding.velocity = 10.6 def shell = new GroovyShell(binding) shell.evaluate(“mass * velocity ** 2 / 2”) 62
  • 68. GroovyClassLoader • Most powerful mechanism – could also visit or change the AST – scripts & classes can be loaded from elsewhere – more control on compilation • GroovyClassLoader gcl = new GroovyClassLoader(); Class clazz = gcl.parseClass( new File(“f.groovy”)); GroovyObject instance = (GroovyObject)clazz.newInstance(); instance.setMetaClass(customMC); 63
  • 69. Externalize business rules • Although Groovy DSLs can be embedded in normal Groovy classes, you should externalize them • Store them elsewhere – in a database, an XML file, etc. • Benefits – Business rules are not entangled in technical application code – Business rules can have their own lifecycle, without requiring application redeployments 64
  • 70. nd a Ag e • The context and the usual issues we face • Some real-life examples of Domain-Specific Languages • Groovy’s DSL capabilities • Integrating a DSL in your application • Considerations to remember when designing your own DSL 65
  • 71. Start small, with key concepts Beware overengineering!
  • 72. Grow your language progressively
  • 73. Get your hands dirty Play with the end-users
  • 74. Let your DSL fly, it’s not yours, it’s theirs!
  • 76. Stay humble. You can’t get it right the first time. Don’t design alone at your desk Involve the end users from the start
  • 77. Playing it safe in a sandbox
  • 78. Various levels of sandboxing • Groovy supports the usual Java Security Managers • Use metaprogramming tricks to prevent calling / instantiating certain classes • Create a special GroovyClassLoader AST code visitor to filter only the nodes of the AST you want to keep – ArithmeticShell in Groovy’s samples 73
  • 79. Test, test, test! • Don’t just test for nominal cases – Explicitly test for errors! • Ensure end-users get meaningful error messages 74
  • 80. nd a Ag e • Summary • Questions & Answers 75
  • 81. Summary • Groovy’s a great fit for Domain-Specific Languages – Malleable & flexible syntax – Full object-orientation • Metaprogramming capabilities – Runtime metaprogramming – Compile-time metaprogramming • Groovy’s very often used for mission-critical DSLs 76
  • 82. ? I kan haz my cheezburgr naw? Or do ya reely haz keshtionz?
  • 83. Appendix 78
  • 84. • http://www.flickr.com/photos/wheatfields/420088151/sizes/l/ • http://www.flickr.com/photos/therefromhere/518053737/sizes/l/ • http://www.flickr.com/photos/romainguy/230416692/sizes/l/ • http://www.flickr.com/photos/addictive_picasso/2874279971/sizes/l/ • http://www.flickr.com/photos/huangjiahui/3127634297/sizes/l/ • http://www.flickr.com/photos/25831000@N08/3064515804/sizes/o/ • http://www.flickr.com/photos/lanier67/3147696168/sizes/l/ • http://www.flickr.com/photos/ktb/4916063/sizes/o/ • http://www.flickr.com/photos/nathonline/918128338/sizes/l/ • http://www.flickr.com/photos/kevinsteele/39300193/sizes/l/ • http://commons.wikimedia.org/wiki/File:Brueghel-tower-of-babel.jpg • http://commons.wikimedia.org/wiki/File:Platypus.jpg • http://www.flickr.com/photos/joaomoura/2317171808/sizes/l/ • http://www.flickr.com/photos/wiccked/132687067/ • http://www.flickr.com/photos/xcbiker/386876546/sizes/l/ • http://www.flickr.com/photos/pietel/152403711/sizes/o/ 79
  • 85. • http://www.flickr.com/photos/forezt/192554677/sizes/o/ • http://keremkosaner.files.wordpress.com/2008/04/ softwaredevelopment.gif • http://www.jouy.inra.fr • http://www.flickr.com/photos/ejpphoto/408101818/sizes/o/ • http://www.flickr.com/photos/solaro/2127576608/sizes/l/ • http://www.flickr.com/photos/biggreymare/2846899405/sizes/l/ • http://www.flickr.com/photos/timsamoff/252370986/sizes/l/ • http://www.flickr.com/photos/29738009@N08/2975466425/sizes/l/ • http://www.flickr.com/photos/howie_berlin/180121635/sizes/o/ • http://www.flickr.com/photos/yogi/1281980605/sizes/l/ • http://www.flickr.com/photos/dorseygraphics/1336468896/sizes/l/ 80