SE.Software Coding
SE.Software Coding
Software Engineering
Software Coding, testing and
debugging
Orwa, Dec 2024
So far
• Software engineering
– What
– Why
• Software engineering models
– Variations
• Requirements elicitation
– Problem statement
– Process
– Outcome
• Software design
Learning Outcomes
• What is:
– Coding standards?
– Coding?
– Code Testing?
– Code debugging?
Introduction: Coding standards
• A coding standard
– is a set of programming styles and practices to which a group of
people adhere, in the belief that such adherence contributes the
overall effectiveness in producing high quality code that is
understandable and maintainable
– Improves reliability
Why Coding Stds and Guidelines
• Many bugs can be prevented by coding in a simple,
clear, and consistent style
• that follows idioms and patterns that experienced
programmers have developed.
• Walkthroughs:
– A more formal process in which the author of the code formally
presents the code to a small group of programmers and/or
testers.
– The author reads the code line by line explaining what it does,
reviewers listen and ask questions.
– Participants should follow the 4 essential elements.
Code Review
• Code Walk Through
– an informal code analysis technique and used mostly by
the development team => developer technique
• Identify problems:
– Find problems with the software such as missing items, mistakes,
etc.
• Follow rules:
– Amount of code to be reviewed, how much time will be spent, etc.
• Prepare:
– Each participant should prepare in order to contribute to the review.
• Write a report:
– Summarize the results of the review, make report available to the
development team.
Code Review
36
Code Testing
• The lowest level of testing is the Unit testing and is done by the
developer/ programmers (not by testers).
• Requires knowledge of the internal program design and code => use
of White-box testing techniques
39
Code Testing
40
Code Testing
• Good testing requires testing good cases
– Reduces debugging time and ensures better product
42
Control-flow-based Testing
• A traditional form of white-box testing
• Step 1: From the source, create a graph describing the flow
of control
– Called the control flow graph
– The graph is created (extracted from the source code) manually
or automatically
• Step 2: Design test cases to cover certain elements of this
graph
– Nodes, edges, paths
43
Example of a Control Flow Graph (CFG)
s:=0; 1
d:=0;
2
while (x<y) {
x:=x+3; 3
y:=y+2;
if (x+y < 100)
s:=s+x+y; 4
else
d:=d+x-y; 5 6
} 7
44
Elements of a CFG
• Three kinds of nodes:
– Statement nodes: represent single-entry-single-exit sequences of
statements
– Predicate nodes: represent conditions for branching
– Auxiliary nodes: (optional) for easier understanding (e.g., “join
points” for IF, etc.)
• Edges: represents possible flow of control
45
IF-THEN, IF-THEN-ELSE, SWITCH
if (c) if (c) switch (c)
then then case 1:
// join point else case 2:
// join point // join point
…
…..
… …
46
Example
switch (position)
case CASHIER
if (empl_yrs > 5)
bonus := 1;
else
.
bonus := 0.7; .
case MANAGER .
bonus := 1.5;
.
if (retiring_soon)
bonus := 1.2 * bonus
case …
endswitch
47
Mapping for Loops
while (c) {
}
…
48
Code Debugging
• Debugging is the process of determining the cause of
a failure