SlideShare una empresa de Scribd logo
1 de 107
Descargar para leer sin conexión
goals
•    DSL Fundamentals
•    Some Ruby Basics
•    DSL construction with Ruby
•    Advanced Topics - A step further
•    Summary
•    Q&A
problem?
           Problem



                      Customer

   reduce the gap
                      Programmer




           Solution
01000001
evolution
 Problem

            ?

                Object Oriented     C++ Java




                                                                  expressive
  GAP




                  Procedural                   C


                     Assembly                      Emergence of
                                                   language

                        100101010
 Solution
the power of language
•    Arm Ball
•    Around the wicket
•    Cow Corner
•    Duck
•    Fly Slip
•    Googly



http://en.wikipedia.org/wiki/List_of_cricket_terms - an long list of cricket terms
evolution
 Problem

            DSL

             Object Oriented       C++ Java




                                                                 expressive
  GAP




                  Procedural                  C


                    Assembly                      Emergence of
                                                  language

                       100101010
 Solution
example




Monit – automatic management and monitoring - http://mmonit.com/
definition
 a computer programming language of limited
     expressiveness focused on a particular
                   domain
                                                            - Martin Fowler




Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
definition
     a computer programming language of
        limited expressiveness focused on a
                  particular domain
                                                            - Martin Fowler




Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
definition
     a computer programming language of
        limited expressiveness focused on a
                 particular domain
                                                            - Martin Fowler




Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
definition
     a computer programming language of
       limited expressiveness focused on a
                particular domain
                                                            - Martin Fowler




Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
Domain Specific Languages
           vs.
    General Purpose
       Languages
what DSLs bring to the table
•    Quality
•    Productivity
•    Reliability
•    Maintainability
•    Reusability
what DSLs bring to the table
•    Quality
•    Productivity
•    Reliability
•    Maintainability
•    Reusability

•  Social impact
what DSLs bring to the table
•    Quality
•    Productivity
•    Reliability
•    Maintainability
•    Reusability

•  Social impact
•  Validation at the domain level
no silver bullet!
no silver bullet!
•  Learning curve
no silver bullet!
•  Learning curve
•  Good language design is hard
no silver bullet!
•  Learning curve
•  Good language design is hard
•  Cost of building
no silver bullet!
•    Learning curve
•    Good language design is hard
•    Cost of building
•    Limited applicability
no silver bullet!
•    Learning curve
•    Good language design is hard
•    Cost of building
•    Limited applicability
•    Maintenance
no silver bullet!
•    Learning curve
•    Good language design is hard
•    Cost of building
•    Limited applicability
•    Maintenance
•    Could be overused or abused
Types of DSL
external DSL
Need to build a parser to process the custom
 syntax

sql, make files, xml config files, regular
  expressions
advantages
•  Free to use any syntax
advantages
•  Free to use any syntax
•  Run time evaluation
disadvantages
•  Starts simple, can get ugly and complex
disadvantages
•  Starts simple, can get ugly and complex
•  Building parsers is difficult
disadvantages
•  Starts simple, can get ugly and complex
•  Building parsers is difficult
•  Lack of tooling support
internal DSL
Extends the host language
advantages
•  Don't have to write and debug a new
   language
advantages
•  Don't have to write and debug a new
   language
•  Full power of base language is available
advantages
•  Don't have to write and debug a new
   language
•  Full power of base language is available
•  Tooling support available
disadvantages
•  constrained by the host language.
Ruby based DSLs are
      internal
DSLs - not special to Ruby
Ruby is special
why is ruby special
•  minimally intrusive Syntax to allow for more
   concise code
why is ruby special
•  minimally intrusive Syntax to allow for more
   concise code
•  Ruby culture - values expressiveness in
   code
why is ruby special
•  minimally intrusive Syntax to allow for more
   concise code
•  Ruby culture - values expressiveness in
   code
•  Dynamic and Reflective
* Working code writing using RSpec, a testing frame work
DSL goodness
OPTIONAL PUNCTUATION
concise code
vs.
SYMBOLS
less noisy than strings
or
BLOCKS
delayed evaluation of code
OPEN CLASSES
build your language
some code here
METAPROGRAMMING
expand your mind
define_method
 eval           alias_method
        module_eval
                   class_eval
instance_eval
‘whenever’
a DSL for cron jobs




    30   4   1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31   *   *   reboot




http://github.com/javan/whenever
language constructs
           year
   hour month   sunday
     day   reboot  monday
     weekend    a.m
           weekday   p.m
expressive




    30   4   1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31   *   *   reboot




http://github.com/javan/whenever
The fascinating thing is that, in my
    experience, most well-written Ruby
programs are already a DSL, just by nature
            of Ruby’s syntax.”

                  - Jamis Buck, 37signals
Writing DSLs in Ruby

THE PROCESS
Application Programming Interface
Example 1
try {
  Socket client = new Socket(“www.google.com”,80);
} catch(IOException e) {
   System.out.println(e);
}
Application Programming Interface
Example 1
try {
  Socket client = new Socket(“www.google.com”,80);
} catch(IOException e) {
   System.out.println(e);
}
Example 2
Customer.find :all, :condition => [ :age >= 25 ]
Application Programming Interface
Example 1
try {
  Socket client = new Socket(“www.google.com”,80);
} catch(IOException e) {
   System.out.println(e);
}
Example 2
Customer.find :all, :condition => [ :age >= 25 ]


