Wednesday, June 03, 2009

Power of Code generation

Code generation is so powerful technology, and it is been used for various purposes and various places, and code generation is not a new concept as well. In the past even though people have not used the same name they have used the same concepts. Normally any given code generation tool there are four parts, and number of steps and component may very from one component to other
  • Code generation configurations
  • Transformation
  • Transformation configuration
  • Code generation
Configuration can be a property file, XML file or datafile or any other kind of document, and most of the time configuration can be human readable. Next is the transformation, for the transformation it could either be something like XSL or simple logic in the scripts of class file to do the transformation. Finally creating artifacts as the results.

A classic example of code generation can be seen in the Web Service field, there people use code generation to generate service and client code from a WSDL. In that case the configuration file would WSDL, and the transformation would be WSDL to Java, and transformation option would be, web service framework, language and etc..., and finally the output would the either or both service skeleton and the stub.

One other powerful use case of code generation is testing, specially in the process of staging testing, where we have some SLA to meet. We generate the code (scripts and configurations) and then measure the results, if it does not meet the expectation then we change the code generation configuration and re-generate the code and measure the results. We do this process until we get the expected results, doing this kind of process manually is so hard as well as error prone.

The most difficult part of the code generation is to identify the requirements including the input configuration and output format. Once we have that code generation is easy, and once we have the code generation tool, doing testing is so easy.

Most of the time what people do is do the experiments(testing) manually in a very small scale, and then use those code and configuration to build a code generation tool.

1 comment:

Pengcheng said...

This is a very good article,