SlideShare a Scribd company logo
1 of 82
Download to read offline
Design Your Own
Domain-Specific
Language
Guillaume Laforge - SpringSource
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, SpringOne, JAX,
  Dynamic Language World, IJTC, and more...




                                                                                               2
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Introduction




         SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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...




                                                                                            10
           SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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


                                                                                                  11
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (1)




                                                                                             12
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (1)




                                                                                             12
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (1)




                                                                                             20%




                                                                                             12
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (2)




                                                                                             13
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (2)




                                                                                             13
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Towards more readibility (2)




                                                                                             80%



                                                                                               13
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
A collection of DSLs


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

  – Technical dialects

  – Notations

  – Business languages




                                                                                                   14
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Technical dialects




                                                                                             15
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
SQL
^[w-.]+@([w-]){2,4}$




                                                                                         17
        SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Notations




                                                                                             18
            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
1. e4 e5
2. Nf3 Nc6
3. Bb5 a6
L2 U F-1 B L2 F B -1 U L2
Visual!
Business languages




                                                                                            22
           SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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...


                                                                                                 23
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The techniques




         SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Three levels of techniques



   Flexible &                                     Meta-                                                             AST
malleable syntax                              programming                                                     transformations
• scripts                                  • POGO                                                             • AST traversal
• optional typing                          • categories                                                       • local transformations
• native syntax constructs                 • builders                                                         • global transformations
• parens / semi ommission                  • custom MetaClasses                                               • hooks into Antlr
• BigDecimal                               • ExpandoMetaClass
• operator overloading
• closures




                                                                                                                           25
                             SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Flexible & malleable




           SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Optional parens & semis

• Make statements and expressions
  look more like natural languages




  – move(left);




  – move left



                                                                                                   31
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                    SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Operator overloading

a + b
a - b
         a.plus(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)
a[b]     a.getAt(b)
                                                        – taskA | taskB & taskC
a << b   a.leftShift(b)
a >> b   a.rightShift(b)                         • Credit an account
+a       a.unaryPlus()                                  – account << 10.dollars
-a       a.unaryMinus()                                   account += 10.dollars
~a       a.bitwiseNegate()                                account.credit 10.dollars

                                                                                                          35
                         SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Meta-programming




        SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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




                                                                                                 38
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
GroovyObject

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

  –get/setProperty(String name)
  –invokeMethod(
       String name, Object[] params)
  –propertyMissing(String name)
  –methodMissing(
       String name, Object[] params)
  –get/setMetaClass(MetaClass mc)

• A GO can have “pretended” methods and properties

                                                                                                 39
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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


                                                                                                40
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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

                                                                                                 41
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The Builder pattern
A builder for HR

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




                                                                                                 43
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
A builder for HR

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




                                                                                                 43
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                    SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                    SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
With a Category

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

 use(DistanceCategory) {
     100.meters
 }

• Interesting scope: thread-bound & lexical
• Have to surround with “use”
  – but there are ways to hide it



                                                                                                   47
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Compile-time
metaprogramming




        SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Compile-time
metaprogramming

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




                                      Transformation




                                                                                               50
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
AST Transformations

• Two kinds of transformations


  – Global transformations
    •applicable to all compilation units


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




                                                                                                   51
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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



                                                                                                     52
                    SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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 {...}




                                                                                                53
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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]
     }
 }
• Check out http://www.spockframework.org
•
                                                                                                 54
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Integrating DSLs




         SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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




                                                                                                  56
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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”);




                                                                                                57
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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" />


                                                                                                 58
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Groovy’s own mechanisms

• Eval
  – for evaluating simple expressions


• GroovyShell
  – for more complex scripts and DSLs


• GroovyClassLoader
  – the most powerful mechanism




                                                                                                  59
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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’)




                                                                                                60
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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”)



                                                                                                  61
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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);



                                                                                                  62
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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


                                                                                                   63
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
A few considerations




           SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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 /
  instanciating 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



                                                                                                  72
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Test, test, test!


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


• Ensure end-users get meaninful error messages




                                                                                                    73
                   SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
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




                                                                                                   74
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Q&A




              Laforge elopment