•  Libraries give a sense of domain-specificity because
   of vocabulary
      •  Nouns / verbs / adverbs / adjectives
Application Programming Interface
Example 1
try {
  Socket client = new Socket(“www.google.com”,80);
} catch(IOException e) {
   System.out.println(e);
}
Example 2
Customer.find :all, :condition => [ :age >= 25 ]


•  Libraries give a sense of domain-specificity because
   of vocabulary
      •  Nouns / verbs / adverbs / adjectives
      •  They are all internal DSLs
Patterns

Interfaces




             Abstractions




             DSL
              “But, I believe a DSL is a healthy bi-product
                   of a good object-oriented design.”
                            Blaine Buxton (Smalltalk developer)
Internal DSLs – A coarse process

  Capture vocabulary and processes
  of the domain

     Discover desired syntax


        Define DSL interface (API)


           Define classes and abstractions


              Implement validations
Capture vocabulary
 •  Task scheduling is the domain of ‘cron’
    •  Tasks
    •  Timing
    •  Frequency
Capture vocabulary
 •  Task scheduling is the domain of ‘cron’
    •  Tasks (e.g. ‘reboot’, ‘send mail’, ‘alert’, etc)
    •  Timing (e.g. ‘5 pm’, ‘4.30 am’, etc)
    •  Frequency (e.g. ‘yearly’, ‘weekend’, etc)
Capture vocabulary
 •  Task scheduling is the domain of ‘cron’
    •  Tasks (e.g. ‘reboot’, ‘send mail’, ‘alert’, etc)
    •  Timing (e.g. ‘5 pm’, ‘4.30.am’, etc)
    •  Frequency (e.g. ‘yearly’, ‘weekend’, etc)

 •  Discover keywords
    •  Special words (‘yearly’, ‘reboot’, etc)
    •  Domain values (‘5 pm’, etc)
    •  A good design would decide ownership of these keywords

                                         annually                    year       at
                                                    hourly
                                                             month            sunday
                                          runner                                   monday
                                                    day              reboot
                                          every                               a.m.
                                                    weekend
                                                                 weekday               p.m.
Discover syntax

                             Experiment
                               around
                              keywords




          Write
        extended
                                                       Design a
        methods                                         syntax
          (e.g.
         2.days)             Discuss
                               with
                             DSL user




                  Define
                                            Define
                ownership
                                          constructs
               of keywords
Design considerations
•  “Follow good design principles”
   –  Entities as classes
      •  As nouns
   –  Operations as methods
      •  Typically as verbs
      •  Adaptive interfaces (wrappers) to instantiate aggregations
      •  Accept hash as argument to simulate ‘call by name’
Purpose               Ruby feature
    (what)                  (how)

                          Function calls w/o
    Getter/setter
                            parentheses

  Pattern matching       Regular expressions         Using Ruby
                                                     features to realize
Alternative interfaces      ‘alias_method’           DSL constructs


      Context                Closure/block

  Code generation                Strings

     Execution           ‘load’, ‘require’, ‘eval’

Arbitrary interfaces/
                           ‘method_missing’
     attributes
Writing ‘Whenever’

 every 2.days, :at => '4:30 am‘ do
     runner “/usr/bin/reboot”
 end
