0% found this document useful (0 votes)
2 views

Module1_Part2

The document outlines various programming paradigms, including monolithic, procedural, structured, object-oriented, logic-oriented, rule-oriented, and constraint-oriented programming, each with its own focus and characteristics. It details the phases of program design and implementation, including requirements analysis, design, implementation, testing, deployment, and maintenance, along with tools like algorithms, flowcharts, and pseudocode. Additionally, it discusses types of errors in programming, testing approaches, and debugging methods to ensure program correctness and efficiency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module1_Part2

The document outlines various programming paradigms, including monolithic, procedural, structured, object-oriented, logic-oriented, rule-oriented, and constraint-oriented programming, each with its own focus and characteristics. It details the phases of program design and implementation, including requirements analysis, design, implementation, testing, deployment, and maintenance, along with tools like algorithms, flowcharts, and pseudocode. Additionally, it discusses types of errors in programming, testing approaches, and debugging methods to ensure program correctness and efficiency.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Module 1

SIGNING EFFICIENT PROGRA

© Oxford University Press 2016. All rights reserved.


PROGRAMMING PARADIGMS
A programming paradigm is a fundamental style of programming that defines how the structure
and basic elements of a computer program will be built.

The style of writing programs and the set of capabilities and limitations that a particular
programming language has depends on the programming paradigm it supports.

These paradigms, in sequence of their application, can be classified as follows:

•Monolithic programming — emphasizes on finding a solution

•Procedural programming—lays stress on algorithms

•Structured programming—focuses on modules

•Object-oriented programming—emphasizes on classes and objects

•Logic-oriented programming—focuses on goals usually expressed in predicate calculus

•Rule-oriented programming—makes use of ‘if-then-else’ rules for computation

•Constraint-oriented programming—utilizes invariant relationships to solve a problem.

© Oxford University Press 2016. All rights reserved.


MONOLITHIC PROGRAMMING
Monolithic programs have just one program module as such programming languages do not
support the concept of subroutines. Therefore, all the actions required to complete a particular
task are embedded within the same application itself. This not only makes the size of the
program large but also makes it difficult to debug and maintain.

Programs written using monolithic programming languages consist of global data and sequential
code. The global data can be accessed and modified from any part of the program.

Examples are Assembly Language and BASIC

© Oxford University Press 2016. All rights reserved.


PROCEDURAL PROGRAMMING
In procedural languages, a program is divided into subroutines that can access global data. To
avoid repetition of code, each subroutine performs a well-defined task. A subroutine that needs
the service provided by another subroutine can call that subroutine. Therefore, with ‘jump’,
‘goto’, and ‘call’ instructions, the sequence of execution of instructions can be altered.
FORTRAN and COBOL are two popular procedural programming languages
Advantages
• The only goal is to write correct programs
• Programs are easier to write as compared to monolithic programming
Disadvantages
• No concept of reusability
• Requires more time and effort to write programs
• Programs are difficult to maintain
• Global data is shared and therefore may get altered (mistakenly)

© Oxford University Press 2016. All rights reserved.


STRUCTURED PROGRAMMING

Structured programming employs a top-down approach in which the overall program


structure is broken down into separate modules. This allows the code to be loaded
into memory more efficiently and also be reused in other programs. Modules are
coded separately and once a module is written and tested individually, it is then
integrated with other modules to form the overall program. Structured programming
is based on modularization which groups related statements together into modules.
Advantages
•With modules, many programmers can work on a single, large program, with each
working on a different module.
•A structured program takes less time to be written than other programs.
•Modules or procedures written for one program can be reused in other programs as
well.
Disadvantages
• Not data-centred
• Global data is shared and therefore may get inadvertently modified
• Main focus is on functions

© Oxford University Press 2016. All rights reserved.


OBJECT-ORIENTED PROGRAMMING (OOP)

The object-oriented paradigm is task-based and data-based. In this paradigm, all the
relevant data and tasks are grouped together in entities known as objects. It treats
data as a critical element in the program development and restricts its flow freely
around the system.
The striking features of OOP include the following:

•Programs are data centred.


•Programs are divided in terms of objects and not procedures.
•Functions that operate on data are tied together with the data.
•Data is hidden and not accessible by external functions.
•New data and functions can be easily added as and when required.
•Follows a bottom-up approach for problem solving.

© Oxford University Press 2016. All rights reserved.


Design and Implementation of Efficient
Programs
To design and develop correct, efficient, and maintainable programs,
the entire program development process is divided into a number of
phases where each phase performs a well-defined task.

Output of one phase provides the input for its subsequent phase.

Requirements Analysis