Guill aume vy Dev
        o f Groo are.com
Head @vmw
 g laforge



            SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
?
I kan haz my cheezburgr naw?
 Or do ya reely haz keshtionz?
Pictures Used in this
Presentation
•   http://www.flickr.com/photos/wheatfields/420088151/                           •    http://www.flickr.com/photos/timsamoff/252370986/
    sizes/l/                                                                           sizes/l/
•   http://www.flickr.com/photos/therefromhere/518053737/                         •    http://www.flickr.com/photos/
    sizes/l/                                                                           29738009@N08/2975466425/sizes/l/
•   http://www.flickr.com/photos/romainguy/230416692/                             •    http://www.flickr.com/photos/howie_berlin/180121635/
    sizes/l/                                                                           sizes/o/
•   http://www.flickr.com/photos/addictive_picasso/                               •    http://www.flickr.com/photos/yogi/1281980605/sizes/l/
    2874279971/sizes/l/
                                                                                  •    http://www.flickr.com/photos/dorseygraphics/
•   http://www.flickr.com/photos/huangjiahui/3127634297/                               1336468896/sizes/l/
    sizes/l/
                                                                                  •    http://www.flickr.com/photos/xcbiker/386876546/sizes/l/
•   http://www.flickr.com/photos/
                                                                                  •    http://www.flickr.com/photos/pietel/152403711/sizes/o/
    25831000@N08/3064515804/sizes/o/
                                                                                  •    http://www.flickr.com/photos/forezt/192554677/sizes/o/
•   http://www.flickr.com/photos/lanier67/3147696168/
    sizes/l/                                                                      •    http://keremkosaner.files.wordpress.com/2008/04/
                                                                                       softwaredevelopment.gif
•   http://www.flickr.com/photos/ktb/4916063/sizes/o/
                                                                                  •    http://www.jouy.inra.fr
•   http://www.flickr.com/photos/nathonline/918128338/
    sizes/l/                                                                      •    http://www.flickr.com/photos/ejpphoto/408101818/
                                                                                       sizes/o/
•   http://www.flickr.com/photos/kevinsteele/39300193/
    sizes/l/                                                                      •    http://www.flickr.com/photos/solaro/2127576608/sizes/
                                                                                       l/
•   http://commons.wikimedia.org/wiki/File:Brueghel-tower-
    of-babel.jpg                                                                  •    http://www.flickr.com/photos/biggreymare/2846899405/
                                                                                       sizes/l/
•   http://commons.wikimedia.org/wiki/File:Platypus.jpg
•   http://www.flickr.com/photos/joaomoura/2317171808/
    sizes/l/
•   http://www.flickr.com/photos/wiccked/132687067/




                                     SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

More Related Content

Viewers also liked

Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Guillaume Laforge
 
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
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGuillaume Laforge
 
Session inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group ParisSession inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group ParisGuillaume Laforge
 
Groovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGroovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Guillaume Laforge
 
Defining DSL (Domain Specific Language) using Ruby
Defining DSL (Domain Specific Language) using RubyDefining DSL (Domain Specific Language) using Ruby
Defining DSL (Domain Specific Language) using RubyNetguru
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific LanguagesJavier Canovas
 
Configuration As Code - Adoption of the Job DSL Plugin at Netflix
Configuration As Code - Adoption of the Job DSL Plugin at NetflixConfiguration As Code - Adoption of the Job DSL Plugin at Netflix
Configuration As Code - Adoption of the Job DSL Plugin at NetflixJustin Ryan
 

Viewers also liked (15)

Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
Groovy DSLs, from Beginner to Expert - Guillaume Laforge and Paul King - Spri...
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
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
 
Gaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume LaforgeGaelyk - JFokus 2011 - Guillaume Laforge
Gaelyk - JFokus 2011 - Guillaume Laforge
 
Session inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group ParisSession inaugurale du Groovy User Group Paris
Session inaugurale du Groovy User Group Paris
 
Groovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume LaforgeGroovy update - S2GForum London 2011 - Guillaume Laforge
Groovy update - S2GForum London 2011 - Guillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012
 
