What Is Code Generation?

Code generators are software constructs that write software. It is code-writing code.

Code generation is a technique already common on development projects. The code wizards offered by most integrated development environments (IDE) are a form of template-driven code generation with which most of us are familiar. Other examples include the forward-engineering capabilities of modeling tools and the use of the Java decompiler (JAD) to reverse-engineer Java source from bytecode.

The use of code generation techniques is wide and varied, but code generators can be loosely categorized as either passive or active [Hunt, 1999].

Passive code generators.

These code generators are run once to provide the developer with a flying start. They produce code that the developer then modifies. Code wizards are an example of passive generators.

Active code generators.

Code generators that fall into the active category produce code that is continually regenerated throughout the project. The code produced is not modified by the developer and is overwritten each time the generator is run.

The distinction between active and passive code generation is a subtle one and essentially comes down to how the generated code is maintained over the course of the project. If the code generator is made part of the build process and generates fresh source each time a build is instigated, then we are using active generation. If the output from the same generator is taken by the software engineer, modified, and placed under source control, then we have passive code generation.

Both techniques can save time and effort, although the two techniques are applied quite differently. These next sections examine the uses of each type of code generation.

    Rapid J2EE Development. An Adaptive Foundation for Enterprise Applications
    Rapid J2EEв„ў Development: An Adaptive Foundation for Enterprise Applications
    ISBN: 0131472208
    EAN: 2147483647
    Year: 2005
    Pages: 159
    Authors: Alan Monnox

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net