SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Writing your own DSL
Yes, it is that easy!
Who am I?
● Rob Kinyon
○ @rkinyon
○ rob.kinyon@gmail.com
● Devops lead for many years
● Developer in Ruby, Python, Perl, JS, and
others.
What is a DSL?
● Domain-Specific Language
What is a DSL?
● Domain-Specific Language
● Language - A vehicle for communication
What is a DSL?
● Domain-Specific Language
● Language - A vehicle for communication
● Domain - A restrained set of concepts
What is a DSL?
● Domain-Specific Language
● Language - A vehicle for communication
● Domain - A restrained set of concepts
● Specific - Limited to.
What is a DSL?
● Domain-Specific Language
● Language - A vehicle for communication
● Domain - A restrained set of concepts
● Specific - Limited to.
○ No, really. :)
Language and Communication
● Communicate in one direction
○ Author -> Executor
Language and Communication
● Communicate in two directions
○ Author -> Executor
○ Author -> Maintainer
Language and Communication
● Communicate in three directions
○ Author -> Executor
○ Author -> Maintainer
○ Specifier -> Author
Language and Communication
● Communicate in four directions
○ Author -> Executor
○ Author -> Maintainer
○ Specifier -> Author
○ Author -> Verifier
Language and Communication
● Communicate in MANY directions
○ Author -> Executor
○ Author -> Maintainer
○ Specifier -> Author
○ Author -> Verifier
○ Author -> Teammate(s)
○ Developer -> Sysadmin/Devops
○ … -> …
Language and Communication
● Communicate in MANY directions
○ Author -> Executor
○ Author -> Maintainer
○ Specifier -> Author
○ Author -> Verifier
○ Author -> Teammate(s)
○ Developer -> Sysadmin/Devops
○ … -> …
The ONLY
computer
Language and Communication
● Communicate in MANY directions
○ Author -> Executor
○ Author -> Maintainer
○ Specifier -> Author
○ Author -> Verifier
○ Author -> Teammate(s)
○ Developer -> Sysadmin/Devops
○ … -> …
All humans
Language and Communication
● Communicate in MANY directions
○ Author -> Executor
○ Author <-> Maintainer
○ Specifier <-> Author
○ Author <-> Verifier
○ Author <-> Teammate(s)
○ Developer <-> Sysadmin/Devops
○ … <-> …
All human
communication
is two-way
Domain-Specific
● Eskimos supposedly have 50+ words for
“snow”
○ Depends on how you count it
● Saami has 1000+ words dealing with
reindeer
○ snarri - a reindeer with short, branched horns
○ busat - a bull with a single, large testicle
Domain-specific : Busat
Busat - The quality of having
appropriately-specific expressiveness
for the domain.
DSLs you already use
● SQL
○ set manipulation DSL
● CSS
○ tree-visitor-defining DSL for setting metadata
● HAML
○ HTML-definition DSL
● Bash
○ A crappy way of issue shell commands with logic
Places for a DSL
● Packaging and orchestration
○ most devops/operations activities
● Configuration file generation
○ web servers
○ monitoring
○ datastores
● Configuration value management across environments
● Anything extremely complicated (such as SQL)
● Anything repetitive (such as CSS)
Reasons for a DSL
● Let the important things shine
● General-purpose is overly-verbose
● Bugs hide in boilerplate
● Non-developers can read and comprehend
○ And maybe even propose changes through PRs?
Reasons for a DSL
DSL is to Ruby
as
Ruby is to Java
Writing a DSL
● Three passes
○ Parsing
○ Validation
○ Production
Writing a DSL - Parsing
● DSL::Maker for parsing
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
Car = Struct.new(:make, :year, :engine)
Engine = Struct.new(:hemi)
class VehicleDSL < DSL::Maker
add_entrypoint(:car, {
:make => String,
:year => Integer,
:engine => generate_dsl({
:hemi => Boolean,
}) do
Engine.new(hemi)
end,
}) do |*args|
default(:make, args, 0)
Car.new(make, model, engine)
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
#!/usr/bin/env ruby
require ‘vehicle/dsl’
filename = ARGV.shift ||
raise “No filename provided.”
vehicles = Vehicle::DSL.parse_dsl(
IO.read(filename),
)
# Do something here with vehicles
[
Car[
:make => ‘Accord’,
:year => 1990,
:engine => Engine[
:hemi => true,
],
],
Car[
:make => Civic,
:year => 2014,
:engine => nil,
],
]
. . .
truck ‘F-150’ {
year 1999
}
. . .
. . .
Truck = Struct.new(:make, :year, :engine)
. . .
class VehicleDSL < DSL::Maker
. . .
add_entrypoint(:truck, {
:make => String,
:year => Integer,
:engine => . . .,
}) do |*args|
default(:make, args, 0)
Truck.new(make, model, nil)
end
end
#!/usr/bin/env ruby
require ‘vehicle/dsl’
filename = ARGV.shift ||
raise “No filename provided.”
vehicles = Vehicle::DSL.parse_dsl(
IO.read(filename),
)
# Do something here with vehicles
[
. . .
Truck[
:make => ‘F-150’,
:year => 1999,
:engine => nil
],
. . .
]
Writing a DSL - Validation
● DSL::Maker for parsing
● DSL::Maker for validation
. . .
class VehicleDSL < DSL::Maker
. . .
add_validation(:car) do |car|
unless car.engine
return “Cars must have an engine”
end
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
. . .
class VehicleDSL < DSL::Maker
. . .
add_validation(:car) do |car|
unless car.engine
return “Cars must have an engine”
end
end
end
car {
make ‘Accord’
year 1990
engine {
hemi Yes
}
}
car ‘Civic’ {
year 2014
}
#!/usr/bin/env ruby
require ‘vehicle/dsl’
filename = ARGV.shift ||
raise “No filename provided.”
# This raises the error
vehicles = Vehicle::DSL.parse_dsl(
IO.read(filename),
)
# Do something here with vehicles
Error: Cars must have an engine
Writing a DSL - Production
● DSL::Maker for parsing
● DSL::Maker for validation
● You’re on your own for production
Writing a DSL - Production
● Work from outside in.
○ Parsing is done inside-out.
● Transform in a series of passes.
○ Expand everything (it’s just data)
● Don’t do anything irrevocable until the end
○ Work in temp directories, stage everything
Conclusion
● DSL::Maker 0.1.0 is available right now
● Patches welcome
○ 100% test coverage
● I’m blogging about this at http:
//streamlined-book.blogspot.com
○ First post on the topic
Questions?