Defining DSL (Domain Specific Language) using Ruby
Defining DSL (Domain Specific Language) using RubyDefining DSL (Domain Specific Language) using Ruby
Defining DSL (Domain Specific Language) using Ruby
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Domain Specific Languages
Domain Specific LanguagesDomain Specific Languages
Domain Specific Languages
 
Groovy 2 and beyond
Groovy 2 and beyondGroovy 2 and beyond
Groovy 2 and beyond
 
Groovy DSL
Groovy DSLGroovy DSL
Groovy DSL
 
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
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Configuration As Code - Adoption of the Job DSL Plugin at Netflix
Configuration As Code - Adoption of the Job DSL Plugin at NetflixConfiguration As Code - Adoption of the Job DSL Plugin at Netflix
Configuration As Code - Adoption of the Job DSL Plugin at Netflix
 

Similar to Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at SpringOne/2GX 2009

Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Guillaume Laforge
 
LAS16-108: JerryScript and other scripting languages for IoT
LAS16-108: JerryScript and other scripting languages for IoTLAS16-108: JerryScript and other scripting languages for IoT
LAS16-108: JerryScript and other scripting languages for IoTLinaro
 
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...Intel® Software
 
Under the Hood of the Testarossa JIT Compiler
Under the Hood of the Testarossa JIT CompilerUnder the Hood of the Testarossa JIT Compiler
Under the Hood of the Testarossa JIT CompilerMark Stoodley
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll buildMark Stoodley
 
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad Assis
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad AssisKubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad Assis
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad AssisAgileSparks
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowKathy Brown
 
Odessa .NET User Group - 10.11.2011 - Applied Code Generation
Odessa .NET User Group - 10.11.2011 - Applied Code Generation Odessa .NET User Group - 10.11.2011 - Applied Code Generation
Odessa .NET User Group - 10.11.2011 - Applied Code Generation Dmytro Mindra
 
z/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020Az/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020AMarna Walle
 
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...AdaLabs
 
Go programming language
Go programming languageGo programming language
Go programming languageAppstud
 
Db2 developer ecosystem
Db2 developer ecosystemDb2 developer ecosystem
Db2 developer ecosystemModusOptimum
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIOpersys inc.
 
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Fabrice Bernhard
 
Protractor: The Hacker way (NG-MY 2019)
Protractor: The Hacker way (NG-MY 2019)Protractor: The Hacker way (NG-MY 2019)
Protractor: The Hacker way (NG-MY 2019)Will Huang
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database RefactoringAnton Keks
 

Similar to Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at SpringOne/2GX 2009 (20)

Linux on System z debugging with Valgrind
Linux on System z debugging with ValgrindLinux on System z debugging with Valgrind
Linux on System z debugging with Valgrind
 
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
Practical Groovy Domain-Specific Languages - Guillaume Laforge - Usi 2009
 
LAS16-108: JerryScript and other scripting languages for IoT
LAS16-108: JerryScript and other scripting languages for IoTLAS16-108: JerryScript and other scripting languages for IoT
LAS16-108: JerryScript and other scripting languages for IoT
 
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...
Unleashing Intel® Advanced Vector Extensions 512 (Intel® AVX-512) Inside the ...
 
Under the Hood of the Testarossa JIT Compiler
Under the Hood of the Testarossa JIT CompilerUnder the Hood of the Testarossa JIT Compiler
Under the Hood of the Testarossa JIT Compiler
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
 
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad Assis
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad AssisKubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad Assis
Kubernetes is Hard! Lessons Learned Taking Our Apps to Kubernetes by Eldad Assis
 
Android Development Tutorial V3
Android Development Tutorial   V3Android Development Tutorial   V3
Android Development Tutorial V3
 
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume LaforgeGR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
GR8Conf 2009: Practical Groovy DSL by Guillaume Laforge
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 
Odessa .NET User Group - 10.11.2011 - Applied Code Generation
Odessa .NET User Group - 10.11.2011 - Applied Code Generation Odessa .NET User Group - 10.11.2011 - Applied Code Generation
Odessa .NET User Group - 10.11.2011 - Applied Code Generation
 
