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.

Domain specific languages

1,410 views

Published on

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

Published in: Technology
  • Be the first to comment

  • Be the first to like this

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 />

×