You are on page 1of 4

PROGRAMMING PARADIGMS

Programming paradigms are simply methods of programming.

PROCEDURAL PARADIGM

Describe, step by step, exactly the procedure that should be followed to solve a


problem. Procedural languages specify, exactly, the steps required to solve a
problem.

The problem with procedural languages is that it can be difficult to reuse code and
to modify solutions when better methods of solution are developed. In order to
address these problems, object-oriented languages (like Eiffel, Smalltalk and Java)
were developed.

These languages use the constructs sequence, selection and repetition.

For  example, to find the area of a rectangle the steps are:

 Read the length


 Read the breadth
 Multiply the length by the breadth
 Output the result

The point to note with these procedural languages is that the programmer has to
specify exactly what the computer is to do.

Procedural languages are used to solve a wide variety of problems. Some of these 
languages are more robust than others. This means that the compiler will not let
the programmer write statements that may lead to problems in certain
circumstances.

As stated earlier, there are procedural languages designed to solve scientific and


business problems. There are some that are particularly designed for solving
problems of control that need real time solutions.

Procedural languages may use functions and procedures but they always specify
the order in which instructions must be used to solve a problem. The use of
functions and procedures help programmers to reuse code but there is always the
danger of variables being altered inadvertently.

1
OBJECT-ORIENTED PARADIGM

For object-oriented paradigm the data and methods of manipulating the data, are
kept as a single unit called an object. An object comprises both data and
algorithms. The data describes the state of the object. Objects communicate by
sending messages to each other. When an object receives a message, it responds by
executing one of its algorithms. The algorithm may change the state of the object,
generate output, or send messages to other objects. OOPS are well-suited to
programming graphical user interface (GUIs). Typically, each element of a GUI is
represented by one object. The object determines both the state and the behavior of
the corresponding element.

For example, an object representing a window would have data for its position,
size and title. If the user closes the window, the OOPS sends a message to the
window object telling it to close itself. The window then executes an algorithm that
erases its image from the screen. The only way that a user can access the data is via
the object's methods. This means that, once an object is fully working, it cannot be
corrupted by the user. It also means that the internal workings of an object may be
changed without affecting any code that uses the object.

Data encapsulation is the combining together of the variables and the methods
that can operate on the variables so that the methods are the only ways of using the
variables. 

Advantages

In a broad sense, the greatest benefit of an object-oriented programming system is


that it imposes a powerful structure on computer programs. This structure can
make complex, intricate systems, such as GUIs, manageable. Several features that
contribute to this structure are:

Modularity

The objects in an OOPS are self-contained, and have clearly defined interfaces to
other objects. This facilitates writing modular code, which reduces the inherent
complexity of a program.

Extensibility

2
Adding a new feature is often simply a matter of defining an object to implement
it. Furthermore, new sub-objects can be defined without having to modify, or even
see, the original code.

In principle, the same thing can be done in a procedural language. However, for
technical reasons, it is more difficult, and it very often corrupts the original design
of the program, leading to unmanageable complexity.

Disadvantages

They are harder to code

FUNCTIONAL PARADIGM

Programs written using this paradigm use functions, which may call other
functions (including themselves). These functions have inputs and outputs.
Variables, as used in procedural languages, are not used 
in functional languages. Functional languages make a great deal of use of
recursion. This makes it a very powerful programming paradigm.

The functional programming paradigm provides a very high level view of


programming. All programs consist of a series of functions that use parameters for
input and pass values to other functions. There are no variables like the ones in
procedural languages. However, like procedural languages, the programmer has to
tell the computer the precise steps to be taken to solve a problem. Another facility
of functional programming that makes it a powerful programming paradigm 
is the use of recursion.

Functional languages are often simpler syntactically and make it easier to work on
abstract problems, but they can also be "further from the machine" in that their
programming model makes it hard to understand exactly how the code is translated
into machine language (which can be problematic for system programming).

DECLARATIVE PARADIGM

Further advance was made when declarative programming paradigms were


developed. For this paradigm the computer is told what the problem is, not how to
solve the problem. Given a database the computer searches for a solution. The
computer is not given a procedure to follow as in the paradigms discussed so far.
Another programming paradigm is the declarative one. Declarative languages tell
the computer what is wanted but do not provide the details of how to do it. These

3
languages are particularly useful when solving problems in artificial intelligence
such as medical diagnosis, fault finding in equipment and oil exploration. The
method is also used in robot control. An example of a declarative language is
Prolog.

SCRIPTING
A script is an interpreted language that runs on a client. That is they run on your
computer instead of on a web server. Scripts are used to add special multimedia
effects to web pages. Examples: animated graphics, scrolling messages, ads and
calendars. Scripts also allow interactive capabilities.

Scripting languages are typically not meant to be full-fledged programming


languages with support for large system development. For instance, they may not
have compile-time type checking or require variable declarations. Typically,
scripting languages require little syntax to get started but make it very easy to
make a mess.

Examples of scripting languages: javascript, VBScript and Perl.

SUMMARY

A programming language can support multiple paradigms. C++ is designed to


support elements of procedural programming, object-based programming, object-
oriented programming, and generic programming.

Designers and programmers can decide how to build a program using any or a mix
of these paradigm elements.

Thus a programmer can write a program in C++ that

 is a purely procedural program


 is a purely object-oriented program
 contains elements of both paradigms

You might also like