Program Comprehension


Program Comprehension

Study Questions

  1. In your opinion, what is program comprehension? In other words, what does it mean to comprehend a computer program?

  2. In what activities during the process of software development is program comprehension relevant? Important?

  3. Recall five situations in which you failed to understand a simple computer program. Can you explain the reason for these difficulties?

  4. Recall situations in which you succeeded in reading and understanding big computer programs easily. What characterized these computer programs?

  5. Develop two computer programs that perform the same task. One program is easily comprehensible; the second program is difficult to comprehend. What guided you in the development of each program?

  6. In your opinion, what are the five most important factors that influence the comprehensibility of computer programs?

  7. Suggest five heuristics that may help software developers in the process of comprehending computer programs. Refer to rules that can be used during the writing process and to guidelines that can be applied during the comprehension process.

The topic of program comprehension gets a lot of attention. This fact is reflected, for example, by the rich Annotated Bibliography about Code Reading and Program Comprehension . [1] A closer look at the annotated bibliography reveals that the topic is complex and has many subtopics, such as problems in program comprehension, factors that influence the comprehension of computer programs, relationships between professional experience and program comprehension abilities , heuristics to be applied in the process of program comprehension, and pedagogical attempts to help students gain experience in program comprehension. It is clear that program comprehension influences directly the daily life of software developers. For example, based on four experiments that demonstrate the influence of typographic style (source code formatting and commenting) on program comprehension, Oman [Oman90] concludes that about one-half of the maintenance programmer s time is spent studying the source code and related documentation. Fjeldstad and Hamlen [Fjeldstad and Hamlen83] observe that during enhancement or maintenance process of software systems, programmers study the original program about 3.5 times as long as they study the documentation of the program, and just as long as they spend implementing the enhancement.

One basic and interesting question to be posed is, why is program comprehension discussed at all? Can t we read code as we read other written documents, such as books, letters , program documentation, and so forth? The answer, of course, is No. Computer programs are expressed in a unique way that requires different reading skills than the skills needed to read and comprehend other documents.

Tasks  
  1. Identify several features/characteristics of computer programs that make their understanding different from the understanding of other written documents.

  2. Are the characteristics you listed in Question 1 dependent on the programming language in which the computer program is written?

    2a. If yes, in what sense? Suggest situations in which there is a relationship between the comprehension of computer programs and the programming language by which they are expressed.

    2b. If no, what characteristics of computer programs make their comprehension independent on the programming languages in which they are written?

Theories of Program Comprehension

A comprehensive article in which Davies [Davies93] outlines the main research studies about program comprehension concludes that although a wide range of perspectives have been adopted by studies that address the strategic aspects of programming skills, no clear picture emerges from this work. Among other implications, this conclusion says that program comprehension is still in search of one coherent theoretical framework. Because comprehension is so relevant to the daily life of software developers, the lack of a framework raises some practical questions, such as: How should software developers cope with program comprehension? How does the fact that no clear picture with respect to program comprehension has emerged so far influence code quality and development environments?

Davies [Davies93] suggests that multiple knowledge sources should be used in order to understand the behavior of computer programs. This perspective will guide the continuation of this section about theories of program comprehension. Specifically, we address factors that influence the process of program comprehension and strategies and actions adopted by software developers when they cope with the comprehension of computer programs.

We start by examining what it means to understand a computer program. Is it limited to understanding all the variables ? All the objects? All the data structures? Knowing what all the procedures are? The role of all functions? Is it important to understand the overall behavior of the program or only the behavior of specific parts ?

According to Biggerstaff, Mitbander, and Webster [Biggerstaff94], one understands a computer program when one is able to explain different aspects of the program (such as its structure and its behavior) in a way that is qualitatively different from the way by which these aspects are expressed by the source code (p. 72). According to Littman, Pinto, Letovsky, and Soloway [Littman87], to understand a program, a programmer must be familiar with the objects that the program manipulates and the actions that the program performs .

Task  

Select the longest computer program that you developed during the last year. According to the preceding definitions, explain what it means to comprehend that particular program.

Based on [Fjeldstad and Hamlen83] and [Brooks83], we present a list of factors affecting program readability and comprehension:

Representational factors and intrinsic properties of the program text: This includes factors such as the text s length, names of variables, procedure and other identifiers, the programming language, the nature and inclusion of comments, indentation, module structure, and typographic factors such as upper- and lowercase fonts.

Type of computation the program performs: The difficulty of comprehending a computer program depends in part on the difficulty ofunderstanding the problem the computer program solves . This happens also in cases when the complexity of the problem is different from the complexity of the resulting program.

Reason the task is performed (such as modification, debugging): Different tasks require varying levels of comprehension of different aspects of the program. For example, a programmer whose task is to modify the output format will be more concerned with the output statements in the program and less concerned with the major control structure than a programmer who attempts to find a bug that causes the program to produce wrong values. The task also affects the way the programmer searches the code listing (local view vs. global view).

Differences among the individuals performing the task: This includes factors such as the programmer s general knowledge, programmer skills and professional experience, and comprehension strategy applied (for example, by hierarchy or by input-output functions).

Task  

Select five of the preceding factors and exemplify them with the program you worked on in the previous task. In that particular program, do these factors support the comprehension of the program or do they disturb its comprehension?

Littman, Pinto, Letovsky, and Soloway [Littman87] collected data from experienced programmers as they enhanced a personnel database program. Based on the data analysis, two strategies for program understanding were identified:

