PROGRAMMING PARADIGMS

 

Procedure or Imperative Programming

Procedural programming can sometimes be used as a synonym for imperative programming (specifying the steps the program must take to reach the desired state), but can also refer to a programming paradigm based upon the concept of the procedure call. Procedures, also known as routines, subroutines, methods, or functions simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself (recursion).

Procedural programming is often a better choice than simple sequential or unstructured programming in many situations which involve moderate complexity or which require significant ease of maintainability. Possible benefits:

  • The ability to re-use the same code at different places in the program without copying it.
  • An easier way to keep track of program flow than a collection of "GOTO" or "JUMP" statements (which can turn a large, complicated program into spaghetti code).
  • The ability to be strongly modular or structured.

 

Procedural Programming is a program with a sequence of instructions and data is held in a store.  The instructions are executed in sequence, and update the data.

 

 

Object Oriented Programming

Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. It is based on several techniques, including:

·         encapsulation

the principle of information hiding is the hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed.  It is the ability to provide users with a well-defined interface to a set of functions in a way which hides their internal workings. In object-oriented programming, it is the technique of keeping together data structures and the methods (procedures) which act on them.

·         modularity

is a software design technique that increases the extent to which software is composed from separate parts, called modules.

·         polymorphism

Generally, it is the ability to appear in many forms. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language (OOPL).

·         and inheritance

It is a way to form new classes (instances of which are called objects) using classes that have already been defined. The new classes, known as derived classes, take over (or inherit) the attributes and behavior of the pre-existing classes, which are referred to as base classes (or ancestor classes). It is intended to help reuse existing code with little or no modification.

It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP.

The focus of procedural programming is to break down a programming task into a collection of data structures and subroutines, whereas in object oriented programming it is to break down a programming task into objects. Either method can be valid for accomplishing a specific programming task. (Object orientation is often referred to as OO and object oriented programming as OOP.)

The most popular programming languages usually have both OOP and procedural aspects.

Some differences between pure object-oriented languages and non-OO procedural languages:

pure OO

pure procedural

methods

functions

objects

modules

message

call

attribute

variable

 

Note: 

In object-oriented programming, the term method refers to a subroutine that is exclusively associated either with a class (called class methods, static methods, or factory methods) or with an object (called instance methods).

Like a procedure in procedural programming languages, a method usually consists of a sequence of statements to perform an action, a set of input parameters to customize those actions, and possibly an output value (called return value) of some kind. The purpose of methods is to provide a mechanism for accessing (for both reading and writing) the private data stored in an object or a class.

 

 

 

 

Functional Programming

 

Functional programming is a style of programming that emphasizes the evaluation of expressions, rather than execution of commands. The expressions in these languages are formed by using functions to combine basic values. A functional language is a language that supports and encourages programming in a functional style.

For example, consider the task of calculating the sum of the integers from 1 to 10. In an imperative language such as C, this might be expressed using a simple loop, repeatedly updating the values held in an accumulator variable total and a counter variable i:

total = 0;
for (i=1; i<=10; i++)
   total += i;

In a functional language, the same program would be expressed without any variable updates. For example, in Haskell, the result can be calculated by evaluating the expression:

sum [1..10]

Here, [1..10] is an expression that represents the list of integers from 1 to 10, while sum is a function that can be used to calculate the sum of an arbitrary list of values.

The same idea could also be used in (strict) functional languages such as SML or Scheme, but it is more common to find such programs written with an explicit loop, often expressed recursively. Nevertheless, there is still no need to update the values of the variables involved:

SML:

let fun sum i tot = if i=0 then tot else sum (i-1) (tot+i)
in sum 10 0
end

 

It is often possible to write functional-style programs in an imperative language, and vice versa. It is then a matter of opinion whether a particular language can be described as functional or not.

 

Declarative Programming Language

A program is "declarative" if it describes what something is like, rather than how to create it. For example, HTML web pages are declarative because they describe what the page should contain — title, text, images — but not how to actually display the page on a computer screen. This is a different approach from imperative programming languages such as Fortran, C, and Java, which require the programmer to specify an algorithm to be run. In short, imperative programs explicitly specify an algorithm to achieve a goal, while declarative programs explicitly specify the goal and leave the implementation of the algorithm to the support software (for example, a SQL select statement specifies the properties of the data to be extracted from a database, not the process of extracting the data).

Declarative programming is interested in the what, but leaves the how up to interpretation.

 

 

 

Make a Free Website with Yola.