Program Comprehension – Three Techniques for Zeroing In
In the next few posts I’m going to cover in some detail three of the techniques that have been developed for zeroing in on functionality when maintaining programs. I think these techniques are all potentially useful to RPG maintenance programmers who must maintain large, complex RPG programs on the AS/400, iSeries they are not totally familiar with:
- Program Slicing
- Concept Assignment
- Key Statement Analysis
Program slicing is the process of slicing away portions of the program you are not concerned with. The process usually begins once you have located a statement that sets a particular variable you are interested in. To understand what data may be flowing into that variable and under what conditions, you work backward finding all possible paths that may lead to that statement and all possible values that may be feeding into it. Statements that are not on none of the paths are “sliced away” effectively leaving in the mind of the programmer, a program-within-a-program – a subset of the entire program. Forward slicing can also be done, which serves as a means of impact analysis for source code changes. Most experienced maintenance programmers engage in program slicing intuitively, though good source exploration tools can greatly facilitate the process.
Concept Assignment is the mapping of the programmer’s real world knowledge to specific source statements in a program. For example, the programmer may understand the business concept that “we only give refunds in the first 30 days after a sale.” Based on a task given to the programmer, he or she may then attempt to attach that concept to particular source statements. The systematic process of Concept Assignment involves locating indicators in the source code that seem to signal the presence of the target concept. In this example, the programmer may make a list of database files or fields that he or she knows to be involved with refunds, and then engage in systematic searches of the code to find those indicators. Typical signals are such things as fields, the applied use of naming conventions and programming standards, comments and so on. As signals are located and their containing statements are confirmed as relevant, those statements are “attached” to the concept. Again, most experienced programmers engage in this activity intuitively, and a good source explorer tool can facilitate.
Key Statement Analysis is an attempt to automatically find the most impactful or essential statements in a program or module. For a program being analyzed this would typically begin by inventorying the fields that are output. For each of these fields the last statement that sets them prior to output is located. For each of these statements backward slices are formed – these slices are comprised of sets of statements. After all the sets of statements from all the slices from all the fields are gathered, the complete set of statements is analyzed for frequency and some form of Pareto analysis is used to identify the key statements in the program. Key Statement Analysis is probably not practical as a manual operation but requires a tool to automate the calculations.
Tomorrow: more on Program Slicing