SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Real world
         DSL
 making technical
    and business
  people speaking
the same language
by Mario Fusco
Red Hat – Senior Software Engineer
mario.fusco@gmail.com
twitter: @mariofusco
What is a
Domain Specific Language?
               A
computer programming language
              of
    limited expressiveness
         focused on a
      particular domain
Why use a
Domain Specific Language?

2 principles driving toward
     DSL development
Communication is king




    The only purpose of
        languages,
  even programming ones
   IS COMMUNICATION
Written once, read many times
 Always code as
  if the person
     who will
  maintain your
code is a maniac
 serial killer that
  knows where
      you live
"Any fool can write code
that a computer can
understand.
Good programmers
write code that humans
can understand“
          Martin Fowler
Pros & Cons of DSLs
+ Expressivity  Communicativity
+ Conciseness
+ Readability  Maintainability  Modificability
+ Higher level of abstraction
+ Higher productivity in the specific problem domain

̶ Language design is hard
 ̶ Upfront cost
  ̶ Additional indirection layer  Performance concerns
   ̶ Lack of adeguate tool support
    ̶ Yet-another-language-to-learn syndrome
DSL taxonomy
 External DSL  a language having custom
  syntactical rules separate from the main language of
  the application it works with

 Internal DSL  a particular way of employing a
  general-purpose language, using only a small subset
  of the language's features

 Language workbench  a specialized IDE for
  defining and building DSL, usually in a visual way,
  used both to determine the structure of the DSL and
  to provide an editing environment for people using it
DSL Types Comparison
                + learning curve                     ̶ syntactic noise
                + cost of building                    ̶ needs to be recompiled
Internal DSL    + programmers familiarity               (if host language is static)
                + IDE support (autocompletion …)
                + composability
                + flexibility                        ̶ need to learn of grammars
                + readability                            and language parsing
External DSL    + clear separation between            ̶ boundary between DSL
                  business (DSL) and host language       and host language
                + helpful when business code is        ̶ easier to grow out of
                  written by a separate team             control
                  (domain experts)
Language        + visual                             ̶ tools immaturity
Workbench       + rapid development                   ̶ vendor lock-in
                + IDE support for external DSL
What is an internal DSL?

 A (business) internal DSL is a
        fluent interface
built on top of a clearly defined
    Command & Query API
The Command & Query API
public interface Car {
    void setColor(Color color);
    void addEngine(Engine engine);
    void add Transmission(Transmission transmission);
}

public interface Engine {
    enum Type { FUEL, DIESEL, ELECTRIC, HYDROGEN, METHANE }
    void setType(Type type);
    void setPower(int power);
    void setCylinder(int cylinder);
}

public interface Transmission {
    enum Type { MANUAL, AUTOMATIC, CONTINOUSLY_VARIABLE }
    void setType(Type type);
    void setNumberOfGears(int gears);
}
Let's build a car
Car car = new CarImpl();
Car.setColor(Color.WHITE);

Engine engine1 = new EngineImpl();
engine1.setType(Engine.Type.FUEL);
engine1.setPower(73);
engine1.setCylinder(4);
car.addEngine(engine1);

Engine engine2 = new EngineImpl();
engine2.setType(Engine.Type.ELECTRIC);
engine2.setPower(60);
car.addEngine(engine2);

Transmission transmission = new TransmissionImpl();
transmission.setType(Transmission.Type.CONTINOUSLY_VARIABLE);
car.setTransmission(transmission);
Quite good …

… but you don't expect
a (non-technical)
domain expert to read
this, don't you?
"Domain users shouldn't
be writing code in our DSL
but it must be designed
for them to understand
and validate“
          Debasish Ghosh
Object Initialization
new CarImpl() {{
    color(Color.WHITE);            + clear hierarchic structure
    engine(new EngineImpl {{
        type(Engine.Type.FUEL);
        power(73);                       ̶ syntactial noise
        cylinder(4);
    }});
    engine(new EngineImpl {{           ̶ explicit use of constructors
        type(Engine.Type.FUEL);
        power(60);
    }});
    transmission(new TransmissionImpl {{
        type(Transmission.Type.CONTINOUSLY_VARIABLE);
    }});
}};                                 + small implementation effort
         ̶ unclear separation between Command API and DSL
