ICS 121: Code Generation and Reverse Engineering
Overview
- What is code generation?
- Why use code generation?
- What is reverse engineering?
- Why use reverse engineering?
What is code generation?
- Code generation is the process of using a tool that outputs
program source code based on some specification
- Popular types of code generation (characterized by the type of input
specification)
- Wizards: built into IDEs, prompt the user for choices, then
generates code and templates for the developer to fill in.
- UML tools: Reads a UML design, generates many class files with
templates for operations. Some can generate implementations of
state charts.
- Specification based: reads a custom file format and generates
code to implement that specification. E.g., torque reads an XML
specification of a database and outputs an SQL schema and Java
code to access that database.
- Record-and-playback: often used in testing, records keyboard
mouse events and generates script to repeat that test later
- Source-to-source: Reads a specification that is embedded in
source code (as javadoc tags) to generate related source code.
E.g, XDoclet and JUnitDoclet
Why use code generation?
- Usually it is better to build and use (better) libraries than to
generate large amounts of code
- Code generation is useful when:
- You are building a static GUI with standard widgets, e.g.,
a dialog box
- You must implement a large application program skeleton, e.g.,
MFC
- One body of code is just a "mirror" of other code, e.g., code
to load and save objects from the database
- UML or JUnitDoclet templates help automate the first steps of new code
development
- Very similar code must be generated for multiple platforms,
e.g., slightly different versions of an SQL schema for use with
different vendor's databases
- Often code generation is mainly done at one point in the
development process and then custom coding is done
- Often the generated code is hard to understand and maintain
What is reverse engineering?
- Reverse engineering is the process of reading code and
producing design documents.
- Examples:
- Use a GUI builder to edit a dialog box, then later open
that same file in the same GUI builder again.
- Use a UML tool to reverse engineer a UML design from source
code: ArgoUML
demo
- "Round-trip engineering" means that one tool can generate code,
and reverse engineer the same code that it generated. This can
sometimes work even if you edit the code with a text editor.
Why use reverse engineering?
- You are trying to understand code that was given to you
- You want to see how much your implementation has diverged from
your original design
- You are continuing to use a round-trip engineering tool like
Together Control Center
sample use case templateexample test plan templateProject plan template