This action might not be possible to undo. Are you sure you want to continue?
If we are to use a more specific definition of a paradigm; a paradigm is an idealized pattern of usage under which some agent can operate. From this definition a programming paradigm is the pattern of thought that computer programmers can operate when writing a program. A programming paradigm is a way of thinking about problems and their solutions, or an approach on how to use a computer to implement those solutions. For a programmer to solve a particular problem, he needs to know several things, namely: • • • Must have a clear picture of what the problem is supposed to do. Must have an understanding of how the program should work to produce the desired result. Must understand how the program fits in its environment
In order to understand what a program is supposed to do, how it should work, and know the environment in which it should function, the programmer must form a mental model of the problem. A mental model is like a simulation of an object or an abstract concept. It is used to predict the behavior of the problem under different circumstances. The purpose of a paradigm is for the programmer to have mental models of a solution to the problem. A paradigm is not to be confused with the programming language. While the programming language provides the means of to program the computer, it does not necessarily provide a mental model for the programmer. But there are instances when a particular programming language seems to impose a programming paradigm. For example, the C + + language being object-oriented approach in solving problems.
Major Programming Paradigm There are several kinds of major programming paradigms; the most common are the following: 1. Imperative 2. Logical 3. Functional
4. Object-oriented It is quite possible that a problems is solvable with one type of paradigm can also be solved using the others. But there are certain types of problems that are best solved by following a certain paradigm.
Imperative Paradigm The imperative programming paradigm is characterized by programming with states and commands that modify the states. Imperative means a command or order, while a command or a procedure means a particular course of action. It means that imperative programming implies procedures (or programs) or directions for performing an action. The imperative paradigm is an abstraction of real computers, which are based on the Von Neumann machine. Computers have registers and memories; these memories can be thought of as storage for variables. Imperative programming is based on the idea that the program manipulates the stored variables. A variable, which implies a particular location in memory, may be assigned a value and a later re-assigned to another value. The collection of names and the associated values together with the procedures for manipulating them constitutes the states. The imperative paradigm assumes that a computer can maintain through environment variables any change in the computations process. It recognizes the fact that computers have re-usable memory that can change state. Computations are performed through a guided sequence of steps, in which variables are changed or referred to. The order of the steps to follow is crucial, because a given step will have a different effect depending on the current state of the variables. For example in a shorting program, the initial state includes the array of values to be sorted. When the program is finished the final state are the sorted values, while the intermediate state represents the progress towards this goal. Popular programming languages are more often imperative mainly because of two reasons: 1) The imperative paradigm closely resembles the actual computer or machine itself, so the programmer is much closer to the machine. 2) Because it is the only one sufficient enough for widespread use. An imperative language can be easily translated to an efficient machine code, so they are considered highly efficient. The imperative paradigm is also popular because the programmer can easily express his own solutions to the problem.
Some disadvantages language with this paradigm is that some problems are hard to model using this paradigm. The order of the steps is crucial, which makes it difficult for some problems. And unless programs are carefully written, an imperative program can only be understood in terms of its execution behavior. The reason is that during the execution of the program, any variable may be assigned a different value or the control may be transferred to a different location that makes it hard to determine current state of the program may need to be examined. When imperative programming is combined with subprograms it is called procedural programming also called structured programming. Examples of procedural programming languages are FORTRAN, COBOL, C and Pascal. Logical Paradigm The logical paradigm takes a declarative approach to problem-solving. Various logical assertions are made about a situation to establish all the known facts. The role of the computer becomes maintaining data and logical deductions and relations. This logical approach to a problem is useful for expressing problems where it is not obvious what the function should be. A logical programming paradigm can be divided into three steps: 1. A series of definition/declarations that define the problem domain. 2. Statements of relevant facts. 3. Statements of goals in the form of queries. The solution is derived from deduction of the available facts, and they are returned as query. The logical programming paradigm has several advantages. One, the system solves the problems; so programming steps themselves are kept to a minimum. Second, since it is largely based on mathematical logic, proving the validity of a given program becomes simple. Functional Paradigm