Programming Concepts
Programming Concepts
com 0785187880
PROGRAMMING CONCEPTS
Definition of terms:
Program: a set of detailed and unambiguous instructions that instructs a computer to
perform a specific task, for example, to add a set of numbers.
Problem: any question or matter involving difficulty or uncertainty and is proposed for
solution.
Programming Languages
A programming language is a set of symbols in computer language that are used in coding
computer programs.
A programming language is a specially written code used for writing application programs
e.g C, Pascal, COBOL, VISUAL BASIC, C++ and Java.
Programming languages are of the following types:
Machine Code (Language) is the language used to write programs in binary form (zeros
and ones).
Assembly Language:
These are programming languages that use mnemonic codes in coding programs. Mnemonic codes
are abbreviations used in coding assembly language programs, for example, LDA for Load, ADD
for Addition, etc. Mnemonic codes are very close to machine code, hence are low level language
assembly language codes
These are programming languages that use English like statements in coding programs, for
example COBOL, Pascal, BASIC, etc.
There are so many high level languages because each language is designed for a specific
problem to be solved in our daily lives. For example BASIC was designed for learning
purposes, COBOL for business applications, FORTRAN for scientific purposes, etc. Below
is an example of a BASIC program that accepts two numbers entered through the
keyboard, adds them and display the result on the screen:
START
INPUT “ENTER FIRST NUMBER.”, A
INPUT “ENTER SECOND NUMBER.”, B
SUM = A + B
PRINT SUM
END
Programs written in High Level Language are first converted to machine code before running.
They are problem oriented and therefore can be used on any computer (not
machine dependent)
Disadvantages of HLL
Takes long to run since they need to be first converted to machine code.
They occupy a lot of disk storage space as compared to low level languages.
Translators
These are programs used to convert source code into machine code, and are in three types, which
are interpreters, compilers and assemblers, which are further explained below:
1. Interpreters
These are programs that convert (translate) and run one instruction of a program at a time before
going to the next, until the end of the program, e.g. the BASIC interpreter. They do not produce
the machine code version of a program; hence conversion is repeated when you run the program
again. Thus interpreters retain source code. The interpreter must be present in the computer for the
program to run.
Functions of Interpreters
They check syntax error in a program statement.
They translate an instruction into machine language and run it before going to the next.
Allocates storage space to variables.
Advantages of interpreters
It is easy to find and correct syntax errors in interpreted programs.
It is very fast to run programs for the first time.
It is very fast to run small programs.
Disadvantages of interpreters
They are very slow in running very large programs.
They do not produce an object code of a source code and hence difficult to use.
The interpreter must be present in the computer for the program to run.
2. Compilers
These are programs that convert a high level language program into its machine code equivalent at
one go and then run it, e.g. the COBOL compiler. Thus it translates the entire program before
running it. Once compiled, the program no longer needs conversion since the machine code
version is the one that will be run, until some changes are made to the program code. Thus a
compiler produces an object code of the program. The computer must have a compiler for
translation.
mlamboevans1@gmail.com 0785187880
Functions of Compilers
They check syntax errors in program statements.
They allocate storage space to variables.
Translate the whole program into machine code at one go.
Run an object code of the program.
Produces a program listing which indicates position of errors in a program.
Advantages of Compilers
Compiled programs runs faster since the object code is run.
Compilers indicate the line numbers with syntax errors and therefore assist programmers in
debugging programs.
They are appropriate even for very large programs.
Disadvantages of Compilers
Slower than interpreters for running programs for the first time.
The compiler must be present for the translation process to occur.
They can cause the computer to crash.
Difficult to find errors in compiled program.
*NB: Source Code refers to the program written in English-like statements (High Level
Language) by the programmer.
Object Code refers to a machine code version of a source code. All programs written in source
code must be converted to object code for the computer to understand them.
3. Assemblers: These are programs used to convert assembly language instructions into machine
language. Other uses of assemblers include:
They generate machine code that is equivalent to assembly language.
They are used to check the validity of instructions, that is, checking for syntax errors in an
instruction.
They also assign memory locations to variables.
Disadvantage of modularisation
It may be difficult to link the modules together.
There could be problems of usage of variables as similar variable names may be referring
to different sets of data.
They may also vary in scope.
NB: Library programs: this refers to a collection of standard programs and subroutines that are
stored and available for immediate use by other modules in the system. Library programs are
referenced by most modules in the systems.
NB: The difference between a procedure and a function is that a procedure is a sub program that
do not return a value while a function is a sub-program that returns a value.