SlideShare a Scribd company logo
Implementing DSLs in Groovy Matt Secoske http://blog.secosoft.net http://objectpartners.com
DSL? Groovy?
D omain  S pecific  L anguage: A language that clearly  expresses the ideas of a  particular domain
aka: fluent / humane interfaces problem oriented languages little / mini languages macros (as in Excel)
Domain Specific  Language
this:
not this:
this:
not this:
A DSL is just another tool in our toolbox.  It’s a jig to help us build our applications. picture copyrighted @2007 Pat Warner, http://www.patwarner.com
why?
bring the syntax closer to the  domain   (the experts language)
mrMustard .didIt( Murder .of( mrGreen )) .in( theKitchen ) .with( theCandleStick )
/^([a-zA-Z0-9_])+(([a-zA-Z0-9])+)+([a-zA-Z0-9]{2,4})+$/
class CreateQuizComments < ActiveRecord::Migration   def self.up   create_table :quiz_comments do |t|   t.column :name, :string   t.column :email, :string   t.column :url, :string   t.column :comment, :text    end   end   def self.down   drop_table :quiz_comments   end end
Goal:   make the  problem  easier to    understand
(My)  Ultimate  Goal:  Be able to give the code to  the experts, and have them  use  it
Types of DSLs: - Internal - External - Functional - Object Oriented
Internal DSLs  - extending a language - can be whatever  you  want - within the laws of the base    language
Groovy?
A Compelling Story: - Much of the flexibility of Ruby - Familiar Java idioms and syntax - Is focused on the JVM  - and Java “pain points”
Groovy has good DSL support:  - introspection / reflection (ability to parse(itself)) Meta-Object Protocol  - syntactic sugar Builders  Duck Typing Categories ExpandoMetaClass Named Parameters Operator Overloading
Introspection / Reflection - Access to the AST at Class loading time - Can run/load code at any time
class  MyGroovy  extends  GroovyClassLoader { protected  CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) { CompilationUnit cu =  super .createCompilationUnit(config, source); cu.addPhaseOperation( new  PrimaryClassNodeOperation() { public   void   call (SourceUnit source,  GeneratorContext context,  ClassNode classNode)  throws  CompilationFailedException { String name = classNode.getName(); if  (name.endsWith( &quot;Foo&quot; )) { BlockStatement code =  new  BlockStatement(); classNode.addMethod( ”bar&quot; ,Opcodes.ACC_PUBLIC, null , null , null ,code); } } },Phases.CONVERSION); return  cu; } } Adapted from blackdrag’s blog:  http://blackdragsview.blogspot.com/2006/11/chitchat-with-groovy-compiler.html
Meta Object Protocol   - Determines what’s running at Runtime  - add/modify/intercept methods, properties MetaClass Class getFoo() doesntExistOnClass() Other Code
more Groovy syntactic sugar
Duck typing : flexible code if it walks like a duck… and it quacks like a duck… its probably a …. a =  ”a string&quot; println  a. class  // => class java.lang.String a =  1 println  a. class  // => class java.lang.Integer
builders : structured data   swing =  new  SwingBuilder() frame = swing.frame( title: 'Life'  ) {    vbox {    panel( id: 'canvas' ) {   vstrut(height: 300 )   hstrut(width: 300 )   }   hbox {   glue()    button( text: 'Next' , actionPerformed:{evolve()})    } }} frame.pack() frame.show()
Using “ use ”  (Groovy Categories) class  MeasureCategory {   static  Measurement getLbs( final  Integer self) {   new  Measurement(self, Measurement.Pounds)   } } aClosure = {->   println   4 .lbs.of( &quot;Sugar&quot; )   } use (MeasureCategory. class ) {   println   1 .lbs.of( &quot;Carrots&quot; )  // -> 1 Pounds of Carrots   aClosure. call ()   // -> 4 Pounds of Sugar }
Using  ExpandoMetaClass: metaClass =  new  ExpandoMetaClass(Integer. class , true ) metaClass.getLbs << {->   &quot;${delegate} pounds&quot; } metaClass.initialize() i =  1 ; println  i // => 1   println  i. class // => java.lang.Integer println  i.lbs // => 1 pounds
Using  ExpandoMetaClass: metaClass =  new  ExpandoMetaClass(Integer. class , true ) metaClass.getLbs << {->   &quot;${delegate} pounds&quot; } metaClass.initialize() i =  1 ; println  i // => 1   println  i. class // => java.lang.Integer println  i.lbs // => 1 pounds
To  Expando  or not to  Expando … - global usage (good and bad) - must be aware of context - naming collisions use + aspects/annotations = somewhat finer grained control
Operator Overloading: class  Foo { String meh; public  Foo(String meh) { this .meh = meh} public  String toString() { meh } public  Foo  plus (other) { new  Foo( this .meh + other.toString())   } } a =  new  Foo( &quot;Hello &quot; ) b =  new  Foo( &quot;World&quot; ) c =  &quot;New World&quot; println  a + b  // -> “Hello World” println  a + c  // -> “Hello New World”
Grails/Hibernate Criteria Builder: def  c = Account.createCriteria()  def  results = c {  like( &quot;holderFirstName&quot; ,  &quot;Fred%&quot; )  and {  between( &quot;balance&quot; ,  500 ,  1000 )  eq( &quot;branch&quot; ,  &quot;London&quot; )  }  maxResults( 10 )  order( &quot;holderLastName&quot; ,  &quot;desc&quot; )  }
A Recipe DSL: use(MeasurementCategory) { recipe =  new  Recipe() recipe.ingredients = [ 2 .cups.of( &quot;Milk&quot; ), 2 .tsps.of( &quot;Chocolate Milk Mix&quot; ) ] recipe.steps { with( &quot;drinking glass&quot; ) { add( &quot;Chocolate Milk Mix&quot; ) stirIn( &quot;Milk&quot; ) } } }
Domain Specific Language syntax approaches the problem understanding++
Three things that always matter: Naming Structure Context } Meaning
Thank You! slides at:   http://blog.secosoft.net