z/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020Az/OS Small Enhancements - Edition 2020A
z/OS Small Enhancements - Edition 2020A
 
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...
LSM 2011 AdaLabs presentation slides: How to make my business opensource & vi...
 
Go programming language
Go programming languageGo programming language
Go programming language
 
Db2 developer ecosystem
Db2 developer ecosystemDb2 developer ecosystem
Db2 developer ecosystem
 
Intro To Starling Framework for ActionScript 3.0
Intro To Starling Framework for ActionScript 3.0Intro To Starling Framework for ActionScript 3.0
Intro To Starling Framework for ActionScript 3.0
 
Is Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VIIs Android the New Embedded Linux? at AnDevCon VI
Is Android the New Embedded Linux? at AnDevCon VI
 
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
Modernisation of legacy PHP applications using Symfony2 - PHP Northeast Confe...
 
Protractor: The Hacker way (NG-MY 2019)
Protractor: The Hacker way (NG-MY 2019)Protractor: The Hacker way (NG-MY 2019)
Protractor: The Hacker way (NG-MY 2019)
 
Database Refactoring
Database RefactoringDatabase Refactoring
Database Refactoring
 

More from Guillaume Laforge

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

More from Guillaume Laforge (20)

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

Recently uploaded

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 

Recently uploaded (20)

My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 

