Introduction-To-Programming 10
Introduction-To-Programming 10
Introduction-To-Programming 10
Although computers appear to be amazingly intelligent machines, they cannot yet think on their
own. They still rely on human being to give them directives. Computers are very literal, and
they must be told what to do right down to the last detail. It is only as effective as the
instructions we give it, and those instructions are contained in what we actually called program.
This chapter explain the concept of programming, as well as different programming paradigms.
Learning objectives
After studying this lesson, student should be able to:
Discuss what a computer program is.
State and explain the different steps to write a program
Discuss some examples of programming paradigm with some examples in each case.
Discuss the concepts of testing, debugging, documentation
Define some concepts related to Object Oriented Programming
Contents
I. DEFINITIONS .......................................................................................................................... 2
II. CHARACTERISTICS OF A GOOD PROGRAM ...................................................................... 2
III. DEVELOPING A PROGRAM .............................................................................................. 2
IV. PROGRAMMING LANGUAGES ......................................................................................... 4
V. PROGRAMMING PARADIGMS ............................................................................................. 8
VI. PROGRAM TESTING AND DEBUGGING ......................................................................... 9
VII. PROGRAM DOCUMENTATION ....................................................................................... 11
VIII. OBJECT ORIENTED PROGRAMMING (OOP) ................................................................. 12
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 2 By DZEUGANG Placide
I. DEFINITIONS
(a) Efficiency: This is the degree with which the program fulfils its purposes without waste
of resources
(b) Reusability: This is the ease with which a program or a module of a program can be
reused to design other program.
(c) Maintainability: this is the ease with which modifications can be made to satisfy new
requirements or to correct deficiencies. Well-designed program should be flexible
enough to accommodate future changes that will be needed as new requirements come
to light.
(d) Reliability: This is the frequency and extends to which a program fails to perform its
functions under normal operating circumstances.
(e) Correctness: This is the degree with which a program meets its specified requirements.
(f) Robustness: This is the degree with which software resist to users manipulations errors
(g) Documentation: enough comment should be inserted in a program to facilitate its
understanding by any computer user
(h) Portability: Portability refers to the ability of an application to run on different
platforms (operating systems) with or without minimal changes.
(i) Flexibility: A program should be flexible enough to handle most of the changes without
having to rewrite the entire program.
(j) Readability: The program should be written in such a way that it makes other
programmers or users to follow the logic of the program without much effort.
A program consists of a series of instructions that a computer processes to perform the required
operation. In addition, it also includes some fixed data, required to perform the instructions,
and the process of defining those instructions and data. Thus, in order to design a program, a
programmer must determine three basic rudiments:
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 3 By DZEUGANG Placide
Problem
analysis
Task analysis
Documentation
Algorithm
Testing and development
debugging
Coding
Problem Analysis: In this phase, the problem is analysed precisely and completely.
Based on one's understanding, the developer knows about the scope within which
the problem needs to be developed.
Task Analysis: After analysing the problem, the developer needs to develop
various solutions to solve the given problem. From these solutions, the optimum
solution is chosen, which can solve the problem comfortably and economically.
Algorithm Development: An algorithm depicts the solution in logical steps
(sequence of instructions).
Coding: After meeting all the design considerations, the actual coding of the
program takes place in the chosen programming language. languages.
Testing and Debugging: A program compiler and programmer-designed test data
machine test the code for syntax errors. The results obtained are compared with
results calculated manually from these test data.
Documentation: Documenting a program enables the user to operate the program
correctly. It also enables other persons to understand the program clearly so that it
may, if necessary, be modified, or corrected by someone other than the original
programmer.
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 4 By DZEUGANG Placide
A programming language is then defined as a language that is used for creating computer
programs. A programming language is determined by syntax and semantic.
- The syntax is the rules guiding the formulations of the program statement. It specifies
how words and symbols are put together to form statements and expressions. It is the
grammar of the language.
- Semantic describes the meaning of a program statement. It is the vocabulary of the
language.
Simplicity A good programming language must be simple and easy to learn and use.
Abstraction Abstraction means the ability to define and use complicated structures
or operations in ways that allow many of the details to be ignored.
Efficiency The program written in good programming language are efficiently
translated into machine code, are efficiently executed, and acquires as little space in
the memory as possible.
Structuredness Structuredness means that the language should have necessary
features to allow its users to write their programs based on the concepts of structured
programming.
Compactness In a good programming language, programmers should be able to
express intended operation concisely.
Extensibility A good programming language should allow extension through simple,
natural, and elegant mechanisms.
Suitability to its Environment the language must also be made suitable to its
environment.
Machine language is a set of instructions and data that a computer's central processing unit can
execute directly. Machine language statements are written in binary code, and each statement
corresponds to one machine action.
Characteristics:
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 5 By DZEUGANG Placide
a) Each computer can only understand programs that are written in its own ML
b) ML is provided by the computer manufacturer
c) Coded as a series of 0’s and 1’s. E.g. 1001110001
Disadvantages
Assembly language is the human-readable notation for the machine language used to control
specific computer operations. Programs are written using symbolic instruction codes that are
meaningful abbreviations or mnemonics. Program written in assembly language are translated
into machine language using assembler
Characteristics Weakness
a) Also provided by the manufacturer a) Machine dependant
b) One instruction for each computer b) The program is usually long
operation c) Hard to learn and slow to write
c) Computer codes are representing by
mnemonics (a set of letters)
d) The code must be assembled into
machine language before execution.
Some examples of third generation languages are: PASCAL, FORTRAN, BASIC, COBOL,
C and C++, HTML,
SQL, NOMAD and FOCUS are examples of fourth generation programming languages.
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 6 By DZEUGANG Placide
The fifth generation programming language or visual programming language is also known as
natural language. Provides a visual or graphical interface, called a visual programming
environment, for creating source codes.
Programming languages can be classified into two main types: Low-level programming
language and High-level programming language.
Comparison
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 7 By DZEUGANG Placide
The computer interprets the instructions as 1's and 0's. A source program written in assembly
language or in a high-level language must be converted to the machine language (object
program) before being executed by the machine. This process is called translation and requires
a tool called translator
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 8 By DZEUGANG Placide
V. PROGRAMMING PARADIGMS
The three main categories of programming paradigms are: imperative, object-oriented and
declarative.
1) Imperative languages
Imperative paradigm, also known as Procedural programming specifies a list of operations that
the program must complete to reach the desired state. Each program has a starting state, a list
of operations to complete, and an ending point.
The advantages of this paradigm are its efficiency, closeness to the machine and popularity.
The disadvantages include: the difficulties in debugging as well as the difficulties in
understanding the semantic of a program. Typical examples of typical imperative programming
languages are: Fortran, Algol, Pascal, C and Basic
2) Object-oriented programming
Object-oriented programming is one the newest and most powerful paradigms. In object
oriented programs, the designer specifies both the data structures (called attributes) and the
types of operations that can be applied to those data structures (called methods). This pairing
of a piece of data with the operations that can be performed on it is known as an object. A
program thus becomes a collection of cooperating objects, rather than a list of instructions.
Objects can store state information and interact with other objects, but generally each object
has a distinct, limited role.
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 9 By DZEUGANG Placide
3) Declarative languages
Two final paradigms to discuss are compiled languages and interpreted languages.
d) Compiled languages use a program called a compiler to translate source code into
machine instructions, usually saved to a separate executable file. E.g. Pascal, C
e) Interpreted languages, in contrast, are programs that can be executed from directly
from source code by a special program called an interpreter. This distinction refers to
the implementation, rather than the language design itself. LISP and HTML are well
known interpreted languages.
The fact that a program is capable of producing results gives no guarantee that these answers
are correct. Before implementing the program on the user's system, it should be tested
thoroughly to ensure that it is running properly and giving desired results. This process of
validating a program is known as testing. If the program fails the test procedure, the reasons
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 10 By DZEUGANG Placide
for this failure must be detected and removed. The process of detecting, isolating and correcting
bugs in a program is known as debugging.
• Syntax Errors: errors due to the fact that the syntax of the language is not respected.
Syntax errors are the most common errors and, typically, involve incorrect punctuation,
incorrect word sequence, undefined terms or misuse of terms. These errors are easier to
correct because in case of such errors, programming languages provide a useful error
message, which gives an idea about what is wrong with the program.
• Logic errors are those errors that remain after all the semantic and syntax errors have
been removed. Usually, logic errors manifest themselves when the result the program
produces doesn't match the result your test data suggest it should produce. Logic errors
occur when you implement the algorithm for solving the problem incorrectly. The key
to fixing logic errors is to be able to reproduce the error consistently.
• A semantic error occurs when you obey the syntax rules of the language but are using
the statement out of context.
Black box testing, also known as functional testing is a testing technique where the internal
architecture of the item being tested is not necessarily known by the tester (the person
responsible for testing the program). The tester should only know about the inputs and the
expected outcomes. The ultimate goal of black box testing is to test every possible combination
and value of input. Thus, the tester and the programmer can be independent of one another,
avoiding programmer bias towards one's own work.
White box testing, also known as glass box, structural, clear box and open box testing, is one
of the most popular testing approaches. Unlike black box testing, white box testing uses
specific knowledge of programming code to examine outputs. He must apply test cases and
various inputs in order to test branches, conditions, loops and the logical sequence of statements
being executed.
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 11 By DZEUGANG Placide
1) The brute force category of debugging is probably the most common and efficient
method for isolating the cause of a software error. Brute force debugging methods are
applied when all methods of debugging fail.
2) Backtracking is a common debugging approach that can be used successfully in small
programs. Beginning at the site where a symptom has been uncovered, the source code
is traced backward (manually) until the site of the cause is found.
3) Cause Elimination is manifested by induction or deduction and introduces the concept
of binary partitioning. Data related to the error occurrence are organized to isolate
potential causes.
Usually, the end user has nothing to do with how the program was created, but he/she is
interested in how it can be used to his/her advantage. Some useful documenting techniques
from the user's point of view are as follows:
• System Manuals: A system manual contains the detailed technical information for
each application system. It describes each of the major functions performed by the
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 12 By DZEUGANG Placide
application, the data affected by or used within the application and the logical flow of
data within the application, as well as details concerning all application input and
output.
• User Manuals: User manuals assist the person to understand the proper use of the
system. It provides detailed instructions concerning the procedure(s) to be followed to
enter data into the application for processing, as well as to request nonrecurring reports
and other information.
Modifying an application, if it is a complex one, is not very easy especially if the modification
is to be done by a programmer other than the original one. In such cases, proper documentation
can reduce the burden of the programmers a great deal. Some useful documenting techniques
from the programmer's point of view are as follows:
• Comments: Comments are used within a program to assist the reader in understanding
the function or purpose of a single or multiple instructions. In C programming we use
// and /*…*/ to insert comment in the code.
• Programming Tools: Algorithms, flowcharts and pseudocodes are useful means of
program documentation. They help in making the program logic easier to understand.
In case, the program needs certain modification, the programmer can fall back on these
tools.
• Various Reports: Programming involves many steps. In all these steps, certain reports
are generated such as error reports, maintenance reports and testing reports.
VIII.1 Object
An object can be considered a "thing" that can perform a set of related activities. The set of
activities that the object performs defines the object's behavior. For example, the hand can grip
something or a Student (object) can give the name or address. In pure OOP terms an object is
an instance of a class.
VIII.2 Class
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 13 By DZEUGANG Placide
A class is simply a representation of a type of object. A class is the blueprint from which the
individual objects are created. Class is composed of three things: a name, attributes, and
operations.
VIII.4 Interface
the Interface separates the implementation and defines the structure. Interface can be used to
define a generic template and then one or more abstract classes to define partial
implementations of the interface.
VIII.5 Encapsulation
Encapsulation is a way of organizing data and methods into a structure by concealing the way
the object is implemented, i.e. preventing access to data by any means other than those
specified. Encapsulation therefore guarantees the integrity of the data contained in the object.
VIII.5 Polymorphism
Polymorphisms is a generic term that means 'many shapes'. More precisely
Polymorphisms means the ability to request that the same operations be performed by a wide
range of different types of things. In OOP the polymorphisms is achieved by using many
different techniques named method overloading, operator overloading, and method overriding,
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT
Topic: Introduction to programming 14 By DZEUGANG Placide
VIII.6 Inheritance
Inheritance is the process by which objects can acquire the properties of objects of other class.
In OOP, inheritance provides reusability, like, adding additional features to an existing class
without modifying it. This is achieved by deriving a new class from the existing one. The new
class will have combined features of both the classes.
visit www.dzplacide.overblog.com to discover many other learning tools for computer science & ICT