Program Implementation
Once the pseudocode has been written, it must be converted
in a program using a programming language, this can be done
using the following five stages:
Stage 1: Create the source code
Stage 2: Translate/Link
Stage 3: Test and execute
Stage 4: Maintain the program
Stage 1: Create the Source Code
You need translate the steps of your algorithm into
programming language instructions. When you write a
program using a programming language, the code you write
using assembly or high-level language is known as source
code.
before you translate these instructions into a language
understandable to computers it is a good practice to go
through each program instruction manually, to see if the
program has any errors. This process is called a dry run.
Stage 2: Translate and/or link
Computers only understand machine language instructions
(binary), so other programming language instructions have to
be converted into machine language. You use translators like
assemblers, interpreters and compilers to translate
programming language instructions.
Link
When you write a long or complex program, you will probably
write it in pieces or sections. Linking puts the sections
together to create one piece of code.
Each language has its rules and regulations – in English
language it is called grammar. The rules and regulations of a
programming language are called syntax. When you do not
follow the rules of the programming language the translator
reports these errors. They are called syntax errors.
If the program does not contain any syntax error, a compiler
will translate your program into machine language form. This
process is called compiling. After compilation you get object
code, which is in machine language form.
Source code Translate Object code
Assembly High-level High-level
Language Language code Language code
Assembler Compiler Interpreter
Machine code
(Object Code)
Stage 3: Execute/run program
Before you run, or execute a program, you should test it on
paper to see if it is working properly
Stage 4: Maintain the Program
Once you have a working program that fulfils its purpose, try
to maintain it.
Testing and Debugging
Testing and Debugging
Programs are tested to pick up errors. Three types of errors
can prevent a program from working. Logic errors, syntax
errors, and runtime errors. Errors can be detected when the
program is being translated, when you check it on paper, and
when you execute it. Debugging is the process of fixing errors
when you discover them.
Logic Errors
Logic errors occur when there is a mistake in the flow or
sequence of the program.
An example is using a variable in a calculation before the user
has entered value into the variable. The program may run, but
the outcome may be inaccurate. Logic errors can be picked up
by doing tests on paper and creating flow charts that follow
the logical flow of the program.
Run-time Error
Runtime errors occur when the program is being carried out.
They may be the result of external factors, such as lack of
computer memory or getting stuck in a loop. Run-time errors
can occur when values lead to illegal operations, such as
dividing by zero.
Types of Testing
Types of Testing
It is a good idea to test your program before you execute it.
You do this by going through the program using actual test
values. There are two ways you can do this: testing on paper
and computer testing.
Dry-run testing and trace tables are methods of testing on
paper.
Dry-run Testing
A quick and easy way to test whether you program works is to
use a dry-run test, also called desk checking. This is where
you substitute values for the variables and follow the
instructions in the program step by step to arrive at a
solution.
A dry-run test will tell you if there are any logic errors in your
program. Because if a step is out of sequence, you will not be
able to follow the calculations properly.
Trace Tables
Trace tables are useful if there are loops in your program. The
table will trace each variable as it progresses through the
calculation. It will show you the output of each cycle of
calculation within a problem.
Computer testing is where you test a program on a computer
by running it with as many different types of values of
combinations of data as possible. In an IT environment, this
would be carried out be a program tester. The tester runs the
program using obvious test data and obscure test data to
ensure that the program will run in all circumstances and
conditions.
For example, if a program requires the user to enter numeric
data, a tester must ensure that all kinds of numeric data will
work, such as identical numbers, positive and negative
numbers, real numbers, and values that are higher and lower
than each other. This can help to avoid runtime error when
the program is used in a live environment.
Testing (test data)
Testing (test data)
Testing is the process of running (executing) a program with
the specific intent of finding errors. It is not just about seeing
if the program "works" once, but seeing if it will "break"
when unexpected data is entered.
Testing checks three main things:
1. Verification: Does the program do what it is supposed to
do? Does it meet the given objectives and requirements?
2. Reliability: Can the program handle incorrect input
without crashing?
3. Accuracy: Does the program always give the correct
answer for its calculations and decisions?
Testing (test data)
Categories of Test DataTo thoroughly vet a program, we use
three distinct categories of test data:
1. Normal (Valid) Data
2. Boundary (Extreme) Data
3. Invalid (Erroneous) Data
Testing (test data)
1. Normal (Valid) Data - This represents the data the
program is expected to receive during regular use. This is
to ensure that the basic logic of the program is working
correctly. Examples include:
▪ If a program asks for age (1-120), then
accepted responses would be: 15, 25, 60,
110.
▪ If a program asks for marks (0-100), then
accepted responses would be, 50, 75, 90
Testing (test data)
2. Boundary (Extreme) Data - Values at the exact minimum
and maximum limits of the acceptable range. Examples
include:
▪ If a program accepts age (1-120), then
Boundary values would be: 0, 120
▪ If a program accepts Marks from 0 to 100,
then the boundary values would be 0 and
100.
Testing (test data)
3. Invalid (Erroneous) Data - Data that is the wrong type or
outside the logical range. This is done to test the
program's error-handling capabilities and ensure it
doesn't produce a Runtime Error. Examples include:
▪ If a program asks for age (1-120), then invalid
data would be: -5, 150 and "abc".
▪ If a program accepts integers, then invalide
data would be: "hello","@@@", and 5.5.
Debugging techniques
• Debugging is the process of finding and fixing errors
("bugs") in a computer program. While testing tells you that
a program is broken, debugging tells you why it is broken
and how to mend it.
➢ Print Statements (Output Debugging). This can be done by inserting
temporary code to display the value of variables at specific points in
the program. Example: If a loop isn't ending, you might
print(counter) to see if the variable is actually increasing.
Debugging techniques
➢Using Internal Documentation – effective documentation makes
debugging much faster for you and others. For example, the use of
comments, descriptive variable names, indentation and white
spaces, can be used to explain complex sections of the code, keep
the code organised and make errors easier to spot.
➢Compiler/Interpreter Error Checkers – the computer often tells you
which line has the problem and what type of error it is.
➢Test with Different Test Data.
➢Fix One Error at a Time, then run the program again to see what
happens.
Program Documentation
A programmer is not the only person to use a program. Many programs are
written by more than one programmer. A program is not of much use to a
person if they do not know what does or what it is used for. Documentation
says what a program does and how it is used.
Internal Documentation (also called technical documentation)
Internal documentation is detailed information on the inner workings of
the programming code. If you are looking at a long and complex program
that you did not write, internal documentation can help you see how it
works.
There are several forms of internal documentation:
➢Comments consists of notes within the source code that that will be ignored by
the translator (non-executable codes). It is designed to assist programmers in
identify program sections, explain complex logic or to understanding the
program. A good program will be structured so that is easy to read and does not
require many comments. Comments are written using statements between or
after symbols. Below are examples of symbols used in comments:
Symbols used Example Programming language
{ } (Curly Braces) {This a comment} Pascal
(* *) (Bracket-Star) (* This a comment *) Pascal, Modula-2
// (Double Slash ) // This a comment C, C++, C#, Java,
JavaScript
# (Hash) # This a comment Python, Bash
/* */ (Slash-Star) /* This program
C, C++, C#, Java,
calculates the average
JavaScript
of three numbers */
1. Indentation is used to visually represent a program's structure. It involves
placing specific blocks of code, such as conditional branching statement like
or loop to show where a control structure begins and ends. Indentation
makes the flow of the program easier to follow at a glance and assists in
maintaining the code over time.
Print(“Enter mark”) Print(“Hello World”)
Read(mark) while count <= 3:
if mark >= 50: mark = int(input("Enter student's mark: "))
print("Student has passed") if mark >= 50:
print("Well done!") print("Pass")
else: else:
print("Student has failed") print("Fail")
print("Try again next time") count = count + 1
print("All marks have been checked")
➢Effective Use of White Space – White space refers to the strategic use of blank
lines and spaces within the source code to separate distinct sections of a
program. It is used to logically group related statements – such as separating
variable declarations from the main processing logic or isolating different
functional blocks like input, calculation, and output. By preventing the code
from appearing as a single, dense wall of text, white space improves visual
clarity and makes the program much easier for a programmer to scan and read.
num1 = int(input("Enter first number: "))
total = num1 + num2
average = total / 2
print("Total =", total)
print("Average =", average)
▪ Mnemonic: a mnemonic is a memory aid. Mnemonics refer to the use of
abbreviations, symbols or a short, meaningful word that are designed to
help a programmer remember the function or purpose of a specific code
element.
▪ Variable names: useful variable names should be used when writing a
program. Using meaningful variable names allows a person reading the
source code to understand the program’s logic flow without needing
external manuals.
Programmers may write technical guides. These guides may
have useful indexes and mnemonics used in coding, plus
details of how the program was written. Technical guides may
contain diagrams, flowcharts and algorithm to help explain
the program. Other programmers can refer to it to help them
modify and maintain programs.
External Documentation
External Documentation is often called user documentation
or user manuals. User manuals provide installation
instructions, operation instructions and any other technical
specifications that a user needs to run or install a program.
Most general-purpose applications, have a built-in help
function which is a digital copy of the user documentation. If
you have installed a program on a computer, you may have
seen a documentation called “readme” in a folder that
contain the program.
The readme document have instructions on how to install the
program and may have a few instructions on getting started.
Most popular general-purpose application such as PowerPoint
have instructions built into the program – as we install the
program a wizard guides you through the steps. When you
create a new version of the program you have written, you
should create a new version of the
documentation.