a fluent interface for numeric literals

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.

Advertisements

One thought on “a fluent interface for numeric literals

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