•In this phase, users’ expectations are gathered to know why the
program/software has to be built.

•All the gathered requirements are documented to avoid any doubts


or uncertainty regarding the functionality of the programs.

© Oxford University Press 2016. All rights reserved.


Design and Implementation of Efficient
Programs
Design
•A plan of actions is made before the actual development process could start.

•The core structure of the software/program is broken down into modules.

•The solution of the program is then specified for each module in the form of
algorithms, flowcharts, or pseudocodes.

Implementation
•Designed algorithms are converted into program code using any of the high level
languages.

•The choice of language depends on the type of program like whether it is a system or
an application program.

•Program codes are tested by the programmer to ensure their correctness.

•While constructing the code, the development team checks whether the software is
compatible with the available hardware and other software components that were
mentioned in the Requirements Specification Document created in the first phase.
© Oxford University Press 2016. All rights reserved.
Design and Implementation of Efficient
Programs
Testing
•All the modules are tested together to ensure that the overall system works well as a
whole product.

•Although individual pieces of codes are already tested by the programmers in the
implementation phase, there is always a chance for bugs to creep in the program when the
individual modules are integrated to form the overall program structure.

•Software is tested using a large number of varied inputs also known as test data to ensure
that the software is working as expected by the users’ requirements that were identified in
the requirements analysis phase.

Software Deployment, Training and Support


•After testing the software is deployed in the production environment.

•Software Training and Support is a crucial phase which makes the end users familiar with
how to use the software.

•Moreover, people are often resistant to change and avoid venturing into an unfamiliar
area, so as a part of the deployment phase, it has become very crucial to have training
classes for the users of the software.
© Oxford University Press 2016. All rights reserved.
Design and Implementation of Efficient
Programs
Maintenance
•Maintenance and enhancements are ongoing activities which are done to cope with
newly discovered problems or new requirements.
•Such activities may take a long time to complete as the requirement may call for
addition of new code that does not fit the original design or an extra piece of code
required to fix an unforeseen problem.
•As a general rule, if the cost of the maintenance phase exceeds 25% of the prior-
phases cost then it clearly indicates that the overall quality of at least one prior phase is
poor. In such cases, it is better to re-build the software (or some modules) before
maintenance cost is out of control.

© Oxford University Press 2016. All rights reserved.


Program Design Tools
• Algorithms
• Flowchart
• Pseudocodes

11
© Oxford University Press 2016. All rights reserved.
Algorithms
• An algorithm provides a blueprint for writing a program to solve a particular
problem.
• It is considered to be an effective procedure for solving a problem in a finite
number of steps.
• A well-defined algorithm always provides an answer, and is guaranteed to
terminate.
• Algorithms are mainly used to achieve software re-use.
• A good algorithm must have the following characteristics
 Be precise
 Be unambiguous
 Not even a single instruction must be repeated infinitely
 After the algorithm gets terminated, the desired result must be
obtained © Oxford University Press 2016. All rights reserved.
Control Structures used in Algorithms
Sequence
Sequence means that each step of the algorithm is executed in the specified order.

Decision
Decision statements are used when the outcome of the process depends on some
condition. For example, if x=y, then print “EQUAL”. Hence, the general form of the if
construct can be given as
if condition then process
Repetition
Repetition, which involves executing one or more steps for a number of times, can be
implemented using constructs such as while, do-while, and for loops. These loops
execute one or more steps until some condition is true.

© Oxford University Press 2016. All rights reserved.


Flowcharts
• Flowchart is a graphical or symbolic representation of a process.
• It is basically used to design and document virtually complex processes to
help the viewers to visualize the logic of the process, so that they can gain a
better understanding of the process and find flaws, bottlenecks, and other
less obvious features within it.
• When designing a flowchart, each step in the process is depicted by a
different symbol and is associated with a short description. The symbols in
the flowchart are linked together with arrows to show the flow of logic in
the process

© Oxford University Press 2016. All rights reserved.


Symbols in a Flowchart
• Start and end symbols are also known as the terminal symbols and are

represented as circles, ovals, or rounded rectangles. Terminal symbols are always


the first and the last symbols in a flowchart.
• Arrows depict the flow of control of the program. They illustrate the exact
sequence in which the instructions are executed.
• Generic processing step, also called as an activity, is represented using a
rectangle. Activities include instructions such as add a to b, save the result.
Therefore, a processing symbol represents arithmetic and data movement
instructions. When more than one process has to be executed simultaneously,
they can be placed in the same processing box. However, their execution will be
carried out in the order of their appearance.

© Oxford University Press 2016. All rights reserved.


Flowcharts
• Input/output symbols are represented using a parallelogram and are used to get inputs
from the users or display the results to them.