More Related Content

What's hot

お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
Kazuchika Sekiya
 
uerj201212
uerj201212uerj201212
uerj201212
Juan Lopes
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
C++ course start
C++ course startC++ course start
C++ course start
Net3lem
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날
Sukjoon Kim
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
Ken Kousen
 
Bootstrap
BootstrapBootstrap
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
Jedsada Tiwongvokul
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
bqconf
 
Debugging Memory Problems in Rails
Debugging Memory Problems in RailsDebugging Memory Problems in Rails
Debugging Memory Problems in Rails
Nasos Psarrakos
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
MongoDB
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?
jungkees
 
Presentatie - Introductie in Groovy
Presentatie - Introductie in GroovyPresentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
Getting value from IoT, Integration and Data Analytics
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Connor McDonald
 
Clojure functions
Clojure functionsClojure functions
Clojure functions
Jackson dos Santos Olveira
 
gemdiff
gemdiffgemdiff
gemdiff
teeparham
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo
 
Border Patrol - Count, throttle, kick & ban in perl
Border Patrol - Count, throttle, kick & ban in perlBorder Patrol - Count, throttle, kick & ban in perl
Border Patrol - Count, throttle, kick & ban in perl
David Morel
 
Imutabilidade em ruby
Imutabilidade em rubyImutabilidade em ruby
Imutabilidade em ruby
mauricioszabo
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf
 

What's hot (20)

お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
 
uerj201212
uerj201212uerj201212
uerj201212
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
 
C++ course start
C++ course startC++ course start
C++ course start
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날
 
Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)Making Java Groovy (JavaOne 2013)
Making Java Groovy (JavaOne 2013)
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
 
Debugging Memory Problems in Rails
Debugging Memory Problems in RailsDebugging Memory Problems in Rails
Debugging Memory Problems in Rails
 
Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)Replica Sets (NYC NoSQL Meetup)
Replica Sets (NYC NoSQL Meetup)
 
Do you Promise?
Do you Promise?Do you Promise?
Do you Promise?
 
Presentatie - Introductie in Groovy
Presentatie - Introductie in GroovyPresentatie - Introductie in Groovy
Presentatie - Introductie in Groovy
 
Tokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java DeveloperTokyo APAC Groundbreakers tour - The Complete Java Developer
Tokyo APAC Groundbreakers tour - The Complete Java Developer
 
Clojure functions
Clojure functionsClojure functions
Clojure functions
 
gemdiff
gemdiffgemdiff
gemdiff
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
Border Patrol - Count, throttle, kick & ban in perl
Border Patrol - Count, throttle, kick & ban in perlBorder Patrol - Count, throttle, kick & ban in perl
Border Patrol - Count, throttle, kick & ban in perl
 
Imutabilidade em ruby
Imutabilidade em rubyImutabilidade em ruby
Imutabilidade em ruby
 
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume LaforgeGR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
GR8Conf 2009: What's New in Groovy 1.6? by Guillaume Laforge
 

Viewers also liked

Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
Sten Anderson
 
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
 
Practical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific LanguagesPractical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific Languages
Guillaume Laforge
 
(Greach 2015) Dsl'ing your Groovy
(Greach 2015) Dsl'ing your Groovy(Greach 2015) Dsl'ing your Groovy
(Greach 2015) Dsl'ing your Groovy
Alonso Torres
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
Guillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
Guillaume Laforge
 

Viewers also liked (6)