Contenu connexe

Similaire à Writing your own DSL

OpenSCAD Tutorial
OpenSCAD TutorialOpenSCAD Tutorial
OpenSCAD TutorialJohn Oliva
 
You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)Igalia
 
MongoDB and DigitalOcean Automation with Cloud Manager
MongoDB and DigitalOcean Automation with Cloud ManagerMongoDB and DigitalOcean Automation with Cloud Manager
MongoDB and DigitalOcean Automation with Cloud ManagerJay Gordon
 
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?Autodesk
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015Jorg Janke
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema DesignJoe Drumgoole
 
DSLs for fun and profit by Jukka Välimaa
DSLs for fun and profit by Jukka VälimaaDSLs for fun and profit by Jukka Välimaa
DSLs for fun and profit by Jukka VälimaaMontel Intergalactic
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
TDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-LanguageTDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-LanguageLuciano Sabença
 
Fuzzing softwares for bugs - OWASP Seasides
Fuzzing softwares for bugs - OWASP SeasidesFuzzing softwares for bugs - OWASP Seasides
Fuzzing softwares for bugs - OWASP SeasidesOWASPSeasides
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Tomas Petricek
 
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014REST services and IBM Domino/XWork - DanNotes 19-20. november 2014
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014John Dalsgaard
 
Talend connect BE Vincent Harcq - Talend ESB - DI
Talend connect BE Vincent Harcq - Talend  ESB - DITalend connect BE Vincent Harcq - Talend  ESB - DI
Talend connect BE Vincent Harcq - Talend ESB - DIVincent Harcq
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackdivyapisces
 
Scala services in action
Scala services in actionScala services in action
Scala services in actionUnderscore
 
AD109 Navigating the Jungle of Modern Web Development
AD109 Navigating the Jungle of Modern Web DevelopmentAD109 Navigating the Jungle of Modern Web Development
AD109 Navigating the Jungle of Modern Web DevelopmentShean McManus
 
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRuby Bangladesh
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...Andy Maleh
 

Similaire à Writing your own DSL (20)

HTML 5 and CSS 3
HTML 5 and CSS 3HTML 5 and CSS 3
HTML 5 and CSS 3
 
OpenSCAD Tutorial
OpenSCAD TutorialOpenSCAD Tutorial
OpenSCAD Tutorial
 
You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)
 
