FILES: Consulting, Applications, CodeGen, Languages,

Automatic Code Generation Techniques

Creating programs that write,
or help write,
other programs.

Copyright (C) 1995, J Consultants
Call me, I can help. 408-705-2284
j@mall-net.com

Wherever large sections of code have the potential to be similar in some aspects, it often pays to look at ways of generating this code via automation techniques.

This point of view is not always appreciated before the fact, as most American Programmers tend to believe in producing actual code rather than analyzing specifications and descriptions for similarities, and in working at coding, rather than thinking about structure. This is particularly true when deadlines are unlikely to be met by the very conventional techniques they favor.

Does it make more sense to pursue techniques which can not succeed? Or to seek out more favorable alternatives? I think a small investment in the latter is often prudent.

The code generators are by necessity "one-off" in nature, and are quite often discarded once they have produced the final code. Often, it is believed that the newly generated code can best be maintained via more conventional techniques, and larger extensions are not contemplated. Other times, this due to the belief that this was some special case, a fluke; and that "if this worked more often, we'd all be using it."

Nevertheless, during the implementation phase, the ability to regenerate some large portion of code in a matter of hours or days in response to each specification change, often becomes a motivating factor for the organization of the specification into a new level of clarity. While this is very often worthwhile in itself, it often brings the specification into a form facilitating the use of tables. These tables can often be generated from the rule base core of the code generator by changing a portion of the code generator.

The process usually involves several phases:

Although the prototype may take a day or two, the process tends to take longer. It is not that the prototype or final generator takes very long to make; but when the people creating the specification see that changes can often be implemented in a matter of a day or two, they begin to feel it reasonable make more changes to the specification in response to other needs they have been holing back on. Also, the ability to produce code often results in it becoming apparent much earlier in a project, that what was initially desired, may not adequately reflect the needs of the end users or the needs or capabilities of other groups involved in the project.

The kinds of languages usually chosen are output oriented. Word processor mail merge packages or text runoff packages are more useful where there is more variation in the theme, with more code being generated. In contrast, while database packages can handle more variables, they generally require more work for each code fragment. The two can often be combined to some extent.

Code Generation vs Process Tables:

Each approach has it's merits. But remember, it is often possible to use the rule portion of a code generator to generate a table if the system evolves towards a more orthogonal design. The advantage is that the rule set has already been (more or less) proven.


A Few Sample Cases:

A portion of the HTML code used in the main index structure of Mall-Net, the HOT LISTS, is handled by database code produced by a code generator; a double expansion of sorts.
Copyright (C) 1996, j@mall-net.com
Call me, I can help. 408-705-2284
FILES: JV: Apps Table, CodeGen, Lang,

Copyright (C) 1996, J Consultants