Functions Sequence
car();
    color(Color.WHITE);
                               + lowest possible syntactic noise
    engine();
        type(Engine.Type.FUEL);
        power(73);               ̶ impossible to enforce right sequence
        cylinder(4);                of global function invocation
    engine();
        type(Engine.Type.ELECTRIC);
        power(60);                      ̶ use of global context variable(s)
    transmission();
        type(Transmission.Type.CONTINOUSLY_VARIABLE);
end();
                         + works well for defining the items of a (top level) list
     ̶ hierarchy defined only by identation convention
Methods Chaining
car()
    .color(Color.WHITE)          + object scoping
    .engine()
        .type(Engine.Type.FUEL)
        .power(73)
        .cylinder(4)       + method names act as keyword argument
    .engine()
        .type(Engine.Type.ELECTRIC)
        .power(60)
    .transmission()
                             + works good with optional parameter
        .type(Transmission.Type.CONTINOUSLY_VARIABLE)
.end();


    ̶ hierarchy defined only by identation convention
Nested Functions
car(
    color(Color.WHITE),              + no need for context variables
    transmission(
        type(Transmission.Type.CONTINOUSLY_VARIABLE),
    ),
    engine(                                ̶ higher punctuation noise
        type(Engine.Type.FUEL),
        power(73),                    ̶ arguments defined by position
        cylinder(4)                     rather than name
    ),
    engine(
        type(Engine.Type.ELECTRIC), ̶ rigid list of arguments or
        power(60)                            need of methods overloading
    )
);                            ̶ inverted evaluation order

        + hierarchic structure is echoed by function nesting
Is my DSL good
(concise, expressive, readable)
            enough?
              You cooked the meal …




    … now eat it!

DSL design is an iterative process
Mixed Strategy
car(                         nested function for top level object creation
    color(Color.WHITE),
    transmission()
        .type(Transmission.Type.CONTINOUSLY_VARIABLE),
    engine()
        .type(Engine.Type.FUEL)
        .power(73)
        .cylinder(4),          method chaining for arguments definition
    engine()
        .type(Engine.Type.ELECTRIC)
        .power(60)
);
                        function sequence for top level lists
car(
    ...
);
Advanced DSL examples
Hibernate Criteria Queries
List cats = session
        .createCriteria(Cat.class)
        .add( Restrictions.like("name", "Fritz%") )
        .add( Restrictions.between("weight", min, max) )
        .addOrder( Order.desc("age") )
        .setMaxResults(50)
        .list();
jMock
Turtle turtle = context.mock(Turtle.class);

// The turtle will be told to turn 45 degrees once only
oneOf(turtle).turn(45);

// The turtle can be told to flash its LEDs any number
// of times or not at all
allowing(turtle).flashLEDs();

// The turtle can be asked about its pen any number of times
// and will always return PEN_DOWN
allowing(turtle).queryPen();
will(returnValue(PEN_DOWN));

// The turtle will be told to stop at least once.
atLeast(1).of(turtle).stop();
lambdaj
  Plain Java version:
List<Car> automaticCars = new ArrayList<Car>();
for (Car car : cars) {
    if (car.getTransmission().getType() ==
                    Transmission.TYPE.AUTOMATIC)
        automaticCars.add(car);
}

  lambdaj version:

List<Sale> salesOfAFerrari = select(cars, having(
             on(Car.class).getTransmission().getType(),
             equalTo(Transmission.TYPE.AUTOMATIC)
));
Q                                                 A
Mario Fusco                          mario.fusco@gmail.com
Red Hat – Senior Software Engineer     twitter: @mariofusco

Weitere ähnliche Inhalte

Was ist angesagt?

Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Jordi Cabot
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptzand3rs
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation Ayush Gupta
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8icarter09
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptLaurence Svekis ✔
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final TaglessJohn De Goes
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & FeaturesDataStax Academy
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - PolymorphismMudasir Qazi
 

Was ist angesagt? (20)

Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
Model-Driven Software Engineering in Practice - Chapter 4 - Model-Driven Arch...
 