MongoDB and DigitalOcean Automation with Cloud Manager
MongoDB and DigitalOcean Automation with Cloud ManagerMongoDB and DigitalOcean Automation with Cloud Manager
MongoDB and DigitalOcean Automation with Cloud Manager
 
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?
Forge - DevCon 2017, Darmstadt Germany: HFDM - What, why & how?
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 
DSLs for fun and profit by Jukka Välimaa
DSLs for fun and profit by Jukka VälimaaDSLs for fun and profit by Jukka Välimaa
DSLs for fun and profit by Jukka Välimaa
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
TDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-LanguageTDC 2020 - Implementing a Mini-Language
TDC 2020 - Implementing a Mini-Language
 
Fuzzing softwares for bugs - OWASP Seasides
Fuzzing softwares for bugs - OWASP SeasidesFuzzing softwares for bugs - OWASP Seasides
Fuzzing softwares for bugs - OWASP Seasides
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014REST services and IBM Domino/XWork - DanNotes 19-20. november 2014
REST services and IBM Domino/XWork - DanNotes 19-20. november 2014
 
Talend connect BE Vincent Harcq - Talend ESB - DI
Talend connect BE Vincent Harcq - Talend  ESB - DITalend connect BE Vincent Harcq - Talend  ESB - DI
Talend connect BE Vincent Harcq - Talend ESB - DI
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
 
Scala services in action
Scala services in actionScala services in action
Scala services in action
 
Embedded C
Embedded CEmbedded C
Embedded C
 
AD109 Navigating the Jungle of Modern Web Development
AD109 Navigating the Jungle of Modern Web DevelopmentAD109 Navigating the Jungle of Modern Web Development
AD109 Navigating the Jungle of Modern Web Development
 
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in RubyRubyconf Bangladesh 2017 - Lets start coding in Ruby
Rubyconf Bangladesh 2017 - Lets start coding in Ruby
 
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ... Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
Montreal.rb 2022-10-05 - Glimmer DSL for SWT - Ruby Desktop Development GUI ...
 

Dernier

On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.CarlotaBedoya1
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...Escorts Call Girls
 

Dernier (20)

On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 

