I came across two interesting items on the web today. The first was Rocky Lhotka’s mCSLA series in which he presents a DSL over CSLA. I know, I know but let’s put our opinions about CSLA aside and look at the really important point. Here is a sample of Rocky’s DSL
Object Customer in Test
{
Allow Create{“Clerk”};
Allow Edit{“Clerk”};
Allow Delete{“Clerk”};
Public ReadOnly int id;
Public string Name{
Allow Write {“Clerk”};
Rule StringRequired;
Rule StringMaxLength{50};
}
} Identity Id;
Altogether, about 10 significant lines of code written. I’m going to let that simmer for a while and move to the second post of interest. This time from Uncle Bob. In this post, Uncle Bob points out that it costs about $11 per SLOC and points to a sample line of code:
StringBuffer nameBuffer = new StringBuffer();
So let’s look back at Rocky’s code (and I highly recommend watching the video). There’s a helluva lot more embedded in Allow Create{“Clerk”} than in StringBuffer nameBuffer=new StringBuffer();
That one line:
- Tells Rocky’s framework to give the “Clerk” role permission to create a Customer object
- Wires up the UI (although very rudimentary) to create a new Customer
- Handles all the plumbing to save the Customer to the database
On top of all this, the code is generated CONSISTENTLY. So you don’t have to worry whether Uncle Bob remembered to dispose of his database connection, because once you program the framework to handle it, that’s the way it’s done. I would guess that each of those bullets would take an average of 7 lines of code to write by hand (that’s not even counting unit tests). 21 lines of code replaced by one. If this doesn’t sell the value of software factories to you, I don’t know what will.