0% found this document useful (0 votes)
21 views

Programe Comprehension

Program comprehension is key to effective software maintenance and evolution. It involves developing a mental model of the program to understand its goals, knowledge, and elements. Cognitive models examine the goals, knowledge, and mental representations used during program comprehension. Programmers use strategies like chunking and cross-referencing to build higher-level abstractions from code elements and link related parts of a program.

Uploaded by

mehwish naz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Programe Comprehension

Program comprehension is key to effective software maintenance and evolution. It involves developing a mental model of the program to understand its goals, knowledge, and elements. Cognitive models examine the goals, knowledge, and mental representations used during program comprehension. Programmers use strategies like chunking and cross-referencing to build higher-level abstractions from code elements and link related parts of a program.

Uploaded by

mehwish naz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Programme Comprehension

1
Outline
1. General Idea
2. Basic Terms
3. Cognition Models for Program Understanding
4. Protocol Analysis
5. Visualization for Comprehension
6. Summary

2
General Idea

It is important to comprehend a complex system to be able to maintain it.

Modification of software with inaccurate and incomplete understanding


is likely to degrade its performance and reliability.

Good program comprehension is key to providing effective software


maintenance and effective evolution of software.

3
Basic Maintenance Task

4
Basic Terms Cognitive Model
Model Maintenance activity Authors

Control-flow Understand Pennington

Functional Understand Pennington

Top-down Understand Soloway, Adelson, and


Ehrlich

Integrated Understand, Von Mayrhauser and


Corrective, Vans
Adaptive,
And Perfective
Other Enhancement Letovsky
Understand Brooks
Shneiderman and
Mayer

5
Cognitive Model code Comprehension

• Goal of code cognition

• Knowledge

• Mental model

6
Goal of Code Cognition
A code maintainer tries to understand a program with a specific goal in
mind.
Example 1: Debugging a program to detect the cause of a known failure
Example 2: Adding a new function to the existing program

Identifying the goal can help in defining the scope of program


comprehension.
Scope of program comprehension: complete program or part of a program
A program comprehension process is a sequence of activities that use
existing knowledge about the program to generate new knowledge about it.
7
Knowledge for code
 Programmers possess two kinds of knowledge
• General knowledge
• Software-specific knowledge
 General knowledge:
• Algorithms and data structures
• Operating systems
• Programming principles
• Programming languages
• Software architecture and design
• Testing and debugging techniques

8
Knowledge for code
 Software-specific knowledge

• The software system has implemented public-key cryptography for data encryption.

• The software system has been structured as a three-tier client-server system.

• Module x implements a location server.

• A certain for loop in method y may execute for a random number of times.

• Variable mcount keeps track of the number of times module z is invoked.

9
Knowledge for code
 Software-specific knowledge (New Knowledge )

• Functionality

• Software architecture

• Control flow and data flow

• Exception handling

• Stable storage

• Implementation details 10
Knowledge

11
Mental Model

A mental model describes a programmer’s mental representation


of the program being comprehended.
A mental model of a program is not unique; different programmers
view and interpret a programmer in different ways.
A programmer develops a mental model by identifying both static
and dynamic elements of the program.
Examples of program elements
for loop
A TCP (Transmission Control Protocol) connection
12
Over all control flow
Mental Model

A mental model describes a programmer’s mental representation


of the program being comprehended.
A mental model of a program is not unique; different programmers
view and interpret a programmer in different ways.
A programmer develops a mental model by identifying both static
and dynamic elements of the program.
Examples of program elements
for loop
A TCP (Transmission Control Protocol) connection
13
Over all control flow
Mental Model

Static elements of a mental model


Text-structures
Chunks
Schemas
Plans
Hypotheses

Dynamic elements of a mental model


Chunking
Cross-referencing
Strategies

14
Mental Model static elements

 Text-structures
• Code and its structure are known as text-structures.
• It is useful in gaining control flow knowledge in program understanding.
• A programmer can easily identify the following text-structures:
• Loop constructs: for, while, and until
• Sequences
• Conditional statements: if-then-else
• Variable definitions and initializations
• Calling hierarchies within and among modules
• Definitions of module parameters
• Understanding text-structures is the beginning of program comprehension.

