Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Practical Considerations
   for DSLs in Ruby

       Muness Alrubaie
      muness@gmail.com
      muness.blogspot.com

   ...
?
Ask!
What are we going to
   talk about?
Text


   A limited form of language
  suitable for a specific class of
            problems.




Domain Specific Language?
Venti half-caf, extra hot, no whip
              mocha




  DSL Example
Route 66, swinging, easy on
 the chorus, extra solo at the
 coda, and a bump at the end.




      Scattered, smothered,
 ...
... languages are not so much a
means of expressing truth that has
already been established, but are a
means of discoverin...
Declarative Programming
External vs. Internal
Consideration 1: Focused
Fluent Interfaces
Composing fluent
        interfaces
• Named Parameters
    calendar.add 'a conference call', :on => 'may
    3', :at => '4 ...
Consideration 2: End In Mind
Consideration 3: DRY
Consideration 4:
Be Context Sensitive
The fascinating thing is that, in my experience,
most well-written Ruby programs are already
a DSL, just by nature of Ruby...
Consideration 5:
Evolve into a DSL
Considerations

• Focused
• Begin with the End in Mind
• Don’t repeat your context
• Take advantage of run-time context
• ...
Resources
• Martin Fowler on:

   • Language Workbenches

   • Internal DSL Style

   • Fluent Interfaces

• Writing Domai...
?
                  session
                evaluations

              Muness Alrubaie
             muness@gmail.com
     ...
Os Alrubaie Ruby
Os Alrubaie Ruby
Os Alrubaie Ruby
Os Alrubaie Ruby
Os Alrubaie Ruby
Upcoming SlideShare
Loading in …5
×

Os Alrubaie Ruby

564 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Os Alrubaie Ruby

  1. 1. Practical Considerations for DSLs in Ruby Muness Alrubaie muness@gmail.com muness.blogspot.com ThoughtWorks www.thoughtworks.com
  2. 2. ? Ask!
  3. 3. What are we going to talk about?
  4. 4. Text A limited form of language suitable for a specific class of problems. Domain Specific Language?
  5. 5. Venti half-caf, extra hot, no whip mocha DSL Example
  6. 6. Route 66, swinging, easy on the chorus, extra solo at the coda, and a bump at the end. Scattered, smothered, covered. More examples
  7. 7. ... languages are not so much a means of expressing truth that has already been established, but are a means of discovering truth that was previously unknown. Their diversity is a diversity not of sounds and signs but of ways of looking at the world. Why?
  8. 8. Declarative Programming
  9. 9. External vs. Internal
  10. 10. Consideration 1: Focused
  11. 11. Fluent Interfaces
  12. 12. Composing fluent interfaces • Named Parameters calendar.add 'a conference call', :on => 'may 3', :at => '4 PM' • Method Chaining calendar.add('a conference call').on('May 3').at('4 PM') • Nested Calls calendar.add a('conference call').on('May 3').at('4 PM')
  13. 13. Consideration 2: End In Mind
  14. 14. Consideration 3: DRY
  15. 15. Consideration 4: Be Context Sensitive
  16. 16. The fascinating thing is that, in my experience, most well-written Ruby programs are already a DSL, just by nature of Ruby’s syntax. Symbols, blocks, optional parentheses around parameters—these all go a long way toward making Ruby programs read naturally. Additionally, a well-designed application encapsulates its problem domain, which also just happens to be a good metric for determining the effectiveness of a DSL. A DSL can be thought of as (and many cases, really is) an API for your application.
  17. 17. Consideration 5: Evolve into a DSL
  18. 18. Considerations • Focused • Begin with the End in Mind • Don’t repeat your context • Take advantage of run-time context • Evolve your implementation into DSL
  19. 19. Resources • Martin Fowler on: • Language Workbenches • Internal DSL Style • Fluent Interfaces • Writing Domain Specific Languages, Jamis Buck • Evolving an Embedded DSL in Java, Steve Freeman and Nat Pryce • Language Oriented Programming: The Next programming Paradigm, Sergey Dmitriev • Software Factories, Microsoft
  20. 20. ? session evaluations Muness Alrubaie muness@gmail.com muness.blogspot.com This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 2.5 License. http://creativecommons.org/licenses/by-nc-sa/2.5/

×