oop Lecture 10
oop Lecture 10oop Lecture 10
oop Lecture 10
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Object Oriented Programming in JavaScript
Object Oriented Programming in JavaScriptObject Oriented Programming in JavaScript
Object Oriented Programming in JavaScript
 
Javascript Best Practices
Javascript Best PracticesJavascript Best Practices
Javascript Best Practices
 
JVM Under The Hood WDI.pdf
JVM Under The Hood WDI.pdfJVM Under The Hood WDI.pdf
JVM Under The Hood WDI.pdf
 
Scala cheatsheet
Scala cheatsheetScala cheatsheet
Scala cheatsheet
 
JIT Compiler
JIT CompilerJIT Compiler
JIT Compiler
 
A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation A Case Study on Java. Java Presentation
A Case Study on Java. Java Presentation
 
Django Models
Django ModelsDjango Models
Django Models
 
Functions in javascript
Functions in javascriptFunctions in javascript
Functions in javascript
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
polymorphism
polymorphism polymorphism
polymorphism
 

Andere mochten auch

The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingPeter Friese
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific LanguagesJavier Canovas
 
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)Jordi Cabot
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Marco Brambilla
 
EMF Compare 2.0: Scaling to Millions (updated)
EMF Compare 2.0: Scaling to Millions (updated)EMF Compare 2.0: Scaling to Millions (updated)
EMF Compare 2.0: Scaling to Millions (updated)mikaelbarbero
 
IFML - The interaction flow modeling language, the OMG standard for UI modeli...
IFML - The interaction flow modeling language, the OMG standard for UI modeli...IFML - The interaction flow modeling language, the OMG standard for UI modeli...
IFML - The interaction flow modeling language, the OMG standard for UI modeli...Marco Brambilla
 
MoDisco EclipseCon2010
MoDisco EclipseCon2010MoDisco EclipseCon2010
MoDisco EclipseCon2010fmadiot
 
You need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesYou need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesPhilip Langer
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework XtextSebastian Zarnekow
 
Programming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and AlfProgramming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and AlfEd Seidewitz
 
ATL tutorial - EclipseCon 2008
ATL tutorial - EclipseCon 2008ATL tutorial - EclipseCon 2008
ATL tutorial - EclipseCon 2008William Piers
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingMario Fusco
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondMario Fusco
 

Andere mochten auch (20)

The Unbearable Stupidity of Modeling
The Unbearable Stupidity of ModelingThe Unbearable Stupidity of Modeling
The Unbearable Stupidity of Modeling
 
Domain-Specific Languages
Domain-Specific LanguagesDomain-Specific Languages
Domain-Specific Languages
 
Introducing MDSD
Introducing MDSDIntroducing MDSD
Introducing MDSD
 
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)
MDD - Desarrollo de software dirigido por modelos que funciona (de verdad!)
 
Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...Industrial and Academic Experiences with a User Interaction Modeling Language...
Industrial and Academic Experiences with a User Interaction Modeling Language...
 
EMF Compare 2.0: Scaling to Millions (updated)
EMF Compare 2.0: Scaling to Millions (updated)EMF Compare 2.0: Scaling to Millions (updated)
EMF Compare 2.0: Scaling to Millions (updated)
 
IFML - The interaction flow modeling language, the OMG standard for UI modeli...
IFML - The interaction flow modeling language, the OMG standard for UI modeli...IFML - The interaction flow modeling language, the OMG standard for UI modeli...
IFML - The interaction flow modeling language, the OMG standard for UI modeli...
 
MoDisco EclipseCon2010
MoDisco EclipseCon2010MoDisco EclipseCon2010
MoDisco EclipseCon2010
 
OCL tutorial
OCL tutorial OCL tutorial
OCL tutorial
 
You need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF ProfilesYou need to extend your models? EMF Facet vs. EMF Profiles
You need to extend your models? EMF Facet vs. EMF Profiles
 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework Xtext
 
Programming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and AlfProgramming in UML: An Introduction to fUML and Alf
Programming in UML: An Introduction to fUML and Alf
 
Acceleo Code Generation
Acceleo Code GenerationAcceleo Code Generation
Acceleo Code Generation
 
Eugenia
EugeniaEugenia
Eugenia
 