15
Mental Model static elements

 Chunks

A program chunk is a block of related code segment.

Chunks enable programmers to create higher level abstractions from lower-level abstractions.

Examples

• A code block initializing a module’s parameters tells the programmer about the nature of

the parameters and their value ranges.

• Understanding a for loop enables a programmer to create an abstraction of an internal

functional step performed by the program.

16
Mental Model static elements

 Schemas

• Schemas are generic knowledge structures that guide the programmer’s interpretations,

inferences, expectations, and attentions when passages are comprehended.

• The concept of programming plans correspond to the notion of schemas.

17
Mental Model static elements

 Plans

– A knowledge element is anything that is useful in understanding a program.

– Plans are broad kinds of knowledge elements used by programmers.

– Examples of knowledge elements


• If the name of a function gives an indication of the activity performed by the
function, then the function identifier is a knowledge element.
• A block of comments describing a for loop

• A for loop itself is a knowledge element.

• A description of the problem domain of the program

18
Mental Model static elements

 Plans
– Example of plan
• A doubly-linked list is an example of a plan; a designer has planned to implement
certain concepts with this data structure.
– A plan is a kind of schema with two parts:
• Slot type
– Slot types describe generic objects.
– Example: A tree data structure is a generic slot type.
• Slot filler
– Slot fillers are customized to hold elements of particular types.
– Example: A code segment, such as a for loop’s code is a slot filler.
– The programmer links the slot-type and slot-filler structures by means of the kind-of
and is-a modeling relationships.

19
Mental Model static elements

 Plans
There are two broad kinds of plans.
Domain plans
Programming plans
Domain plans

These include knowledge about the real world problem, including the program’s environment.

Example: If the software is for numerical analysis application, plans will include schemas for

different aspects of linear algebra, such as matrix multiplication and matrix inversion.

Programming plans

Example: A programmer may design a for loop to search an item in a data set and repeatedly use

the loop in many places in the program


20
Mental Model static elements

 Hypothesis

– As programmers start reading code and the related documents, they start developing
an understanding of the program to varying degrees.
– Programmers can test the results of their understanding as conjectures (aka
hypotheses.)
• Why: Why conjectures hypothesize the purpose of a program element.
– Verification of a why conjecture enables a programmer to have a good understanding of
the program element.
• How: How conjectures hypothesize the method for realizing a program goal.
– Given a program goal, the programmer needs to know how that goal has been
implemented.
• What: What conjectures enable programmers to classify program elements.

21
Mental Model Dynamic elements

 Chunking

 Cross-referencing

 Strategies

22
Mental Model Dynamic elements

 Chunking
– In a program, the lowest level of chunks are code segments.
– creates higher level abstraction structures by combining lower level
chunks.
– This process of creating higher level chunks is called chunking.
– The process of chunking is repeatedly applied to create increasingly
higher levels of abstractions.
– When a block of code is recognized, it is replaced by the programmer
with a label representing the functionality of the code block.
– A block of lower level labels can be replaced with one higher level
label representing a higher level functionality.

23
Mental Model Dynamic elements

 Cross-referencing
– Cross-referencing means being able to link elements of different
abstraction levels.
– This helps in building a mental model of the program under study.
– Example:
• Control flow and data-flow can be program elements at a lower level,
whereas functionalities are higher level program elements.
• There is a need to cross-reference between control-flow and data-flow elements
and program functionalities.

24
Mental Model Dynamic elements

 Cross-referencing
– A strategy is a planned sequence of actions to reach a specific goal.
– A strategy is formulated by identifying actions to achieve a goal.
– Example: if the goal is to understand the code representing a function, one can define
a strategy as follows:
• Understand the overall computational functionality of the function by reading its
specification, if it exists.
• Understand all the input parameters to the function.
• Read all code line by line.
• Identify chunks of related code.
• Create a higher level model of the function in terms of the chunks.
– Strategies guide the two dynamic elements, namely, chunking and cross-referencing,
to produce higher-level abstraction structures.
25
Class Activity

Find the coding examples for following mental elements OR take an example
code and find the following mental model elements in that specific code.
• Chunking
• Cross-Referencing
• Chunks
• Plans

26

You might also like