3. What do they mean? Bug Feature Release Candidate Show stopper “The next release candidate would contain features X, Y & Z and no more than 5 high priority Bugsandno show stoppers”
4. Agenda Why should I use DSLs Domain Specific Languages Fluent interface
5. Domain Specific Languages created specifically to solve problems in a particular domain Layer of abstraction on top of an existing domain model Can be used by domain experts
9. Internal DSLs Built on top of an existing language Use languages like Ruby, Python, BOO
10.
11.
12. Fluent Interface design Hide your working. Keep your state to yourself. Think really hard about names. Take advantage of your implementation language. If you have them, blocks are you friends. Test first design can be a useful way of exploring what your interface should be. Reasonable defaults.
13. Tips & Tricks Use Interfaces Return different interface to change functionality Generics are handy if user need to specify type Lambda and delegates for custom functionality
16. The Story You need to create a simple rule engine that would enable developers to add custom rules to the company’s Shopping cart application.
17. The engine Three customer types: regular, preferred & VIP Customer the following fields: name address date of birth The system tracks the customer’s purchases (date, amount) Products can be on Sale (discount) Discount changes according to rules Each rule must have a customer type
18. Usage examples A VIP customer get 15% discount on all purchases Buying product A would give you 10% discount on product B Preferred and VIP customers can buy 5 + 1 of a specific product All customers can get 20% off purchase using specific coupon If amount of purchase > 100$ customer is entitled for 10% discount. If customer have purchased > 100$ the last three months upgrade him to VIP On the customer’s birthday he’s entitled to 50% discount All customers living in New York can get up to 25% off all purchases
Notas del editor
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.