ATL tutorial - EclipseCon 2008
ATL tutorial - EclipseCon 2008ATL tutorial - EclipseCon 2008
ATL tutorial - EclipseCon 2008
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Why we cannot ignore Functional Programming
Why we cannot ignore Functional ProgrammingWhy we cannot ignore Functional Programming
Why we cannot ignore Functional Programming
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 

Ähnlich wie Technical and business people speaking the same language with DSL

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Vitaly Baum
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipelineGirish Ghate
 
Game development
Game developmentGame development
Game developmentAsido_
 
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben Sander
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben SanderHSA-4131, HSAIL Programmers Manual: Uncovered, by Ben Sander
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben SanderAMD Developer Central
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glchangehee lee
 
Model-Driven Development in the context of Software Product Lines
Model-Driven Development in the context of Software Product LinesModel-Driven Development in the context of Software Product Lines
Model-Driven Development in the context of Software Product LinesMarkus Voelter
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Languagezefhemel
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable ShadingMark Kilgard
 
ISCA Final Presentation - HSAIL
ISCA Final Presentation - HSAILISCA Final Presentation - HSAIL
ISCA Final Presentation - HSAILHSA Foundation
 
Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training CoursePaul Laskowski
 
HSA HSAIL Introduction Hot Chips 2013
HSA HSAIL Introduction  Hot Chips 2013 HSA HSAIL Introduction  Hot Chips 2013
HSA HSAIL Introduction Hot Chips 2013 HSA Foundation
 
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Data Con LA
 
Extension and Evolution
Extension and EvolutionExtension and Evolution
Extension and EvolutionEelco Visser
 
Apache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail DubkovApache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail DubkovJavaDayUA
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaDmitry Buzdin
 
Inspecting Block Closures To Generate Shaders for GPU Execution
Inspecting Block Closures To Generate Shaders for GPU ExecutionInspecting Block Closures To Generate Shaders for GPU Execution
Inspecting Block Closures To Generate Shaders for GPU ExecutionESUG
 

Ähnlich wie Technical and business people speaking the same language with DSL (20)

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
Game development
Game developmentGame development
Game development
 
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben Sander
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben SanderHSA-4131, HSAIL Programmers Manual: Uncovered, by Ben Sander
HSA-4131, HSAIL Programmers Manual: Uncovered, by Ben Sander
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
Model-Driven Development in the context of Software Product Lines
Model-Driven Development in the context of Software Product LinesModel-Driven Development in the context of Software Product Lines
Model-Driven Development in the context of Software Product Lines
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
PIL - A Platform Independent Language
PIL - A Platform Independent LanguagePIL - A Platform Independent Language
PIL - A Platform Independent Language
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
ISCA Final Presentation - HSAIL
ISCA Final Presentation - HSAILISCA Final Presentation - HSAIL
ISCA Final Presentation - HSAIL
 
Verilog HDL Training Course
Verilog HDL Training CourseVerilog HDL Training Course
Verilog HDL Training Course
 
HSA HSAIL Introduction Hot Chips 2013
HSA HSAIL Introduction  Hot Chips 2013 HSA HSAIL Introduction  Hot Chips 2013
HSA HSAIL Introduction Hot Chips 2013
 
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
Big Data Day LA 2015 - Compiling DSLs for Diverse Execution Environments by Z...
 
Extension and Evolution
Extension and EvolutionExtension and Evolution
Extension and Evolution
 
Apache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail DubkovApache Cassandra. Inception - all you need to know by Mikhail Dubkov
Apache Cassandra. Inception - all you need to know by Mikhail Dubkov
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
Type-safe DSLs
Type-safe DSLsType-safe DSLs
Type-safe DSLs
 
Inspecting Block Closures To Generate Shaders for GPU Execution
Inspecting Block Closures To Generate Shaders for GPU ExecutionInspecting Block Closures To Generate Shaders for GPU Execution
Inspecting Block Closures To Generate Shaders for GPU Execution
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 