Building DSLs with Groovy
Building DSLs with GroovyBuilding DSLs with Groovy
Building DSLs with Groovy
 
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 Domain-Specific Languages
Practical Groovy Domain-Specific LanguagesPractical Groovy Domain-Specific Languages
Practical Groovy Domain-Specific Languages
 
(Greach 2015) Dsl'ing your Groovy
(Greach 2015) Dsl'ing your Groovy(Greach 2015) Dsl'ing your Groovy
(Greach 2015) Dsl'ing your Groovy
 
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
 

Similar to Os Secoske

ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
Guillaume Laforge
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
Wes Williams
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
James Williams
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
mpnkhan
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
Tsuyoshi Yamamoto
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
Stephen Chin
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
Guillaume Laforge
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ray Toal
 
The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202
Mahmoud Samir Fayed
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
Andres Almiray
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
Andres Almiray
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
Puneet Behl
 

Similar to Os Secoske (20)

ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Groovy Basics
Groovy BasicsGroovy Basics
Groovy Basics
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
名古屋SGGAE/J勉強会 Grails、Gaelykでハンズオン
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Groovy
GroovyGroovy
Groovy
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
 
The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202The Ring programming language version 1.8 book - Part 95 of 202
The Ring programming language version 1.8 book - Part 95 of 202
 
GTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with GroovyGTAC Boosting your Testing Productivity with Groovy
GTAC Boosting your Testing Productivity with Groovy
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Groovy for Java Developers
Groovy for Java DevelopersGroovy for Java Developers
Groovy for Java Developers
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Groovy for java developers
Groovy for java developersGroovy for java developers
Groovy for java developers
 

More from oscon2007

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
oscon2007
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
oscon2007
 
Os Borger
Os BorgerOs Borger
Os Borger
oscon2007
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
oscon2007
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
oscon2007
 
Os Bunce
Os BunceOs Bunce
Os Bunce
oscon2007
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
oscon2007
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
oscon2007
 
Os Fogel
Os FogelOs Fogel
Os Fogel
oscon2007
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
oscon2007
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
oscon2007
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
oscon2007
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
oscon2007
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
oscon2007
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
oscon2007
 
Os Pruett
Os PruettOs Pruett
Os Pruett
oscon2007
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
oscon2007
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
oscon2007
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
oscon2007
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
oscon2007
 

More from oscon2007 (20)

J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Solr Presentation5
Solr Presentation5Solr Presentation5
Solr Presentation5
 
Os Borger
Os BorgerOs Borger
Os Borger
 
Os Harkins
Os HarkinsOs Harkins
Os Harkins
 
Os Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman WiifmOs Fitzpatrick Sussman Wiifm
Os Fitzpatrick Sussman Wiifm
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 
Yuicss R7
Yuicss R7Yuicss R7
Yuicss R7
 
Performance Whack A Mole
Performance Whack A MolePerformance Whack A Mole
Performance Whack A Mole
 
Os Fogel
Os FogelOs Fogel
Os Fogel
 
Os Lanphier Brashears
Os Lanphier BrashearsOs Lanphier Brashears
Os Lanphier Brashears
 
Os Tucker
Os TuckerOs Tucker
Os Tucker
 
Os Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman SwpOs Fitzpatrick Sussman Swp
Os Fitzpatrick Sussman Swp
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Os Berlin Dispelling Myths
Os Berlin Dispelling MythsOs Berlin Dispelling Myths
Os Berlin Dispelling Myths
 
Os Kimsal
Os KimsalOs Kimsal
Os Kimsal
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
Os Alrubaie
Os AlrubaieOs Alrubaie
Os Alrubaie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Os Jonphillips
Os JonphillipsOs Jonphillips
Os Jonphillips
 
Os Urnerupdated
Os UrnerupdatedOs Urnerupdated
Os Urnerupdated
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
maazsz111
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
SAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloudSAP S/4 HANA sourcing and procurement to Public cloud
SAP S/4 HANA sourcing and procurement to Public cloud
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 

