Novick Software
SQL Server Consulting Design Programming Tuning

  andy novick is a sql server mvp



Achieving Programmer Productivity using a Reusable Framework and Code Generation

This is good news.  The promise of the .Net, programmer productivity, can be achieved.  After my most recent project there is no doubt in my mind:  .Net is the most productive environment for application development that I've ever used.  The numbers are there to support this assertion.  Let me tell you how it works and then I'll show you some of the numbers at the end of this article.

There are two factors behind the programmer productivity:

  • The ease of building a reusable framework library through object oriented techniques
  • The ease of using code generation tools to build the business object/data access layers of the application.

The project that I'm using as a reference has built three applications in 8 months.  Much of that time was spent on building the WinForms framework that provides the foundation for the applications.  The business object layer provides an easily bindable object library that takes care of all of the data access.  98 percent of the code in this library was generated.  The rest was written to enforce business rules.

Figure 1 illustrates the architecture employed on these projects.  As you can see, the application uses the business object library and does not interact with the database directly.  It also uses various classes from the WinForms Application Framework (WFA) and has few interactions with the operating system or even with the .Net Framework.

Figure 1: Architecture of the WinForms Application Framework

Figure 2 shows where the code in the framework and business libraries came from.  It's a combination of hand written code, libraries supplied by Microsoft in the form of application blocks, and generated code.  The WFA has its own set of business objects that provide persistence of messages, security settings, and other objects that make up the framework.

Figure 2: Sources of WinForms Application Framework Code

The business object libraries use the CSLA design created by Rocky Lhotka and written about in his book Expert One-on-One Visual Basic Business Objects.  The code generation tool is ComExpress.  Shoutsoft, the maker of ComExpress includes their own somewhat modified version of the CSLA library that uses attributes on the business objects to dynamically generate SQL for data access.  It's an interesting approach and one that I've been able to turn to my advantage.  Using it I've been able to create a CSLA library that access a DB2 database hosted on a iSeries system.  And I've been able to make objects that are usually on DB2 work on SQL Server when the application is offline and using a replicated database.  I turns out to be neat trick. 

So where does the programmer productivity come from?  As you can see from Figure 2, the WFA Framework code has been written once and used with several applications.  We're on our third one now.  Like I said, the business objects were generated a process that took several hours of design time for about 70 objects using the code generation tool.  At the bottom of the figure are Microsoft Application Blocks  that come from Microsoft's Patterns and Practices web site and the CSLA code that came from Rocky's book and from the ComExpress tool.  Although the code generation tool costs money. Rocky's version of CSLA is free (FYI, CodeSmith has a free template for CLSA).  At the absolute bottom is the .Net Framework, which is part of the operating system.  The only code that has to be written for each new application is the application it self. 

Figure 3 shows the quantity of code that went to each of the boxes above.  I picked Application 1, which was the largest of the three.  As you can see, the application code makes up only 12% of the total code.  K LoC stands for thousand lines of code.

Figure 3: Quantity of Code in Each Framework Component


Finally, Figure 4 breaks the code down by how it was obtained.

Figure 4: Breakdown of the Code by Method of Creation


Eighty-eight percent of the next application doesn't have to be written by hand.  Of course, there may be a need for new business objects for the next application but the code generation approach using CSLA takes care of that.  What's more, because there are so many tasks that are already handled by the WinForms Application Framework, I can spend most of my time building the application and, I hope, making it better.



Personal Blog

New Tips:

Use dsinit to set the SQL Server instance for Windows Azure dev storage


Nov 7, '12
Loser: DB

Full Schedule