Code Generation - Letting the computer do the repetitive work.

Code generation is in use all over the software industry:

Every person I have talked to in this industry has used code generation in some form. Very few understand the true power of good code generation.

Good Code Generation -

Each of the tools above has some of these characteristics. Other than the ones I have built and used very successfully I have yet to see a commercially available code generator that has all of these abilities.

Object oriented application frameworks are intended to provide a basis for creating business objects. Traditionally, there would be base classes and developers would create derived classes that have all of the code to process the specific types of data. Many tasks like persisting data in databases and passing data between object tiers and simple validation (numeric ranges, date ranges, value lists, etc.) require very similar code in every single business object. A developer can create additional base class functionality and use meta data to make decisions at runtime to select the correct routines for each attribute. This methodology is processor and memory intensive and does not scale to large applications well. By using code generation all of this code and all of the decisions can be produced at compile time mechanically. The developer can then spend their time writing the business logic that is beyond the scope of the code generation.

Rather than describing many different projects I have used code generation to reduce initial development, maintenance and stability, I am going to describe a how a typical project uses code generation.

  1. Gather Requirements.
  2. Identify capabilities for base classes.
  3. Identify capabilities for code generated classes.
  4. Create and test base classes.
  5. Create object model for code generation - Rose, a database, XML, etc.
  6. Create template code for code generation.
  7. Generate test objects and debug template code.
  8. Generate full object model.
  9. Insert business logic into generated objects.
  10. Debug business objects
    1. Bugs in generated portion of code are fixed in templates and whole system is regenerated.
    2. Bugs in business logic are fixed where they occur.

I have used this model on multiple projects which has allowed three or less developers to create and maintain systems in excess of 1 million lines. These systems have scaled from small systems in Windows to huge systems on UNIX without any significant problems.


Copyright 2001 Paul Rubin