Mehr von Mario Fusco

Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automationMario Fusco
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APIMario Fusco
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...Mario Fusco
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep diveMario Fusco
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerMario Fusco
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Mario Fusco
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVMMario Fusco
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Introducing Drools
Introducing DroolsIntroducing Drools
Introducing DroolsMario Fusco
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardMario Fusco
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife SpringMario Fusco
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdajMario Fusco
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 

Mehr von Mario Fusco (20)

Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Let's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java APILet's make a contract: the art of designing a Java API
Let's make a contract: the art of designing a Java API
 
How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
 
OOP and FP
OOP and FPOOP and FP
OOP and FP
 
Lazy java
Lazy javaLazy java
Lazy java
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Drools 6 deep dive
Drools 6 deep diveDrools 6 deep dive
Drools 6 deep dive
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVM
 
Java 8 Workshop
Java 8 WorkshopJava 8 Workshop
Java 8 Workshop
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Monadic Java
Monadic JavaMonadic Java
Monadic Java
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Introducing Drools
Introducing DroolsIntroducing Drools
Introducing Drools
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
 
No more loops with lambdaj
No more loops with lambdajNo more loops with lambdaj
No more loops with lambdaj
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 

Kürzlich hochgeladen

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
#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
 
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
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
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
 
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
 

