Coding and Testing
Coding and Testing
1
Introduction
Design Phase(Design Document) Coding
Each module: Coded and Unit tested(in isolation)
Detailed Design
Algorithm and Data Structure
3
Coding..
Objective:
transform the design of a system into code in a high-
level language, and
Organisation dependent
4
Coding..
Coding Standard Advantages:
It facilitates
code understanding and code reuse.
It promotes
good programming practices. 5
Coding..
Coding Standards(Mandatory)
Naming variables
Coding Guidelines(Optional)
General suggestions regarding the coding style
Actual implementation left to the developer
6
Coding..
Code Review
Coding standard are followed or not?
7
Coding Standards and
Guidelines
8
Representative Coding
Standards
9
Coding Standards and
Guidelines
Representative coding standards:
Rules for limiting the use of globals:
It list
10
Coding Standards and
Guidelines
Standard headers for different
modules:
11
Coding Standards and
Guidelines
Standard headers for different
modules:
Example Header Format:
Name of the module.
Date on which the module was created.
Author’s name.
Modification history.
12
Coding Standards and
Guidelines
Standard headers for different
modules:
14
Coding Standards and
Guidelines
Naming conventions for global variables,
local variables, and constant identifiers:
16
Coding Standards and
Guidelines
Conventions regarding error return values
and exception handling mechanisms:
17
Representative Coding
Guidelines
18
Coding Standards and
Guidelines
Representative coding guidelines:
Do not use a coding style that is
too clever or too difficult to understand:
20
Coding Standards and
Guidelines
Representative coding guidelines:
Avoid obscure side effects:
The side effects of a function call include
modifications to the parameters passed by reference,
modification of global variables, and I/O operations.
An obscure side effect is one that is not
obvious from a casual examination of the
code.
Obscure side effects make it difficult to
understand a piece of code.
21
Coding Standards and
Guidelines
Representative coding guidelines:
Avoid obscure side effects:
The side effects of a function call include
purposes:
Programmers often use the same identifier to
denote several temporary entities.
23
Coding Standards and
Guidelines
Representative coding guidelines:
Do not use an identifier for multiple
purposes:
The rationale that they give for such multiple
use of variables is memory efficiency,
e.g., three variables use up three memory
locations,
whereas when the same variable is used for three
different purposes, only one memory location is used.
However , there are several things wrong with
this approach and hence should be avoided.
24
Coding Standards and
Guidelines
Representative coding guidelines:
Do not use an identifier for multiple
purposes: Some of the Problems
multiple purposes.
Use of a variable for multiple purposes can
27
Coding Standards and
Guidelines
Representative coding guidelines:
Length of any function should not
exceed 10 source lines:
A lengthy function is usually very difficult to
understand as it probably has
a large number of variables and
computations.
29
Code Review
30
Code Review
Review is a very effective technique to remove
defects from source code.
31
Code Review
Code review for a module is undertaken
after the module successfully compiles.
32
Code Review
The reason behind why code review is a much
more cost-effective strategy to eliminate errors
from code compared to testing is that
reviews directly detect errors.
Code walkthrough.
Code inspection.
36
Code Review
Code walkthrough.
37
Code Review
Code walkthrough.
Code walkthrough is an informal code analysis
technique
Code Review
Code walkthrough.
Code walkthrough is an informal code analysis
technique.
41
Code Review
Code walkthrough.
Code inspection.
45
Code Review
Code Inspection
During code inspection, the code is
examined for the presence of
some common programming errors.
46
Code Review
Code Inspection
principal aim of the code inspection:
is to check for the presence of some
common types of errors that usually
creep into code due to
programmer mistakes and oversights
and
to check whether coding standards have
been adhered to.
47
Code Review
Code Inspection
The inspection process has several
beneficial side effects, other than
finding errors.
52
Code Review
Code Inspection
54
Code Review
Code Inspection
Following is a list of some classical
programming errors which can be checked
during code inspection:
Use of uninitialised variables.
Jumps into loops.
Non-terminating loops.
Incompatible assignments.
Array indices out of bounds.
Improper storage allocation and 55
Code Review
Code Inspection
Mismatch between actual and formal
parameter in procedure calls.
Use of incorrect logical operators or
incorrect precedence among operators.
Improper modification of loop variables.
Dangling reference caused when the
referenced memory has not been allocated.
56
Code Review
57
Code Review
Clean Room Testing
Clean room testing was pioneered at IBM.
This type of testing relies heavily on
walkthroughs,
inspection, and
formal verification.
62
Software Documentation
When a software is developed, in
addition to the executable files and
the source code,
several kinds of documents such as
users’ manual,
software requirements specification
(SRS) document,
design document,
test document, etc., are developed
63
Software Documentation
Good documents are helpful in the
following ways:
Good documents help
enhance understandability of code.
the users to understand and effectively
use the system.
effectively tackle the manpower
turnover problem.
the manager to effectively track the
progress of the project. 64
Software Documentation
Types of software documents:
Internal documentation: These are
provided in the source code itself.
68
External Documentation
A systematic software development
style ensures that all these(SRS….)
documents
are of good quality and
are produced in an orderly fashion.
69
External Documentation
An important feature that is
required of any good external
documentation is
consistency with the code.
all the documents developed for a
product should be up-to-date
proper understandability by the
category of users for whom the
document is designed.
Gunning’s fog index 70
External Documentation
Gunning’s fog index (developed by Robert
Gunning in 1952) is a metric that has been
designed to measure the readability of a
document.
number of years of formal education that a
person should have, in order to be able to
comfortably understand that document.
a fog index of 12, any one who has completed
his 12th class would not have much difficulty
in understanding that document.
71
External Documentation
The Gunning’s fog index of a document D
can be computed as follows:
73
External Documentation
Example: Calculate its Fog index for the
sentence: “The Gunning’s fog index is based on
the premise that use of short sentences and
simple words makes a document easy to
understand.”
The fog index of the above example
sentence is:
0.4(23/1) + (4/23)100 = 26
74