Subsections

2.2 Programming Knowledge

Among the many constituents of programming knowledge--for example, the operation of compilers and other tools, general data structure knowledge, and the capability of reasoning and abstracting--program plans and building blocks are two of the most important. As a series of interconnecting actions to achieve a goal [Soloway and Ehrlich, 1984,Rich and Waters, 1990], a program plan provides a skeleton structure for programs by abstracting key elements. Building blocks are the primitive elements provided by a programming language. They include basic statements of a programming language and reusable software components in repositories or libraries.


2.2.1 Program Plans

Considerable evidence exists in empirical studies of programming that program plans are the basic cognitive chunk used in program design and understanding [Soloway and Ehrlich, 1984,Rich and Waters, 1990]. Programs are often added one plan chunk at a time [Rist, 1995,Detienne, 1995]. Because program plans are abstract representations of a solution, during the process of programming, they need to be gradually fleshed out with building blocks. A program often contains different plans that are interlaced. Figure 2.2 shows a program and the program plans it uses. Program plans are hierarchical. A program plan at a higher abstraction level is built upon program plans of lower levels. For example, in Figure 2.2, the plan Shuffling an array comprises three other program plans: Loop over an array, Create a random number in a range, and Swap two numbers.

Figure 2.2: A program and its program plans

01	public class CardDealer{
02	static int [] cards = new int [52];
03	static { for (int i=0; i<52; i++) cards[i]=i; }
04	/** create a random number in a range */
05	public static int getRandomNumber (int from, int to) {
06	    return ((int)(Math.random() * (to - from)) + from);
07	}
08	/** shuffle the cards */
09	public static void shuffleCards() {
10	int r, temp;
11	for (int i=0; i<52; i++) {
12	    r = getRandomNumber(i, 52);
13	    temp = cards[i];
14	    cards[i] = cards[r];
15	    cards[r] = temp:
16	    }
17	}
18	public static void main(String[] args) {
19	    shuffleCards();
20	    for (int=0; i<52; i++) {
21	    System.out.print(`` `` + cards[i]);
22	    }
23  }
24  }
The above program contains following program plans:
Plan Name Plan Description Lines Realizing the Plan
Create a random number in a range Get the range;

Convert a random number between [0, 1.0] to the range.

5,7
Swap two numbers Save one data to a temporary variable;

Move the other data to the saved data;

Move the temporary variable to the other data.

13-15
Loop over an array Initialize;

Set the ending condition;

Perform operations;

Increase the loop variable.

11-16;

20-22

Shuffling an array Loop over an array;

Create a random number in a range;

Swap two numbers.

11-16

2.2.2 Building Blocks

Although programmers can build a program with only the basic statements of a programming language, it is just as impossible to build a complex software system from basic program statements alone as it is to build a jet airplane from only nuts and bolts. Reusable software components are an indispensable part of the building blocks, especially in today's object-oriented programming languages. A reusable software component is a software module that can be integrated into a new program directly or after minor changes. A software module refers to a named and addressable abstraction--either a procedural abstraction, such as a function, or a data abstraction, such as a class. Procedures, functions, methods, and classes are all considered software modules. In this dissertation, the term module refers to software abstractions to be developed by programmers, and the term component is used to refer to those modules that have been packaged for reuse. Because basic program statements of a programming language are not of interest in this research, the term ``building block'' is used throughout interchangeably with the term ``software component.''

2.2.3 Orthogonality of Program Plans and Software Components

Software components are used to realize program plans. Program plans and software components are orthogonal to each other: a program plan can be realized with different software components, and a software component can be used in the realization of different program plans. Figure 2.3 illustrates the orthogonal relationship between program plans and software components.

Figure 2.3: Orthogonality between program plans and software components

\includegraphics[width=.8\linewidth]{figs/Orthogonality.eps} % latex2html id marker 7997
$\textstyle \parbox{.8\linewidth}{\small {The task \...
...lines, i.e., the components
of \texttt{swapInt()} and \texttt{Math.Random()}.}}$


Ph.D. Dissertation by Yunwen Ye, April 20, 2001, Department of Computer Science, University of Colorado