• A conditional or decision symbol is represented using a diamond. It is basically used to


depict a Yes/ No question or a True/False test. The two arrows coming out of it, one from
the bottom vertex and the other from the right vertex, correspond to Yes or True, and No
or False, respectively. The arrows should always be labeled. A decision symbol in a
flowchart can have more than two arrows, which indicate that a complex decision is being
taken.
• Labeled connectors are represented by an identifying label inside a circle and are used in
complex or multi-sheet diagrams to substitute for arrows. For each label, the ‘outflow’
connector must have one or more ‘inflow’ connectors. A pair of identically labeled
connectors issued to indicate a continued flow when the use of lines becomes confusing

© Oxford University Press 2016. All rights reserved.


Pseudocode
• Pseudocode is a compact and informal high-level description of an algorithm
that uses the structural conventions of a programming language.
• It is basically meant for human reading rather than machine reading, so it
omits the details that are not essential for humans. Such details include
variable declarations, system-specific code, and sub-routines.
• Pseudocodes are an outline of a program that can be easily converted into
programming statements.
• They consist of short English phrases that explain specific tasks within a
program’s algorithm. They should not include keywords in any specific
computer language. The sole purpose of pseudocodes is to enhance human
understandability of the solution.

© Oxford University Press 2016. All rights reserved.


TYPES OF ERRORS
While writing programs, very often we get errors in our program. These errors if
not removed will either give erroneous output or will not let the compiler to
compile the program.

Run-time Errors occur when the program is being run executed. Such errors
occur when the program performs some illegal operation like

• Dividing a number by zero


• Opening a file that already exists
• Lack of free memory space
• Finding square or logarithm of negative numbers

Run-time errors may terminate program execution, so the code must be written
in such a way that it handles all sorts of unexpected errors rather terminating it
unexpectedly. This ability to continue operation of a program despite of run-
time errors is called robustness.

© Oxford University Press 2016. All rights reserved.


TYPES OF ERRORS

Compile-time Errors occur at the time of compilation of the program. Such


errors can be further classified as follows:

Syntax Errors is generated when rules of C programming language are violated.


For example, if we write int a: then a syntax error will occur since the correct
statement should be int a;

Semantic Errors Semantic errors are those errors which may comply with rules
of the programming language but are not meaningful to the compiler. For
example, if we write, a * b = c; it does not seem correct. Rather, if written like c
= a * b would have been more meaningful.

© Oxford University Press 2016. All rights reserved.


TYPES OF ERRORS
Logical Errors are errors in the program code that result in unexpected and undesirable
output which is obviously not correct.

Such errors are not detected by the compiler, and programmers must check their code
line by line or use a debugger to locate and rectify the errors.

Logical errors occur due to incorrect statements. For example, if you meant to perform c
= a + b; and by mistake you typed c = a * b; then though this statement is syntactically
correct it is logically wrong.

Linker Errors occur when the linker is not able to find the function definition for a given
prototype. For example, if you write clrscr(); but do not include conio.h then a linker error
will be shown.
© Oxford University Press 2016. All rights reserved.
Testing Approaches
Testing is an activity that is performed to verify correct behavior of a program. It
is specifically carried out with an intent to find errors.

Unit testing is applied only on a single unit or module to ensure whether it


exhibits the expected behavior.

Integration Tests are a logical extension of unit tests. In this test, two units that
have already been tested are combined into a component and the interface
between them is tested. This process is repeated until all the modules are tested
together. The main focus of integration testing is to identify errors that occur
when the units are combined.

System testing checks the entire system. For example, if our program code
consists of three modules then each of the module is tested individually using
unit tests and then system test is applied to test this entire system as one
system.

© Oxford University Press 2016. All rights reserved.


Debugging Approaches
• Debugging is an activity that includes execution, testing and code correction.

• It is done to locate errors in the program code. Once located, errors are then isolated
and fixed to produce an error-free code. Different approaches applied for debugging a
code includes:

Brute-Force Method: In this technique, a printout of CPU registers and relevant memory
locations is taken, studied, and documented. It is the least efficient way of debugging a
program and is generally done when all the other methods fail.

Backtracking Method: works by locating the first symptom of error and then trace
backward across the entire source code until the real cause of error is detected.
However, the main drawback of this approach is that with increase in number of source
code lines, the possible backward paths become too large to manage.

Cause Elimination: lists all possible causes of an error is developed. Then relevant tests
are carried out to eliminate each of them. If some tests indicate that a particular cause
may be responsible for an error then the data are refined to isolate the error.

© Oxford University Press 2016. All rights reserved.

You might also like