DSL presentation at the local Software Craftsmanship group

A couple of days ago I gave a talk at the local Software Craftsmanship group on the subject of Domain Specific Languages (DSL) and fluent interfaces. After the session I prepared an exercise for the audience:
Create a fluent interface for an online shop that calculates discounts based on customer and purchase information.
I gave a list of use cases and waited to see what would happen:

  • 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

I was expecting API along these lines:

RuleEngine.CustomerOfType().GetDiscountOf(15);

The group was divided to teams of 2-3 developers choose a programming language and started working on my exercise. The first thing I’ve noticed is diversity in programming languages – C#, Java, C++ (on Linux!), Python and Ruby were used.
After a while it has become clear that the room was divided into two main groups of thought. Some teams started to design the object model required to solve the problem while other teams started implementing the rules and created the fluent interface from the required rule. This made me think about upfront design vs. iterative development. No one managed to complete the entire exercise but the teams that choose to design up front managed to cover less rules than the teams that created the rules one by one.
It was fun watching teams designing an API and then finding ways to create the API they wanted. I saw some interesting implementation ideas that were very different from what I had in mind in a good way.
All in all it was a good meet-up I can’t wait for the next time.

SCIL.DSL from Uri Lavi on Vimeo.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s