Os Secoske

  • 1. Implementing DSLs in Groovy Matt Secoske http://blog.secosoft.net http://objectpartners.com
  • 3. D omain S pecific L anguage: A language that clearly expresses the ideas of a particular domain
  • 4. aka: fluent / humane interfaces problem oriented languages little / mini languages macros (as in Excel)
  • 5. Domain Specific Language
  • 10. A DSL is just another tool in our toolbox. It’s a jig to help us build our applications. picture copyrighted @2007 Pat Warner, http://www.patwarner.com
  • 11. why?
  • 12. bring the syntax closer to the domain (the experts language)
  • 13. mrMustard .didIt( Murder .of( mrGreen )) .in( theKitchen ) .with( theCandleStick )
  • 15. class CreateQuizComments < ActiveRecord::Migration def self.up create_table :quiz_comments do |t| t.column :name, :string t.column :email, :string t.column :url, :string t.column :comment, :text end end def self.down drop_table :quiz_comments end end
  • 16. Goal: make the problem easier to understand
  • 17. (My) Ultimate Goal: Be able to give the code to the experts, and have them use it
  • 18. Types of DSLs: - Internal - External - Functional - Object Oriented
  • 19. Internal DSLs - extending a language - can be whatever you want - within the laws of the base language
  • 21. A Compelling Story: - Much of the flexibility of Ruby - Familiar Java idioms and syntax - Is focused on the JVM - and Java “pain points”
  • 22. Groovy has good DSL support: - introspection / reflection (ability to parse(itself)) Meta-Object Protocol - syntactic sugar Builders Duck Typing Categories ExpandoMetaClass Named Parameters Operator Overloading
  • 23. Introspection / Reflection - Access to the AST at Class loading time - Can run/load code at any time
  • 24. class MyGroovy extends GroovyClassLoader { protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) { CompilationUnit cu = super .createCompilationUnit(config, source); cu.addPhaseOperation( new PrimaryClassNodeOperation() { public void call (SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { String name = classNode.getName(); if (name.endsWith( &quot;Foo&quot; )) { BlockStatement code = new BlockStatement(); classNode.addMethod( ”bar&quot; ,Opcodes.ACC_PUBLIC, null , null , null ,code); } } },Phases.CONVERSION); return cu; } } Adapted from blackdrag’s blog: http://blackdragsview.blogspot.com/2006/11/chitchat-with-groovy-compiler.html
  • 25. Meta Object Protocol - Determines what’s running at Runtime - add/modify/intercept methods, properties MetaClass Class getFoo() doesntExistOnClass() Other Code
  • 27. Duck typing : flexible code if it walks like a duck… and it quacks like a duck… its probably a …. a = ”a string&quot; println a. class // => class java.lang.String a = 1 println a. class // => class java.lang.Integer
  • 28. builders : structured data swing = new SwingBuilder() frame = swing.frame( title: 'Life' ) { vbox { panel( id: 'canvas' ) { vstrut(height: 300 ) hstrut(width: 300 ) } hbox { glue() button( text: 'Next' , actionPerformed:{evolve()}) } }} frame.pack() frame.show()
  • 29. Using “ use ” (Groovy Categories) class MeasureCategory { static Measurement getLbs( final Integer self) { new Measurement(self, Measurement.Pounds) } } aClosure = {-> println 4 .lbs.of( &quot;Sugar&quot; ) } use (MeasureCategory. class ) { println 1 .lbs.of( &quot;Carrots&quot; ) // -> 1 Pounds of Carrots aClosure. call () // -> 4 Pounds of Sugar }
  • 30. Using ExpandoMetaClass: metaClass = new ExpandoMetaClass(Integer. class , true ) metaClass.getLbs << {-> &quot;${delegate} pounds&quot; } metaClass.initialize() i = 1 ; println i // => 1 println i. class // => java.lang.Integer println i.lbs // => 1 pounds
  • 31. Using ExpandoMetaClass: metaClass = new ExpandoMetaClass(Integer. class , true ) metaClass.getLbs << {-> &quot;${delegate} pounds&quot; } metaClass.initialize() i = 1 ; println i // => 1 println i. class // => java.lang.Integer println i.lbs // => 1 pounds
  • 32. To Expando or not to Expando … - global usage (good and bad) - must be aware of context - naming collisions use + aspects/annotations = somewhat finer grained control
  • 33. Operator Overloading: class Foo { String meh; public Foo(String meh) { this .meh = meh} public String toString() { meh } public Foo plus (other) { new Foo( this .meh + other.toString()) } } a = new Foo( &quot;Hello &quot; ) b = new Foo( &quot;World&quot; ) c = &quot;New World&quot; println a + b // -> “Hello World” println a + c // -> “Hello New World”
  • 34. Grails/Hibernate Criteria Builder: def c = Account.createCriteria() def results = c { like( &quot;holderFirstName&quot; , &quot;Fred%&quot; ) and { between( &quot;balance&quot; , 500 , 1000 ) eq( &quot;branch&quot; , &quot;London&quot; ) } maxResults( 10 ) order( &quot;holderLastName&quot; , &quot;desc&quot; ) }
  • 35. A Recipe DSL: use(MeasurementCategory) { recipe = new Recipe() recipe.ingredients = [ 2 .cups.of( &quot;Milk&quot; ), 2 .tsps.of( &quot;Chocolate Milk Mix&quot; ) ] recipe.steps { with( &quot;drinking glass&quot; ) { add( &quot;Chocolate Milk Mix&quot; ) stirIn( &quot;Milk&quot; ) } } }
  • 36. Domain Specific Language syntax approaches the problem understanding++
  • 37. Three things that always matter: Naming Structure Context } Meaning
  • 38. Thank You! slides at: http://blog.secosoft.net