There are many types of code generators and techniques. Some of them low-level techniques that helps achieving some specific tasks. One example is language abstraction. Your high-level language is automatically translated-generated into low-level machine code. One example in Java world is JSP transformation into servlet. These generators generally invisible to the developers and can’t be considered as an automation in development.
The generators that provide automation are those generate final software that the software team develops. In business applications, final software is composed of elements like GUIs, business logic codes and database codes. Every elements of software may be taken into generators if you can capture template or pattern. Templates are some specification patterns that depend on your API set. Let’s say templates are meta-descriptions of your coding standards.
“To build a generator or use existing one” is one of the most discussed issue in your software team. Could we utilize the advantages of generators or could it be a wrong investment that ruin clean code base? Yes critical question lies behind the meaning of generated code for your team. If generated code value is high that it shortens development time by removing tedious repetitive tasks than it would be worth for investment.
Code generation can be applied in following way:
1- Determine what to generate: To find repetitive task is not hard in your development environment. If same things are done more than three times it is a candidate to generate. For example, generator experts recommend code generation for CRUD codes.
2- Capture meta-level coding structure: Capturing your meta-coding structure is important. Your coding structure should have a pattern that is shared among applications. What are the variable parts that would be parameterized by generator? How your GUI is constructed? In which way do you access database? How does your controller code manage object states? Capturing is the hardest part of the whole job. It requires understanding of the current development API set very well.
3- Build or configure your generator: There are many generators available there, but if not satisfied with them even you can write it yourself. After building it should be tested against current codes if anything is wrong. Generated code should be complete, concise and error-prone. Otherwise leaky generators make it impossible to benefit generation technology. Your coders would prefer manual way instead of wrestling your generators.
My generator recommendations:
Code Generation in Action
Generative Programming: Methods, Tools, and Applications