Writing your own DSL

  • 1. Writing your own DSL Yes, it is that easy!
  • 2.
  • 3. Who am I? ● Rob Kinyon ○ @rkinyon ○ rob.kinyon@gmail.com ● Devops lead for many years ● Developer in Ruby, Python, Perl, JS, and others.
  • 4. What is a DSL? ● Domain-Specific Language
  • 5. What is a DSL? ● Domain-Specific Language ● Language - A vehicle for communication
  • 6. What is a DSL? ● Domain-Specific Language ● Language - A vehicle for communication ● Domain - A restrained set of concepts
  • 7. What is a DSL? ● Domain-Specific Language ● Language - A vehicle for communication ● Domain - A restrained set of concepts ● Specific - Limited to.
  • 8. What is a DSL? ● Domain-Specific Language ● Language - A vehicle for communication ● Domain - A restrained set of concepts ● Specific - Limited to. ○ No, really. :)
  • 9. Language and Communication ● Communicate in one direction ○ Author -> Executor
  • 10. Language and Communication ● Communicate in two directions ○ Author -> Executor ○ Author -> Maintainer
  • 11. Language and Communication ● Communicate in three directions ○ Author -> Executor ○ Author -> Maintainer ○ Specifier -> Author
  • 12. Language and Communication ● Communicate in four directions ○ Author -> Executor ○ Author -> Maintainer ○ Specifier -> Author ○ Author -> Verifier
  • 13. Language and Communication ● Communicate in MANY directions ○ Author -> Executor ○ Author -> Maintainer ○ Specifier -> Author ○ Author -> Verifier ○ Author -> Teammate(s) ○ Developer -> Sysadmin/Devops ○ … -> …
  • 14. Language and Communication ● Communicate in MANY directions ○ Author -> Executor ○ Author -> Maintainer ○ Specifier -> Author ○ Author -> Verifier ○ Author -> Teammate(s) ○ Developer -> Sysadmin/Devops ○ … -> … The ONLY computer
  • 15. Language and Communication ● Communicate in MANY directions ○ Author -> Executor ○ Author -> Maintainer ○ Specifier -> Author ○ Author -> Verifier ○ Author -> Teammate(s) ○ Developer -> Sysadmin/Devops ○ … -> … All humans
  • 16. Language and Communication ● Communicate in MANY directions ○ Author -> Executor ○ Author <-> Maintainer ○ Specifier <-> Author ○ Author <-> Verifier ○ Author <-> Teammate(s) ○ Developer <-> Sysadmin/Devops ○ … <-> … All human communication is two-way
  • 17. Domain-Specific ● Eskimos supposedly have 50+ words for “snow” ○ Depends on how you count it ● Saami has 1000+ words dealing with reindeer ○ snarri - a reindeer with short, branched horns ○ busat - a bull with a single, large testicle
  • 18. Domain-specific : Busat Busat - The quality of having appropriately-specific expressiveness for the domain.
  • 19. DSLs you already use ● SQL ○ set manipulation DSL ● CSS ○ tree-visitor-defining DSL for setting metadata ● HAML ○ HTML-definition DSL ● Bash ○ A crappy way of issue shell commands with logic
  • 20. Places for a DSL ● Packaging and orchestration ○ most devops/operations activities ● Configuration file generation ○ web servers ○ monitoring ○ datastores ● Configuration value management across environments ● Anything extremely complicated (such as SQL) ● Anything repetitive (such as CSS)
  • 21. Reasons for a DSL ● Let the important things shine ● General-purpose is overly-verbose ● Bugs hide in boilerplate ● Non-developers can read and comprehend ○ And maybe even propose changes through PRs?
  • 22. Reasons for a DSL DSL is to Ruby as Ruby is to Java
  • 23. Writing a DSL ● Three passes ○ Parsing ○ Validation ○ Production
  • 24. Writing a DSL - Parsing ● DSL::Maker for parsing
  • 25. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 26. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 27. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 28. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 29. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 30. Car = Struct.new(:make, :year, :engine) Engine = Struct.new(:hemi) class VehicleDSL < DSL::Maker add_entrypoint(:car, { :make => String, :year => Integer, :engine => generate_dsl({ :hemi => Boolean, }) do Engine.new(hemi) end, }) do |*args| default(:make, args, 0) Car.new(make, model, engine) end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 31. #!/usr/bin/env ruby require ‘vehicle/dsl’ filename = ARGV.shift || raise “No filename provided.” vehicles = Vehicle::DSL.parse_dsl( IO.read(filename), ) # Do something here with vehicles [ Car[ :make => ‘Accord’, :year => 1990, :engine => Engine[ :hemi => true, ], ], Car[ :make => Civic, :year => 2014, :engine => nil, ], ]
  • 32. . . . truck ‘F-150’ { year 1999 } . . . . . . Truck = Struct.new(:make, :year, :engine) . . . class VehicleDSL < DSL::Maker . . . add_entrypoint(:truck, { :make => String, :year => Integer, :engine => . . ., }) do |*args| default(:make, args, 0) Truck.new(make, model, nil) end end
  • 33. #!/usr/bin/env ruby require ‘vehicle/dsl’ filename = ARGV.shift || raise “No filename provided.” vehicles = Vehicle::DSL.parse_dsl( IO.read(filename), ) # Do something here with vehicles [ . . . Truck[ :make => ‘F-150’, :year => 1999, :engine => nil ], . . . ]
  • 34. Writing a DSL - Validation ● DSL::Maker for parsing ● DSL::Maker for validation
  • 35. . . . class VehicleDSL < DSL::Maker . . . add_validation(:car) do |car| unless car.engine return “Cars must have an engine” end end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 36. . . . class VehicleDSL < DSL::Maker . . . add_validation(:car) do |car| unless car.engine return “Cars must have an engine” end end end car { make ‘Accord’ year 1990 engine { hemi Yes } } car ‘Civic’ { year 2014 }
  • 37. #!/usr/bin/env ruby require ‘vehicle/dsl’ filename = ARGV.shift || raise “No filename provided.” # This raises the error vehicles = Vehicle::DSL.parse_dsl( IO.read(filename), ) # Do something here with vehicles Error: Cars must have an engine
  • 38. Writing a DSL - Production ● DSL::Maker for parsing ● DSL::Maker for validation ● You’re on your own for production
  • 39. Writing a DSL - Production ● Work from outside in. ○ Parsing is done inside-out. ● Transform in a series of passes. ○ Expand everything (it’s just data) ● Don’t do anything irrevocable until the end ○ Work in temp directories, stage everything
  • 40. Conclusion ● DSL::Maker 0.1.0 is available right now ● Patches welcome ○ 100% test coverage ● I’m blogging about this at http: //streamlined-book.blogspot.com ○ First post on the topic