Kürzlich hochgeladen (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
#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
 
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...
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
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
 
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
 

Technical and business people speaking the same language with DSL

  • 1. Real world DSL making technical and business people speaking the same language by Mario Fusco Red Hat – Senior Software Engineer mario.fusco@gmail.com twitter: @mariofusco
  • 2. What is a Domain Specific Language? A computer programming language of limited expressiveness focused on a particular domain
  • 3. Why use a Domain Specific Language? 2 principles driving toward DSL development
  • 4. Communication is king The only purpose of languages, even programming ones IS COMMUNICATION
  • 5.
  • 6. Written once, read many times Always code as if the person who will maintain your code is a maniac serial killer that knows where you live
  • 7. "Any fool can write code that a computer can understand. Good programmers write code that humans can understand“ Martin Fowler
  • 8. Pros & Cons of DSLs + Expressivity  Communicativity + Conciseness + Readability  Maintainability  Modificability + Higher level of abstraction + Higher productivity in the specific problem domain ̶ Language design is hard ̶ Upfront cost ̶ Additional indirection layer  Performance concerns ̶ Lack of adeguate tool support ̶ Yet-another-language-to-learn syndrome
  • 9. DSL taxonomy  External DSL  a language having custom syntactical rules separate from the main language of the application it works with  Internal DSL  a particular way of employing a general-purpose language, using only a small subset of the language's features  Language workbench  a specialized IDE for defining and building DSL, usually in a visual way, used both to determine the structure of the DSL and to provide an editing environment for people using it
  • 10. DSL Types Comparison + learning curve ̶ syntactic noise + cost of building ̶ needs to be recompiled Internal DSL + programmers familiarity (if host language is static) + IDE support (autocompletion …) + composability + flexibility ̶ need to learn of grammars + readability and language parsing External DSL + clear separation between ̶ boundary between DSL business (DSL) and host language and host language + helpful when business code is ̶ easier to grow out of written by a separate team control (domain experts) Language + visual ̶ tools immaturity Workbench + rapid development ̶ vendor lock-in + IDE support for external DSL
  • 11. What is an internal DSL? A (business) internal DSL is a fluent interface built on top of a clearly defined Command & Query API
  • 12. The Command & Query API public interface Car { void setColor(Color color); void addEngine(Engine engine); void add Transmission(Transmission transmission); } public interface Engine { enum Type { FUEL, DIESEL, ELECTRIC, HYDROGEN, METHANE } void setType(Type type); void setPower(int power); void setCylinder(int cylinder); } public interface Transmission { enum Type { MANUAL, AUTOMATIC, CONTINOUSLY_VARIABLE } void setType(Type type); void setNumberOfGears(int gears); }
  • 13. Let's build a car Car car = new CarImpl(); Car.setColor(Color.WHITE); Engine engine1 = new EngineImpl(); engine1.setType(Engine.Type.FUEL); engine1.setPower(73); engine1.setCylinder(4); car.addEngine(engine1); Engine engine2 = new EngineImpl(); engine2.setType(Engine.Type.ELECTRIC); engine2.setPower(60); car.addEngine(engine2); Transmission transmission = new TransmissionImpl(); transmission.setType(Transmission.Type.CONTINOUSLY_VARIABLE); car.setTransmission(transmission);
  • 14. Quite good … … but you don't expect a (non-technical) domain expert to read this, don't you?
  • 15. "Domain users shouldn't be writing code in our DSL but it must be designed for them to understand and validate“ Debasish Ghosh
  • 16. Object Initialization new CarImpl() {{ color(Color.WHITE); + clear hierarchic structure engine(new EngineImpl {{ type(Engine.Type.FUEL); power(73); ̶ syntactial noise cylinder(4); }}); engine(new EngineImpl {{ ̶ explicit use of constructors type(Engine.Type.FUEL); power(60); }}); transmission(new TransmissionImpl {{ type(Transmission.Type.CONTINOUSLY_VARIABLE); }}); }}; + small implementation effort ̶ unclear separation between Command API and DSL
  • 17. Functions Sequence car(); color(Color.WHITE); + lowest possible syntactic noise engine(); type(Engine.Type.FUEL); power(73); ̶ impossible to enforce right sequence cylinder(4); of global function invocation engine(); type(Engine.Type.ELECTRIC); power(60); ̶ use of global context variable(s) transmission(); type(Transmission.Type.CONTINOUSLY_VARIABLE); end(); + works well for defining the items of a (top level) list ̶ hierarchy defined only by identation convention
  • 18. Methods Chaining car() .color(Color.WHITE) + object scoping .engine() .type(Engine.Type.FUEL) .power(73) .cylinder(4) + method names act as keyword argument .engine() .type(Engine.Type.ELECTRIC) .power(60) .transmission() + works good with optional parameter .type(Transmission.Type.CONTINOUSLY_VARIABLE) .end(); ̶ hierarchy defined only by identation convention
  • 19. Nested Functions car( color(Color.WHITE), + no need for context variables transmission( type(Transmission.Type.CONTINOUSLY_VARIABLE), ), engine( ̶ higher punctuation noise type(Engine.Type.FUEL), power(73), ̶ arguments defined by position cylinder(4) rather than name ), engine( type(Engine.Type.ELECTRIC), ̶ rigid list of arguments or power(60) need of methods overloading ) ); ̶ inverted evaluation order + hierarchic structure is echoed by function nesting
  • 20. Is my DSL good (concise, expressive, readable) enough? You cooked the meal … … now eat it! DSL design is an iterative process
  • 21. Mixed Strategy car( nested function for top level object creation color(Color.WHITE), transmission() .type(Transmission.Type.CONTINOUSLY_VARIABLE), engine() .type(Engine.Type.FUEL) .power(73) .cylinder(4), method chaining for arguments definition engine() .type(Engine.Type.ELECTRIC) .power(60) ); function sequence for top level lists car( ... );
  • 23. Hibernate Criteria Queries List cats = session .createCriteria(Cat.class) .add( Restrictions.like("name", "Fritz%") ) .add( Restrictions.between("weight", min, max) ) .addOrder( Order.desc("age") ) .setMaxResults(50) .list();
  • 24. jMock Turtle turtle = context.mock(Turtle.class); // The turtle will be told to turn 45 degrees once only oneOf(turtle).turn(45); // The turtle can be told to flash its LEDs any number // of times or not at all allowing(turtle).flashLEDs(); // The turtle can be asked about its pen any number of times // and will always return PEN_DOWN allowing(turtle).queryPen(); will(returnValue(PEN_DOWN)); // The turtle will be told to stop at least once. atLeast(1).of(turtle).stop();
  • 25. lambdaj Plain Java version: List<Car> automaticCars = new ArrayList<Car>(); for (Car car : cars) { if (car.getTransmission().getType() == Transmission.TYPE.AUTOMATIC) automaticCars.add(car); } lambdaj version: List<Sale> salesOfAFerrari = select(cars, having( on(Car.class).getTransmission().getType(), equalTo(Transmission.TYPE.AUTOMATIC) ));
  • 26. Q A Mario Fusco mario.fusco@gmail.com Red Hat – Senior Software Engineer twitter: @mariofusco