Programming Concepts
Programming Concepts
PROGRAMMING CONCEPTS
Dear friends,
In Today’s discussion we will cover the topics such as characteristics of a
good program, modular programming concepts, different types of errors in
programming and finally the concept of structured programming.
Programming
A program is a set of step-by-step instructions that directs the computer to
do the tasks that you wanted and produce the results. There are several
programming languages available for doing specific tasks or making specific type
of applications. Web application languages, desktop application languages,
scripting languages are some of the examples for this. Among all the of the
programming languages C programming is the very basic programming language
useful for a mass. The basic Structure of a C program contains following sections,
Page - 1
Documentation Section consists of a set of comment lines giving the name of
the program and other details.
Link Section provides instructions to the compiler to link functions from the
system library.
Definition Section defines all symbolic constants.
Global Declaration Section: There are some variables and those variables are
declared in this section that is outside of all functions.
main( ) function: Every C program must have one main function section. This
section contains two parts, declaration and executable part.
Declaration Part declares all the variables used in the executable part.
There should be at least one statement in the executable part which contains
instructions to perform certain task.
The declaration and executable part must appear between the opening and
closing braces. All statements in the declaration part should end with the
semicolon.
The Subprogram Section contains all the user defined functions that are
called in the main function.
Page - 2
are the most precious resources of a computer, a program should be laid
out in such a manner that it utilizes the least amount of memory and pro -
cessing time.
Structural: To develop a program, the task must be broken down into a
number of subtasks. These subtasks are developed independently, and
each subtask is able to perform the assigned job without the help of any
other subtask. If a program is developed structurally, it becomes more
readable, and the testing and documentation process also gets easier.
Flexibility: A program should be flexible enough to handle most of the
changes without having to rewrite the entire program. Most of the programs
are developed for a certain period and they require modifications from time
to time. For example, in case of payroll management, as the time pro-
gresses, some employees may leave the company while some others may
join. Hence, the payroll application should be flexible enough to incorporate
all the changes without having to reconstruct the entire application.
Generality: Apart from flexibility, the program should also be general. Gen-
erality means that if a program is developed for a particular task, then it
should also be used for all similar tasks of the same domain. For example,
if a program is developed for a particular organization, then it should suit all
the other similar organizations.
Documentation: Documentation is one of the most important component
of an application development. Even if a program is developed following
the best programming practices, it will be rendered useless if the end user
is not able to fully utilize the functionality of the application. A well-docu-
mented application is also useful for other programmers because even in
the absence of the author, they can understand it.
Page - 3
to be applied to a module, only the affected subroutines have to be changed. This
makes the program easier to read and understand.
Modular programming has a main module and many auxiliary modules.
The main module is compiled as an executable (EXE), which calls the auxiliary
module functions. Auxiliary modules exist as separate executable files, which load
when the main EXE runs. Each module has a unique name assigned in the PRO-
GRAM statement. Function names across modules should be unique for easy ac-
cess if functions used by the main module must be exported.
Languages that support the module concept are IBM Assembler, COBOL,
FORTRAN, C, Python, etc. Among others the benefits of using modular program-
ming include
Less code has to be written.
Page - 4
design, development, and testing. Documentation is needed to supplement
human memory and to help organize program planning. Also, documentation is
critical to communicate with others who have an interest in the program,
especially other programmers who may be part of a programming team. And,
since turnover is high in the computer industry, written documentation is needed
so that those who come after you can make any necessary modifications in the
program or track down any errors that you missed.
Interpreter Compiler
Translates program one statement at a Scans the entire program and translates it
time. as a whole into machine code.
It takes less amount of time to analyze It takes large amount of time to analyze
the source code but the overall execu- the source code but the overall execution
tion time is slower. time is comparatively faster.
No intermediate object code is gener- Generates intermediate object code
ated, hence are memory efficient. which further requires linking, hence re-
quires more memory.
Continues translating the program until It generates the error message only after
the first error is met, in which case it scanning the whole program. Hence de-
stops. Hence debugging is easy. bugging is comparatively hard.
Programming language like Python, Programming language like C, C++ use
Ruby use interpreters. compilers.
Debugging
It is a term used extensively in programming. Debugging means detecting,
locating, and correcting errors or bugs (mistakes), usually by running the program.
Page - 5
These bugs are logic errors, such as telling a computer to repeat an operation but
not telling it how to stop repeating. In this phase you run the program using test
data that you devise. You must plan the test data carefully to make sure you test
every part of the program.
After debugging the debugger will return the error identified while
debugging the program. For the final stage, the execution of the program we
needed to clear the errors. In general different type of errors are there, related
with a program. They are classifies as syntax error, runtime error, and logical
error.
Syntax errors
Syntax or format errors are a major problem for most beginning programmers us -
ing languages such as C++, Java, and C#. A syntax error occurs when the pro-
grammer fails to obey one of the grammar rules of the language. Typically this in-
volves things like using the wrong case, putting punctuation where it is not sup-
posed to be, failing to put punctuation where it is supposed to be, etc.
Runtime errors
A runtime error occurs whenever the program instructs the computer to do some-
thing that it is either incapable or unwilling to do. Since there are a near infinite
number of things that fall in this category, there are a near infinite number of ways
to write programs that cause runtime errors. Runtime errors commonly occur
when statements are written in the wrong order, or perhaps the order is modified
by dragging statements up and down the screen after they are written. Another
common cause of runtime errors results from the construction of instructions that
the computer is unable to carry out.
One of the very good example for this runtime error is the classical divide by zero
error. This is the classical way to demonstrate a runtime error, instruct the com-
puter to divide any number by the value zero. Any value divided by 0 produces an
infinitely large result, which is too large to be accommodated by the computer.
Therefore, in most cases, the computer will tell you that it is unable to perform that
operation.
For example in C programming language.
Page - 6
Int a,b=10,c=0;
a=b/c;
This lines of statements will return runtime error based on zero division.
Logic errors
Logic errors are usually the most difficult kind of errors to find and fix, because
there frequently is no obvious indication of the error. Usually the program runs
successfully. It simply doesn't behave as it should. In other words, it simply
doesn't produce the correct answers.
The causes of logic errors
Logic errors usually result from one or some combination of the following three
causes:
You didn't understand how the program is supposed to behave.
You didn't understand the behavior of each operation that you wrote into
the program.
You were careless.
Apply modular programming concept will give the simplified logic version of
your program.
Structured Programming
C is called a structured programming language because to solve a large problem,
C programming language divides the problem into smaller modules called func-
tions or procedures each of which handles a particular responsibility. The program
which solves the entire problem is a collection of such functions. One major draw-
back of C language is that similar functions cannot be grouped inside a module or
class. Also functions cannot be associated to a type or structure. Thus data and
functions cannot be bound together. C++ language overcomes these problems by
introducing object oriented functionality in its programming capabilities.
Page - 7
Advantages
C structured programming is simple and easy to understand and imple-
ment.
It is well suited for small size implementation. However this is not re-
stricted. A good design can extend it to large size implementation.
Programmers do not require to know complex design concepts to start a
new program.
Disadvantages
Data and methods and not be bind together in a module.
Summary
In this module we discussed about the basic characteristics needed for a
program and the modular programming terminology. Along with these concepts
we also covered the converting mechanism of high level language into machine
level language in two different ways such as the complier and interpreter. Different
types of errors like syntax error, run time error and logical error are the concepts
we studied regarding with the debugging of a program. At last we discussed about
the concept of structured programming in the context of C programming
language.
Assignments
Page - 8
Reference
Page - 9