The as-needed strategy: When one uses this strategy, the focus is on the local behavior of the computer program. As a result, since the programmer does not approach the modification task with a wide understanding of the program, it is necessary to gather additional information about the program structure and the way it operates during the program modification.

The systematic strategy: In this case, the target is to understand the global behavior of the computer program. Accordingly, the programmer wants to understand how the program behaves before the modifications are made. For this aim, the developer gathers information about the causal interactions of the program s functional components . Such knowledge permits the programmers to design modifications that take these interactions into account. In most cases, this strategy leads to successful program modification.

Task  

In what cases does it make sense to work according to the as-needed strategy? In what cases does it make sense to work according to the systematic strategy? For each case, explain why it fits the specific strategy.

Chapter 10, Learning Processes in Software Engineering, deals with just that. In the Learning Organizations section of Chapter 10, we discuss the concept of mental models. Here we refer to mental models as the programmers conception of a computer program. With respect to the task of program comprehension, the following types of mental models have been identified [Littman87]:

Weak mental models of a program: Mental models that contain only static knowledge about the program.

Strong mental models of a program: Mental models that contain both static knowledge about the program and causal knowledge about its behavior.

Task  

Suggest connections between the strategies used for program comprehension (the as-needed strategy/the systematic strategy) and the mental model of a program programmers construct in their mind (weak/strong mental models).

In the rest of this section, we focus on actions that programmers perform in the process of program comprehension. Specifically, Vans, von Mayrhauser and Somlo [Vans99], and von Mayrhauser and Vans [vonMayrhauser93] address the topic of program comprehension through the lens of abstraction (see Chapter 8, The History of Software Engineering, and Chapter 11, Abstraction and Other Heuristics of Software Development ). They describe actions, performed by programmers during software maintenance, on the following three levels of abstraction: Program level (code), Situation level (algorithmic), and Domain level (application). By levels of abstraction, we refer to the level of details and the type of inquiries one deals with. It is clear that during a program comprehension task, programmers should move between levels of abstraction according to the type of knowledge they look for and the actual action they perform.

Task  

In your opinion, what types of actions are characterized by each level of abstraction?

In what follows , we present several examples of actions performed at each level of abstraction. We start by examining the high level of abstraction. Full lists of actions for each level can be found in [Vans99].

  • Domain level (application)

    • Actions and comments that indicate that the programmer seeks high-level understanding. For example: I m thinking how this class contributes to the solution of the problem.

    • Comments that refer to high-level understanding strategy. For example: First I will read the names of the classes and the methods , then. . . .

      Task  

      Why do these actions reflect thinking that is characterized by a high level of abstraction?

  • Situation level (algorithmic)

    • Questions or inquiries that refer to the application area or situation. For example: I wonder if they all used the same coding standards.

    • Comments that describe how the programmer will or would have approached understanding. For example: First I need to understand why and how this method performs this complicated calculation, then. . . .

  • Program level (code)

    • Statements that are word-for-word reading of comments in the code. For example, The comment declares explicitly that. . . .

    • Comments that describe a change in the code when it is carried out.

Tasks  
  1. For each of the actions listed in the preceding section, add at least two phrases that illustrate them.

  2. Recall whether you have ever used statements like the ones mentioned or others that belong to these three categories. Describe these situations.

  3. Select three of the actions listed in the previous section and describe situations for which the selected actions are useful.

  4. Find source code that you or your colleagues developed at least three months ago. Identify one possible upgrade and perform it. Obviously, during this process you will have to comprehend the code. Reflect on the program comprehension process you went through. Identify what strategies you used. If appropriate, suggest ways to improve the code to make its comprehension easier.

  5. Ask a friend to comprehend a program that you understand very well. Encourage your friend to think aloud and tape-record what is said during that process. Transcribe the monologue and identify what heuristics of those mentioned previously were used during the process of program comprehension and how your friend moved between the levels of abstraction.

Beyond the classification of the activities that software developers carry out in their attempts to comprehend computer programs, the aforementioned researchers looked at thinking patterns during the process of program comprehension. Among other interesting results, they present the following:

  • Programmers with little experience in the domain work at lower levels of abstraction until enough domain experience allows them to make connections from the code to higher levels of abstraction.

  • Programmers with domain experience but little knowledge about the software also work at lowers levels of abstraction, but use their knowledge of the domain to make direct connections into higher levels of abstraction of the program model.

  • Code size affects the level of abstraction on which maintenance engineers concentrate while building a mental representation of the program. As the code size increases , developers work less with low-level program details.

    Task  

    Explain the preceding patterns. How do they support the process of program comprehension?

Activity

Phase 1: Split into pairs. Each pair constructs a computer program that has to be as comprehensible as possible. During this attempt to write a comprehensible computer program, reflect on the guidelines you follow.

Phase 2: Switch pairs. Each pair comprehends the code that was written by another pair. During this process, reflect on what heuristics you use in the process of program comprehension.

Discussion

  1. Is there a connection between the software development method (see Chapter 2, Software Engineering Methods ) by which a computer program is developed and its comprehension process?

  2. In what ways should a general software development method address another of program comprehension? In other words, if you have to design a software development method, would you address the topic of program comprehension? If yes, how? If no, explain why.

[1] The URL of the Annotated Bibliography about Code Reading and Program Comprehension is www2.umassd.edu/SWPI/ProcessBibliography/bibcodereading.html .




Human Aspects of Software Engineering
Human Aspects of Software Engineering (Charles River Media Computer Engineering)
ISBN: 1584503130
EAN: 2147483647
Year: 2004
Pages: 242

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net