Designing Your Own Domain-Specific Language in Groovy by Guillaume Laforge at SpringOne/2GX 2009

  • 2. 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, SpringOne, JAX, Dynamic Language World, IJTC, and more... 2 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 3. Introduction SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 6. Subject Matter Experts, Business analysts...
  • 7. 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
  • 9. And in the end... ...nobody understands each other
  • 10. Expressing Requirements... 10 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 11 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 12. Towards more readibility (1) 12 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 13. Towards more readibility (1) 12 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 14. Towards more readibility (1) 20% 12 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 15. Towards more readibility (2) 13 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 16. Towards more readibility (2) 13 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 17. Towards more readibility (2) 80% 13 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 18. A collection of DSLs • In our everyday life, we’re surrounded by DSLs – Technical dialects – Notations – Business languages 14 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 19. Technical dialects 15 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 20. SQL
  • 21. ^[w-.]+@([w-]){2,4}$ 17 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 22. Notations 18 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 23. 1. e4 e5 2. Nf3 Nc6 3. Bb5 a6
  • 24. L2 U F-1 B L2 F B -1 U L2
  • 26. Business languages 22 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 27. 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... 23 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 28. The techniques SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 29. Three levels of techniques Flexible & Meta- AST malleable syntax programming transformations • scripts • POGO • AST traversal • optional typing • categories • local transformations • native syntax constructs • builders • global transformations • parens / semi ommission • custom MetaClasses • hooks into Antlr • BigDecimal • ExpandoMetaClass • operator overloading • closures 25 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 30. Flexible & malleable SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 35. Optional parens & semis • Make statements and expressions look more like natural languages – move(left); – move left 31 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 39. Operator overloading a + b a - b a.plus(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) a[b] a.getAt(b) – taskA | taskB & taskC a << b a.leftShift(b) a >> b a.rightShift(b) • Credit an account +a a.unaryPlus() – account << 10.dollars -a a.unaryMinus() account += 10.dollars ~a a.bitwiseNegate() account.credit 10.dollars 35 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 40. Meta-programming SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 41. Groovy’s dynamic heart: The MOP! MetaObject Protocol
  • 42. 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 38 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 43. GroovyObject • All instances of classes created in Groovy implement the GroovyObject interface: –get/setProperty(String name) –invokeMethod( String name, Object[] params) –propertyMissing(String name) –methodMissing( String name, Object[] params) –get/setMetaClass(MetaClass mc) • A GO can have “pretended” methods and properties 39 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 44. 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 40 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 45. 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 41 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 47. A builder for HR • softskills { ideas { capture 2 formulate 3 } ... } knowhow { languages { java 4 groovy 5 } ... } 43 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 48. A builder for HR • softskills { ideas { capture 2 formulate 3 } ... } knowhow { languages { java 4 groovy 5 } ... } 43 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 • Have to surround with “use” – but there are ways to hide it 47 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 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 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 54. Compile-time metaprogramming SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 55. Compile-time metaprogramming • Groovy 1.6 introduced AST Transformations • Compile-time == No runtime performance penalty! Transformation 50 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 56. AST Transformations • Two kinds of transformations – Global transformations •applicable to all compilation units – Local transformations •applicable to marked program elements •using specific marker annotations 51 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 57. 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 52 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 58. 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 {...} 53 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 59. 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] } } • Check out http://www.spockframework.org • 54 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 60. Integrating DSLs SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 61. 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 56 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 62. 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”); 57 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 63. 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" /> 58 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 64. Groovy’s own mechanisms • Eval – for evaluating simple expressions • GroovyShell – for more complex scripts and DSLs • GroovyClassLoader – the most powerful mechanism 59 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 65. 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’) 60 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 66. 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”) 61 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 67. 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); 62 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 68. 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 63 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 69. A few considerations SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 70. Start small, with key concepts Beware overengineering!
  • 71. Grow your language progressively
  • 72. Get your hands dirty Play with the end-users
  • 73. Let your DSL fly, it’s not yours, it’s theirs!
  • 75. 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
  • 76. Playing it safe in a sandbox
  • 77. Various levels of sandboxing • Groovy supports the usual Java Security Managers • Use metaprogramming tricks to prevent calling / instanciating 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 72 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 78. Test, test, test! • Don’t just test for nominal cases – Explicitely test for errors! • Ensure end-users get meaninful error messages 73 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 79. 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 74 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 80. Q&A Laforge elopment Guill aume vy Dev o f Groo are.com Head @vmw g laforge SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 81. ? I kan haz my cheezburgr naw? Or do ya reely haz keshtionz?
  • 82. Pictures Used in this Presentation • http://www.flickr.com/photos/wheatfields/420088151/ • http://www.flickr.com/photos/timsamoff/252370986/ sizes/l/ sizes/l/ • http://www.flickr.com/photos/therefromhere/518053737/ • http://www.flickr.com/photos/ sizes/l/ 29738009@N08/2975466425/sizes/l/ • http://www.flickr.com/photos/romainguy/230416692/ • http://www.flickr.com/photos/howie_berlin/180121635/ sizes/l/ sizes/o/ • http://www.flickr.com/photos/addictive_picasso/ • http://www.flickr.com/photos/yogi/1281980605/sizes/l/ 2874279971/sizes/l/ • http://www.flickr.com/photos/dorseygraphics/ • http://www.flickr.com/photos/huangjiahui/3127634297/ 1336468896/sizes/l/ sizes/l/ • http://www.flickr.com/photos/xcbiker/386876546/sizes/l/ • http://www.flickr.com/photos/ • http://www.flickr.com/photos/pietel/152403711/sizes/o/ 25831000@N08/3064515804/sizes/o/ • http://www.flickr.com/photos/forezt/192554677/sizes/o/ • http://www.flickr.com/photos/lanier67/3147696168/ sizes/l/ • http://keremkosaner.files.wordpress.com/2008/04/ softwaredevelopment.gif • http://www.flickr.com/photos/ktb/4916063/sizes/o/ • http://www.jouy.inra.fr • http://www.flickr.com/photos/nathonline/918128338/ sizes/l/ • http://www.flickr.com/photos/ejpphoto/408101818/ sizes/o/ • http://www.flickr.com/photos/kevinsteele/39300193/ sizes/l/ • http://www.flickr.com/photos/solaro/2127576608/sizes/ l/ • http://commons.wikimedia.org/wiki/File:Brueghel-tower- of-babel.jpg • http://www.flickr.com/photos/biggreymare/2846899405/ sizes/l/ • http://commons.wikimedia.org/wiki/File:Platypus.jpg • http://www.flickr.com/photos/joaomoura/2317171808/ sizes/l/ • http://www.flickr.com/photos/wiccked/132687067/ SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.