Domain specific languages

1,296 views
1,187 views

Published on

Quick introductory to Domain Specific Languages session done at the Software Craftsmanship in Israel meetup

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,296
On SlideShare
0
From Embeds
0
Number of Embeds
187
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • An internal DSL is one that uses the infrastructure of an existing programming language(also called the host language of the DSL) to build domain-specific semanticson top of it. One of the most popular internal DSLs used today is Rails, which is implementedon top of the Ruby programming language. When you write Rails code,you’re programming in Ruby, based on the semantics that Rails implements for developingweb applications. In most cases, an internal DSL is implemented as a library ontop of the existing host language.An external DSL is one that’s developed ground-up and has separate infrastructure forlexical analysis, parsing techniques, interpretation, compilation, and code generation.Developing an external DSL is similar to implementing a new language fromscratch with its own syntax and semantics. Build tools like make, parser generators likeYACC, and lexical analysis tools like LEX are examples of popular external DSLs.
  • Fromhttp://en.wikipedia.org/wiki/Fluent_interface
  • Domain specific languages

    1. 1. Domain Specific Languages<br />Dror Helper<br />
    2. 2. About.Me<br />Software developer <br />Blogger (http://blog.drorhelper.com)<br />Language geek<br />
    3. 3. What do they mean?<br />Bug<br />Feature<br />Release Candidate<br />Show stopper<br />“The next release candidate would contain features X, Y & Z and no more than 5 high priority Bugsandno show stoppers”<br />
    4. 4. Agenda<br />Why should I use DSLs<br />Domain Specific Languages<br />Fluent interface<br />
    5. 5. Domain Specific Languages<br />created specifically to solve problems in a particular domain<br />Layer of abstraction on top of an existing domain model<br />Can be used by domain experts<br />
    6. 6. DSL classification<br />External vs. Internal<br />Textual vs. Graphic<br />
    7. 7. Graphical DSLs<br />
    8. 8. External DSLs<br />SELECTBook.title, count(*) ASAuthors FROMBook JOINBook_authorONBook.isbn = Book_author.isbnGROUPBYBook.title;<br /><([A-Z][A-Z0-9]*)b[^>]*>(.*?)</1><br />buyIBM @ 100 forNOMURA sellGOOGLE @ limitprice= 70 for CHASE<br />
    9. 9. Internal DSLs<br />Built on top of an existing language<br />Use languages like Ruby, Python, BOO<br />
    10. 10. Fluent interfaces<br />coined by Eric Evans and Martin Fowler<br />An OOP API that aims to provide readable code<br />Use method chaining an pass context via return value<br /><ul><li>TimeIntervalmeetingTime = fiveOClock.until(sixOClock);
    11. 11. DateTime.Now.AddDays(7);  DateTime.Now.AddWeeks(1);</li></li></ul><li> Fluent Interfaces - Examples<br />
    12. 12. Fluent Interface design<br />Hide your working.<br />Keep your state to yourself.<br />Think really hard about names.<br />Take advantage of your implementation language.<br />If you have them, blocks are you friends.<br />Test first design can be a useful way of exploring what your interface should be.<br />Reasonable defaults.<br />
    13. 13. Tips & Tricks <br />Use Interfaces<br />Return different interface to change functionality<br />Generics are handy if user need to specify type<br />Lambda and delegates for custom functionality<br />
    14. 14. Books<br />DSLs in Action<br />DSLs in Boo<br />
    15. 15. The shopping cart <br />A Domain Specific exercise<br />
    16. 16. The Story<br />You need to create a simple rule engine that would enable developers to add custom rules to the company’s Shopping cart application.<br />
    17. 17. The engine<br />Three customer types: regular, preferred & VIP<br />Customer the following fields: <br />name <br />address<br />date of birth<br />The system tracks the customer’s purchases (date, amount)<br />Products can be on Sale (discount)<br />Discount changes according to rules<br />Each rule must have a customer type<br />
    18. 18. Usage examples<br />A VIP customer get 15% discount on all purchases<br />Buying product A would give you 10% discount on product B<br />Preferred and VIP customers can buy 5 + 1 of a specific product<br />All customers can get 20% off purchase using specific coupon<br />If amount of purchase > 100$ customer is entitled for 10% discount.<br />If customer have purchased > 100$ the last three months upgrade him to VIP<br />On the customer’s birthday he’s entitled to 50% discount<br />All customers living in New York can get up to 25% off all purchases<br />

    ×