Writing ‘Whenever’

 every 2.days, :at => '4:30 am‘ do
     runner “/usr/bin/reboot”
 end




 every(2.days(),{:at => '4:30 am’}) do
     runner(“/usr/bin/reboot”)
 end
Writing ‘Whenever’
                             2.days()


 Class JobList
   def every(frequency, option={})
       …
     yield #handles block
   end                           { :at => ‘4.30.am ‘ }



   def runner(task, options={})
     …
   end
 end
Real examples

A TALE OF TWO DSLS
EXAMPLE 1: DSL FOR GMRT
Giant Metrewave Radio Telescope
System
                     30
                  Antennae




 http://gmrt.ncra.tifr.res.in
GMRT Prototype
 •  Objective
     –  Re-engineering ‘ABC’ and ‘Teleset’
     –  Collaboration among TCS, NCRA and CoEP
 •  Challenges
     –  Scientists need a simple, extensible interface to
         •  Monitor and control antennae
         •  Schedule experiments
 •  Approach
    –  ABC as collection of Rails web services
    –  Teleset re-designed as a Ruby DSL
‘Teleset’ as DSL: Version 1.0



   a1 = AntennaClient.new (“http://antenna1”)
   a1.reboot
   a1.monitor 2.mhz


                   Single antenna
‘Teleset’ as DSL : Version 1.1

    Single antenna     a1 = AntennaClient.new (“http://antenna1”)
                       a1.reboot
                       a1.monitor 2.mhz




 Simultaneously,
                                                                    Complex !!!
 for antennae
 a1 and a2

     engine.register_participant :antenna do | antenna |
       reboot
       monitor 2.mhz
     end
     concurrent_iterator on_value => [:a1,:a2], to_variable => ‘antenna’ do
           participant :antenna => ’${antenna}’
     end #Using openwferu engine




       http://openwferu.rubyforge.org - Using OpenWFEru Workflow engine
‘Teleset’ as DSL : Version 2.0

           Suggested prototype


           with antenna :a1, :a2 do
                 reboot
                 monitor 2.mhz                                   Much
                                                                simpler !
           end



  engine.register_participant :antenna do | antenna |
    reboot
    monitor 2.mhz
  end
  concurrent_iterator on_value => [:a1,:a2], to_variable => ‘antenna’ do
        participant :antenna => ’${antenna}’
  end
EXAMPLE 2: DSL FOR
VISUALIZATION
DSL for visualization
 •  Objective
    –  A specification-driven dashboard
       •  Visualization metaphors (charts, data grids, etc)
       •  Organization using layouts (window, tab, portal, etc)
       •  Navigation (page flows)

 •  Challenge
    –  Consistent API
    –  Integration with other components and environment

 •  Ruby was chosen
application ‘ThoughtWorks MCS Demo’ do

  add grid ‘Actors list’ do

   data_source table do
      table_name ‘actor’
    end # data_source

  end # grid
end # application
application ‘Thoughtworks MCS Demo’ do
  add grid ‘Actors list’ do
    data_source table do
      table_name ‘actor’
    end # data_source

    add view ‘Show movies’ do | actor |
      add grid “Movies for actor #{actor}” do
          data_source query do
             text “SELECT …
                   WHERE actor_id=#{actor.actor_id}”
          end # data_source
      end # grid
    end # view
  end # grid
end # application
Advanced topics

A STEP FURTHER
Evolution of a DSL
•  Generalization versus specialization
•  “expressiveness x scope = constant” [3]

          expressiveness


        External   Internal                  DSL
         DSL        DSLs

scope                         scope

         ASM        GPL
                                      GPL

          expressiveness
Three aspects



                     Domain
                                          Domain-specific
                     aspect                 Language




          Language        Specification
           aspect           aspect
Three aspects



  Domain                  Specification            Language
  •  CRUD of              •  Conditionality (if/   •  Natural
     •  Domain entities      switch)               •  Syntactic noise
     •  Relationships     •  Automation            •  Semantic noise
     •  Processes            (loops)
     •  Constraints       •  Reusability
                             (function/classes)
                          •  Data structures
                          •  Error handling
Three aspects



  Domain                  Specification            Language
  •  CRUD of              •  Conditionality (if/   •  Natural
     •  Domain entities      switch)               •  Syntactic noise
     •  Relationships     •  Automation            •  Semantic noise
     •  Processes            (loops)
     •  Constraints       •  Reusability
                             (function/classes)
                          •  Data structures
                          •  Error handling
Three aspects



  Domain                  Specification            Language
  •  CRUD of              •  Conditionality (if/   •  Natural
     •  Domain entities      switch)               •  Syntactic noise
     •  Relationships     •  Automation            •  Semantic noise
     •  Processes            (loops)
     •  Constraints       •  Reusability
                             (function/classes)
                          •  Data structures
                          •  Error handling
Evolution of a DSL


                                                                Specialization
                                                                (inheritance)
                                                  Reusability


                                 Conditions and
                                 loops

                Entities (+
                relationships)



   Entities
   (numbers
   + strings)
Crossroads and crosswords

•  “No domain is an island”
•  Interoperability in DSLs
   •  DSLs need to talk one-another
   •  Achilles’ Heel for external DSLs
   •  Parallel development of different DSLs needs early
      standardization
      •  Chicken-egg problem
Future of DSLs
•  UML and DSL
    •  DSL as front-end to UML (or alternative)[5]




Book “MDA Distilled” (page 16)
Future of DSLs
•  UML and DSL
  •  DSL as front-end to UML (or alternative)[5]
•  High assurance systems
  •  Minimal code, relevant code
Future of DSLs
•  UML and DSL
    •  DSL as front-end to UML (or alternative)[5]
•  High assurance systems
    •  Minimal code, relevant code
•  Multi-core revolution
    •  Multi-threading
    •  Message passing




The Free Lunch Is Over – Herb Sutter’s article on Multi-core Revolution
References and resources
1.    Interview of Bjarne Stroustrup
2.    Presentation by Martin Fowler (at InfoQ.com)
3.    Domain-Specific Languages in Perspective
4.    A Picture is Worth a 1000 Words?
5.    Book “MDA Distilled” (page 16)
6.    The Free Lunch Is Over
Language Design    Library Design
       is                is
 Library Design   Language Design




                      Bjarne Stroustrup [1]
Contacts

iamharshal@yahoo.com
 rohan.kini@gmail.com

Más contenido relacionado

Destacado

Introduction, features and environment of ms front page 2003
Introduction, features and environment of ms front page 2003Introduction, features and environment of ms front page 2003
Introduction, features and environment of ms front page 2003Ann Alcid
 
What does the WAIS IV measure? CHC analysis and beyond
What does the WAIS IV measure?  CHC analysis and beyondWhat does the WAIS IV measure?  CHC analysis and beyond
What does the WAIS IV measure? CHC analysis and beyondKevin McGrew
 
RARP, BOOTP, DHCP and PXE Protocols
RARP, BOOTP, DHCP and PXE ProtocolsRARP, BOOTP, DHCP and PXE Protocols
RARP, BOOTP, DHCP and PXE ProtocolsPeter R. Egli
 
Frames and frame measurements__optometry_india_eyenirvaan.com
Frames and frame measurements__optometry_india_eyenirvaan.comFrames and frame measurements__optometry_india_eyenirvaan.com
Frames and frame measurements__optometry_india_eyenirvaan.comEyenirvaan
 
Network security for E-Commerce
Network security for E-CommerceNetwork security for E-Commerce
Network security for E-CommerceHem Pokhrel
 
Frame measurement & marking
Frame measurement & markingFrame measurement & marking
Frame measurement & markingvivek parmar
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer ProtocolRajan Pandey
 
LUMA's State of Digital Media at DMS 16
LUMA's State of Digital Media at DMS 16LUMA's State of Digital Media at DMS 16
LUMA's State of Digital Media at DMS 16LUMA Partners
 
Pop up design and paper mechanics
Pop up design and paper mechanicsPop up design and paper mechanics
Pop up design and paper mechanicsCatalina Leon
 
Electronic payment system
Electronic payment systemElectronic payment system
Electronic payment systempankhadi
 
Information technology act 2000
Information technology act 2000Information technology act 2000
Information technology act 2000Akash Varaiya
 
Introduction to RF & Wireless - Part 2
Introduction to RF & Wireless - Part 2Introduction to RF & Wireless - Part 2
Introduction to RF & Wireless - Part 2Carl Weisman
 
FireWall
FireWallFireWall
FireWallrubal_9
 
Domain Specific Languages in Ruby - Medellin.rb
Domain Specific Languages in Ruby - Medellin.rbDomain Specific Languages in Ruby - Medellin.rb
Domain Specific Languages in Ruby - Medellin.rbOscar Rendon
 
Security in E-commerce
Security in E-commerceSecurity in E-commerce
Security in E-commercem8817
 
Digital transformation in 50 soundbites
Digital transformation in 50 soundbitesDigital transformation in 50 soundbites
Digital transformation in 50 soundbitesJulie Dodd
 

Destacado (20)

Introduction, features and environment of ms front page 2003
Introduction, features and environment of ms front page 2003Introduction, features and environment of ms front page 2003
Introduction, features and environment of ms front page 2003
 
What does the WAIS IV measure? CHC analysis and beyond
What does the WAIS IV measure?  CHC analysis and beyondWhat does the WAIS IV measure?  CHC analysis and beyond
What does the WAIS IV measure? CHC analysis and beyond
 
Email Client Server System
Email Client Server SystemEmail Client Server System
Email Client Server System
 
RARP, BOOTP, DHCP and PXE Protocols
RARP, BOOTP, DHCP and PXE ProtocolsRARP, BOOTP, DHCP and PXE Protocols
RARP, BOOTP, DHCP and PXE Protocols
 
Frames and frame measurements__optometry_india_eyenirvaan.com
Frames and frame measurements__optometry_india_eyenirvaan.comFrames and frame measurements__optometry_india_eyenirvaan.com
Frames and frame measurements__optometry_india_eyenirvaan.com
 
Network security for E-Commerce
Network security for E-CommerceNetwork security for E-Commerce
Network security for E-Commerce
 
Frame measurement & marking
Frame measurement & markingFrame measurement & marking
Frame measurement & marking
 
Simple Mail Transfer Protocol
Simple Mail Transfer ProtocolSimple Mail Transfer Protocol
Simple Mail Transfer Protocol
 
Smtp
SmtpSmtp
Smtp
 
Smart Card
Smart CardSmart Card
Smart Card
 
LUMA's State of Digital Media at DMS 16
LUMA's State of Digital Media at DMS 16LUMA's State of Digital Media at DMS 16
LUMA's State of Digital Media at DMS 16
 
Pop up design and paper mechanics
Pop up design and paper mechanicsPop up design and paper mechanics
Pop up design and paper mechanics
 
Edi ppt
Edi pptEdi ppt
Edi ppt
 
Electronic payment system
Electronic payment systemElectronic payment system
Electronic payment system
 
Information technology act 2000
Information technology act 2000Information technology act 2000
Information technology act 2000
 
Introduction to RF & Wireless - Part 2
Introduction to RF & Wireless - Part 2Introduction to RF & Wireless - Part 2
Introduction to RF & Wireless - Part 2
 
FireWall
FireWallFireWall
FireWall
 
Domain Specific Languages in Ruby - Medellin.rb
Domain Specific Languages in Ruby - Medellin.rbDomain Specific Languages in Ruby - Medellin.rb
Domain Specific Languages in Ruby - Medellin.rb
 
Security in E-commerce
Security in E-commerceSecurity in E-commerce
Security in E-commerce
 
Digital transformation in 50 soundbites
Digital transformation in 50 soundbitesDigital transformation in 50 soundbites
Digital transformation in 50 soundbites
 

Similar a DSL Construction rith Ruby

DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009Harshal Hayatnagarkar
 
Os Alrubaie Ruby
Os Alrubaie RubyOs Alrubaie Ruby
Os Alrubaie Rubyoscon2007
 
Open Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkOpen Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkMushon Zer-Aviv
 
EKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfEKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfArnaud Bouchez
 
Domain Specific Languages
Domain Specific LanguagesDomain Specific Languages
Domain Specific LanguagesLakshan Perera
 
Bdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проектеBdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проектеISsoft
 
Challenges In Dsl Design
Challenges In Dsl DesignChallenges In Dsl Design
Challenges In Dsl DesignSven Efftinge
 
Iron* - An Introduction to Getting Dynamic on .NET
Iron* - An Introduction to Getting Dynamic on .NETIron* - An Introduction to Getting Dynamic on .NET
Iron* - An Introduction to Getting Dynamic on .NETKristian Kristensen
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?C4Media
 
Beyond Sharing: Open Source Design
Beyond Sharing: Open Source DesignBeyond Sharing: Open Source Design
Beyond Sharing: Open Source DesignMushon Zer-Aviv
 
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesSchwannden Kuo
 
Designing and Implementing Search Solutions
Designing and Implementing Search SolutionsDesigning and Implementing Search Solutions
Designing and Implementing Search SolutionsFindwise
 
Elasticsearch Basics
Elasticsearch BasicsElasticsearch Basics
Elasticsearch BasicsShifa Khan
 

Similar a DSL Construction rith Ruby (20)

DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
DSL Construction with Ruby - ThoughtWorks Masterclass Series 2009
 
Os Alrubaie Ruby
Os Alrubaie RubyOs Alrubaie Ruby
Os Alrubaie Ruby
 
Open Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talkOpen Source Design at Ignite lightning talk
Open Source Design at Ignite lightning talk
 
EKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdfEKON27-FrameworksExpressiveness.pdf
EKON27-FrameworksExpressiveness.pdf
 
Domain Specific Languages
Domain Specific LanguagesDomain Specific Languages
Domain Specific Languages
 
Bdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проектеBdd and dsl как способ построения коммуникации на проекте
Bdd and dsl как способ построения коммуникации на проекте
 
Jax keynote
Jax keynoteJax keynote
Jax keynote
 
Ruby and Security
Ruby and SecurityRuby and Security
Ruby and Security
 
Challenges In Dsl Design
Challenges In Dsl DesignChallenges In Dsl Design
Challenges In Dsl Design
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
Text mining and Visualizations
Text mining  and VisualizationsText mining  and Visualizations
Text mining and Visualizations
 
Iron* - An Introduction to Getting Dynamic on .NET
Iron* - An Introduction to Getting Dynamic on .NETIron* - An Introduction to Getting Dynamic on .NET
Iron* - An Introduction to Getting Dynamic on .NET
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?
 
Beyond Sharing: Open Source Design
Beyond Sharing: Open Source DesignBeyond Sharing: Open Source Design
Beyond Sharing: Open Source Design
 
GroovyDSLs
GroovyDSLsGroovyDSLs
GroovyDSLs
 
Metamorphic Domain-Specific Languages
Metamorphic Domain-Specific LanguagesMetamorphic Domain-Specific Languages
Metamorphic Domain-Specific Languages
 
PL Lecture 01 - preliminaries
PL Lecture 01 - preliminariesPL Lecture 01 - preliminaries
PL Lecture 01 - preliminaries
 
Cucumber
CucumberCucumber
Cucumber
 
Designing and Implementing Search Solutions
Designing and Implementing Search SolutionsDesigning and Implementing Search Solutions
Designing and Implementing Search Solutions
 
Elasticsearch Basics
Elasticsearch BasicsElasticsearch Basics
Elasticsearch Basics
 

Más de ThoughtWorks

Online and Publishing casestudies
Online and Publishing casestudiesOnline and Publishing casestudies
Online and Publishing casestudiesThoughtWorks
 
Insurecom Case Study
Insurecom Case StudyInsurecom Case Study
Insurecom Case StudyThoughtWorks
 
Grameen Case Study
Grameen Case StudyGrameen Case Study
Grameen Case StudyThoughtWorks
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesThoughtWorks
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in RubyThoughtWorks
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiThoughtWorks
 
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank... Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...ThoughtWorks
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices ThoughtWorks
 
Present and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniPresent and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniThoughtWorks
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThoughtWorks
 
Ruby 124C41+ - Matz
Ruby 124C41+  - MatzRuby 124C41+  - Matz
Ruby 124C41+ - MatzThoughtWorks
 
Mac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimMac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimThoughtWorks
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SThoughtWorks
 
Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta ThoughtWorks
 
Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew ThoughtWorks
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkThoughtWorks
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone DevelopmentThoughtWorks
 

Más de ThoughtWorks (20)

Online and Publishing casestudies
Online and Publishing casestudiesOnline and Publishing casestudies
Online and Publishing casestudies
 
Insurecom Case Study
Insurecom Case StudyInsurecom Case Study
Insurecom Case Study
 
Grameen Case Study
Grameen Case StudyGrameen Case Study
Grameen Case Study
 
BFSI Case Sudies
BFSI Case SudiesBFSI Case Sudies
BFSI Case Sudies
 
Construction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific LanguagesConstruction Techniques For Domain Specific Languages
Construction Techniques For Domain Specific Languages
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Concurrency patterns in Ruby
Concurrency patterns in RubyConcurrency patterns in Ruby
Concurrency patterns in Ruby
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagi
 
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank... Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
Ruby on Rails versus Django - A newbie Web Developer's Perspective -Shreyank...
 
Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices Nick Sieger-Exploring Rails 3 Through Choices
Nick Sieger-Exploring Rails 3 Through Choices
 
Present and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola biniPresent and Future of Programming Languages - ola bini
Present and Future of Programming Languages - ola bini
 
The ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj KumarThe ruby on rails i18n core api-Neeraj Kumar
The ruby on rails i18n core api-Neeraj Kumar
 
Ruby 124C41+ - Matz
Ruby 124C41+  - MatzRuby 124C41+  - Matz
Ruby 124C41+ - Matz
 
Mac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. LimMac ruby to the max - Brendan G. Lim
Mac ruby to the max - Brendan G. Lim
 
Project Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G SProject Fedena and Why Ruby on Rails - ArvindArvind G S
Project Fedena and Why Ruby on Rails - ArvindArvind G S
 
Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta Glass fish rubyconf-india-2010-Arun gupta
Glass fish rubyconf-india-2010-Arun gupta
 
Aman kingrubyoo pnew
Aman kingrubyoo pnew Aman kingrubyoo pnew
Aman kingrubyoo pnew
 
HadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software FrameworkHadoopThe Hadoop Java Software Framework
HadoopThe Hadoop Java Software Framework
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
Cloud Computing
Cloud  ComputingCloud  Computing
Cloud Computing
 

Último

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Último (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

DSL Construction rith Ruby

  • 1.
  • 2. goals •  DSL Fundamentals •  Some Ruby Basics •  DSL construction with Ruby •  Advanced Topics - A step further •  Summary •  Q&A
  • 3. problem? Problem Customer reduce the gap Programmer Solution
  • 5.
  • 6. evolution Problem ? Object Oriented C++ Java expressive GAP Procedural C Assembly Emergence of language 100101010 Solution
  • 7. the power of language •  Arm Ball •  Around the wicket •  Cow Corner •  Duck •  Fly Slip •  Googly http://en.wikipedia.org/wiki/List_of_cricket_terms - an long list of cricket terms
  • 8. evolution Problem DSL Object Oriented C++ Java expressive GAP Procedural C Assembly Emergence of language 100101010 Solution
  • 9. example Monit – automatic management and monitoring - http://mmonit.com/
  • 10. definition a computer programming language of limited expressiveness focused on a particular domain - Martin Fowler Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
  • 11. definition a computer programming language of limited expressiveness focused on a particular domain - Martin Fowler Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
  • 12. definition a computer programming language of limited expressiveness focused on a particular domain - Martin Fowler Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
  • 13. definition a computer programming language of limited expressiveness focused on a particular domain - Martin Fowler Martin Fowlers book on DSLs - http://martinfowler.com/dslwip/
  • 14. Domain Specific Languages vs. General Purpose Languages
  • 15. what DSLs bring to the table •  Quality •  Productivity •  Reliability •  Maintainability •  Reusability
  • 16. what DSLs bring to the table •  Quality •  Productivity •  Reliability •  Maintainability •  Reusability •  Social impact
  • 17. what DSLs bring to the table •  Quality •  Productivity •  Reliability •  Maintainability •  Reusability •  Social impact •  Validation at the domain level
  • 19. no silver bullet! •  Learning curve
  • 20. no silver bullet! •  Learning curve •  Good language design is hard
  • 21. no silver bullet! •  Learning curve •  Good language design is hard •  Cost of building
  • 22. no silver bullet! •  Learning curve •  Good language design is hard •  Cost of building •  Limited applicability
  • 23. no silver bullet! •  Learning curve •  Good language design is hard •  Cost of building •  Limited applicability •  Maintenance
  • 24. no silver bullet! •  Learning curve •  Good language design is hard •  Cost of building •  Limited applicability •  Maintenance •  Could be overused or abused
  • 26. external DSL Need to build a parser to process the custom syntax sql, make files, xml config files, regular expressions
  • 27. advantages •  Free to use any syntax
  • 28. advantages •  Free to use any syntax •  Run time evaluation
  • 29. disadvantages •  Starts simple, can get ugly and complex
  • 30. disadvantages •  Starts simple, can get ugly and complex •  Building parsers is difficult
  • 31. disadvantages •  Starts simple, can get ugly and complex •  Building parsers is difficult •  Lack of tooling support
  • 32. internal DSL Extends the host language
  • 33. advantages •  Don't have to write and debug a new language
  • 34. advantages •  Don't have to write and debug a new language •  Full power of base language is available
  • 35. advantages •  Don't have to write and debug a new language •  Full power of base language is available •  Tooling support available
  • 37. Ruby based DSLs are internal
  • 38. DSLs - not special to Ruby
  • 40. why is ruby special •  minimally intrusive Syntax to allow for more concise code
  • 41. why is ruby special •  minimally intrusive Syntax to allow for more concise code •  Ruby culture - values expressiveness in code
  • 42. why is ruby special •  minimally intrusive Syntax to allow for more concise code •  Ruby culture - values expressiveness in code •  Dynamic and Reflective
  • 43. * Working code writing using RSpec, a testing frame work
  • 46.
  • 47. vs.
  • 49. or
  • 51.
  • 53.
  • 55.
  • 56.
  • 57.
  • 59. define_method eval alias_method module_eval class_eval instance_eval
  • 60. ‘whenever’ a DSL for cron jobs 30 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * reboot http://github.com/javan/whenever
  • 61. language constructs year hour month sunday day reboot monday weekend a.m weekday p.m
  • 62. expressive 30 4 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * * reboot http://github.com/javan/whenever
  • 63. The fascinating thing is that, in my experience, most well-written Ruby programs are already a DSL, just by nature of Ruby’s syntax.” - Jamis Buck, 37signals
  • 64. Writing DSLs in Ruby THE PROCESS
  • 65. Application Programming Interface Example 1 try { Socket client = new Socket(“www.google.com”,80); } catch(IOException e) { System.out.println(e); }
  • 66. Application Programming Interface Example 1 try { Socket client = new Socket(“www.google.com”,80); } catch(IOException e) { System.out.println(e); } Example 2 Customer.find :all, :condition => [ :age >= 25 ]
  • 67. Application Programming Interface Example 1 try { Socket client = new Socket(“www.google.com”,80); } catch(IOException e) { System.out.println(e); } Example 2 Customer.find :all, :condition => [ :age >= 25 ] •  Libraries give a sense of domain-specificity because of vocabulary •  Nouns / verbs / adverbs / adjectives
  • 68. Application Programming Interface Example 1 try { Socket client = new Socket(“www.google.com”,80); } catch(IOException e) { System.out.println(e); } Example 2 Customer.find :all, :condition => [ :age >= 25 ] •  Libraries give a sense of domain-specificity because of vocabulary •  Nouns / verbs / adverbs / adjectives •  They are all internal DSLs
  • 69. Patterns Interfaces Abstractions DSL “But, I believe a DSL is a healthy bi-product of a good object-oriented design.” Blaine Buxton (Smalltalk developer)
  • 70. Internal DSLs – A coarse process Capture vocabulary and processes of the domain Discover desired syntax Define DSL interface (API) Define classes and abstractions Implement validations
  • 71. Capture vocabulary •  Task scheduling is the domain of ‘cron’ •  Tasks •  Timing •  Frequency
  • 72. Capture vocabulary •  Task scheduling is the domain of ‘cron’ •  Tasks (e.g. ‘reboot’, ‘send mail’, ‘alert’, etc) •  Timing (e.g. ‘5 pm’, ‘4.30 am’, etc) •  Frequency (e.g. ‘yearly’, ‘weekend’, etc)
  • 73. Capture vocabulary •  Task scheduling is the domain of ‘cron’ •  Tasks (e.g. ‘reboot’, ‘send mail’, ‘alert’, etc) •  Timing (e.g. ‘5 pm’, ‘4.30.am’, etc) •  Frequency (e.g. ‘yearly’, ‘weekend’, etc) •  Discover keywords •  Special words (‘yearly’, ‘reboot’, etc) •  Domain values (‘5 pm’, etc) •  A good design would decide ownership of these keywords annually year at hourly month sunday runner monday day reboot every a.m. weekend weekday p.m.
  • 74. Discover syntax Experiment around keywords Write extended Design a methods syntax (e.g. 2.days) Discuss with DSL user Define Define ownership constructs of keywords
  • 75. Design considerations •  “Follow good design principles” –  Entities as classes •  As nouns –  Operations as methods •  Typically as verbs •  Adaptive interfaces (wrappers) to instantiate aggregations •  Accept hash as argument to simulate ‘call by name’
  • 76. Purpose Ruby feature (what) (how) Function calls w/o Getter/setter parentheses Pattern matching Regular expressions Using Ruby features to realize Alternative interfaces ‘alias_method’ DSL constructs Context Closure/block Code generation Strings Execution ‘load’, ‘require’, ‘eval’ Arbitrary interfaces/ ‘method_missing’ attributes
  • 77. Writing ‘Whenever’ every 2.days, :at => '4:30 am‘ do runner “/usr/bin/reboot” end
  • 78. Writing ‘Whenever’ every 2.days, :at => '4:30 am‘ do runner “/usr/bin/reboot” end every(2.days(),{:at => '4:30 am’}) do runner(“/usr/bin/reboot”) end
  • 79. Writing ‘Whenever’ 2.days() Class JobList def every(frequency, option={}) … yield #handles block end { :at => ‘4.30.am ‘ } def runner(task, options={}) … end end
  • 80. Real examples A TALE OF TWO DSLS
  • 81. EXAMPLE 1: DSL FOR GMRT
  • 82. Giant Metrewave Radio Telescope System 30 Antennae http://gmrt.ncra.tifr.res.in
  • 83. GMRT Prototype •  Objective –  Re-engineering ‘ABC’ and ‘Teleset’ –  Collaboration among TCS, NCRA and CoEP •  Challenges –  Scientists need a simple, extensible interface to •  Monitor and control antennae •  Schedule experiments •  Approach –  ABC as collection of Rails web services –  Teleset re-designed as a Ruby DSL
  • 84. ‘Teleset’ as DSL: Version 1.0 a1 = AntennaClient.new (“http://antenna1”) a1.reboot a1.monitor 2.mhz Single antenna
  • 85. ‘Teleset’ as DSL : Version 1.1 Single antenna a1 = AntennaClient.new (“http://antenna1”) a1.reboot a1.monitor 2.mhz Simultaneously, Complex !!! for antennae a1 and a2 engine.register_participant :antenna do | antenna | reboot monitor 2.mhz end concurrent_iterator on_value => [:a1,:a2], to_variable => ‘antenna’ do participant :antenna => ’${antenna}’ end #Using openwferu engine http://openwferu.rubyforge.org - Using OpenWFEru Workflow engine
  • 86. ‘Teleset’ as DSL : Version 2.0 Suggested prototype with antenna :a1, :a2 do reboot monitor 2.mhz Much simpler ! end engine.register_participant :antenna do | antenna | reboot monitor 2.mhz end concurrent_iterator on_value => [:a1,:a2], to_variable => ‘antenna’ do participant :antenna => ’${antenna}’ end
  • 87. EXAMPLE 2: DSL FOR VISUALIZATION
  • 88. DSL for visualization •  Objective –  A specification-driven dashboard •  Visualization metaphors (charts, data grids, etc) •  Organization using layouts (window, tab, portal, etc) •  Navigation (page flows) •  Challenge –  Consistent API –  Integration with other components and environment •  Ruby was chosen
  • 89.
  • 90.
  • 91. application ‘ThoughtWorks MCS Demo’ do add grid ‘Actors list’ do data_source table do table_name ‘actor’ end # data_source end # grid end # application
  • 92. application ‘Thoughtworks MCS Demo’ do add grid ‘Actors list’ do data_source table do table_name ‘actor’ end # data_source add view ‘Show movies’ do | actor | add grid “Movies for actor #{actor}” do data_source query do text “SELECT … WHERE actor_id=#{actor.actor_id}” end # data_source end # grid end # view end # grid end # application
  • 93.
  • 95. Evolution of a DSL •  Generalization versus specialization •  “expressiveness x scope = constant” [3] expressiveness External Internal DSL DSL DSLs scope scope ASM GPL GPL expressiveness
  • 96. Three aspects Domain Domain-specific aspect Language Language Specification aspect aspect
  • 97. Three aspects Domain Specification Language •  CRUD of •  Conditionality (if/ •  Natural •  Domain entities switch) •  Syntactic noise •  Relationships •  Automation •  Semantic noise •  Processes (loops) •  Constraints •  Reusability (function/classes) •  Data structures •  Error handling
  • 98. Three aspects Domain Specification Language •  CRUD of •  Conditionality (if/ •  Natural •  Domain entities switch) •  Syntactic noise •  Relationships •  Automation •  Semantic noise •  Processes (loops) •  Constraints •  Reusability (function/classes) •  Data structures •  Error handling
  • 99. Three aspects Domain Specification Language •  CRUD of •  Conditionality (if/ •  Natural •  Domain entities switch) •  Syntactic noise •  Relationships •  Automation •  Semantic noise •  Processes (loops) •  Constraints •  Reusability (function/classes) •  Data structures •  Error handling
  • 100. Evolution of a DSL Specialization (inheritance) Reusability Conditions and loops Entities (+ relationships) Entities (numbers + strings)
  • 101. Crossroads and crosswords •  “No domain is an island” •  Interoperability in DSLs •  DSLs need to talk one-another •  Achilles’ Heel for external DSLs •  Parallel development of different DSLs needs early standardization •  Chicken-egg problem
  • 102. Future of DSLs •  UML and DSL •  DSL as front-end to UML (or alternative)[5] Book “MDA Distilled” (page 16)
  • 103. Future of DSLs •  UML and DSL •  DSL as front-end to UML (or alternative)[5] •  High assurance systems •  Minimal code, relevant code
  • 104. Future of DSLs •  UML and DSL •  DSL as front-end to UML (or alternative)[5] •  High assurance systems •  Minimal code, relevant code •  Multi-core revolution •  Multi-threading •  Message passing The Free Lunch Is Over – Herb Sutter’s article on Multi-core Revolution
  • 105. References and resources 1.  Interview of Bjarne Stroustrup 2.  Presentation by Martin Fowler (at InfoQ.com) 3.  Domain-Specific Languages in Perspective 4.  A Picture is Worth a 1000 Words? 5.  Book “MDA Distilled” (page 16) 6.  The Free Lunch Is Over
  • 106. Language Design Library Design is is Library Design Language Design Bjarne Stroustrup [1]