silk and spinach

development, by example

a fluent interface for numeric literals

with one comment

In The Cardinality of a Fluent Interface Michael Feathers posed a code kata in which one has to create a DSL in which constructs such as the following all provide the expected numeric value:

    one
    two
    twelve
    twelve.hundred
    one.hundred.thousand.and.fifteen
    twelve.hundred.and.one
    five.hundred.and.fifty.seven

My first pass at a solution in Ruby is available on github. There’s still some duplication in there, and hopefully I’ll get around to removing it soon.

In his post, Mike asks whether the DSL’s “cardinality” — the number of classes required to implement the DSL — says anything about the DSL’s grammar. Well, my solution has 7 classes (although PartialValue exists only to remove a little duplication). I have no idea what that might mean in the DSL world.

Update 21-may-09:
You can get the code from the github repository.

Written by Kevin Rutherford

December 19, 2007 at 2:25 pm

Posted in kata, ruby

One Response

Subscribe to comments with RSS.

  1. Hi Kevin,

    Paul from Agile Scotland here. I’ve had a shot too. Here’s mine.

    Paul Wilson

    December 22, 2007 at 11:14 pm


Leave a Reply