Program Comprehension – Key Statements Analysis
The final technique for Program Comprehension I’m going to talk about is Key Statements Analysis (KSA). This is a process which requires some sort of automation as it involves a lot of computations. I am considering trying this out for Codelyzer.
KSA basically works by evaluating a large number of a program’s Program Slices. One KSA method is done by using the backward program slicing technique and another method is done by using the forward program slicing technique.
The KSA backward slice technique begins by identifying the set of variables that are output from the program plus the set of global variables, i.e., the “principal variables.” In the AS/400 RPG world, of course, the vast majority of legacy variables are global. However, a variable can be inferred to be truly global if its value is set in one subroutine and used in another. Once the full set of principal variables is defined, all the statements that set their values are assembled. For each of these statements the set of backward program slices is computed. For a given statement this means all possible paths through the program that lead to the statement are determined.
Once all statements in all paths, that lead to all the statements that set all the principal variables, are assembled (got that?) then the frequency with which each statement appears in this overall set is computed. This leads to a ranking of the importance of statements in the program, i.e., KSA from the backward method.
The KSA forward slice technique works by computing the forward slices of each statement in the program. In other words, all the possible downstream statements that are impacted by each statement. This essentially indicates the “impact footprint” of each statement in the program. Statements with the highest number of impacted statements on downstream paths are judged to be key statements.
Another approach useful in either forward or backward analysis is to summarize the results at the level of the subroutine or procedure. This leads to which subroutines are the most critical to the program’s execution. While this information is at a coarser level it may sometimes, in fact, be more useful for program comprehension.
A thorough description of KSA can be found in Evaluating Key Statement Analysis ($) by David Binkley, et al.
I think that this could be a useful method for comprehending large, unfamiliar RPG programs in the AS/400 world if there was a good tool to do the computations. Like I said, I may work on that for Codelyzer.