TPL1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Programming Paradigm

A programming paradigm is an approach to solve problems using some programming language or


also we can say it is a method to solve a problem using tools and techniques that are available to us
following some approach. There are lots of programming languages that are known but all of them
need to follow some strategy when they are implemented and this methodology/strategy is
paradigms. Apart from a variety of programming languages, there are lots of paradigms to fulfll every
demand.
The programming paradigmn consists of two types:

1. Imperative Programming as the name suggests is a type of programming paradigm that


describes how the program executes. Developers are more concerned with how to get an answer step
by step. It comprises the sequence of command imperatives. In this, the order of execution is very
important and uses both mutable and immutable data. Fortran, Java , c++, c programming languages
are examples of imperative programming.
2.Declarative Programming as the name suggests is a type of programming paradigm that
describes what programs to be executed. Developers are more concerned with the answer that is
received. It declares what kind of results we want and leaves programming language aside focusing
on simply figuring out how to produce them. In simple words, it mainly focuses on the end result. It
expresses the logic of computation. Miranda, Erlang, Haskell, and Prolog are a few popular examples
of declarative programming.

Let us go on a whirlwind tour of 4 different sub programming paradigms - Procedural, Object-


Oriented, Functional and Logical.
1. Procedural Programming
Procedural programming can also be referred to as imperative programming. It is a programming
paradigm based upon the concept of procedure calls, in which statements are structured into
procedures (also known as subroutines or functions). They are a list of instructions to tell the
computer what to do step by step, Procedural programming languages are known as top-down
languages. Most of the early programming languages are all procedural.
Examples of Procedural languages: FORTRAN, COBOL, ALGOL, BASIC, C and Pascal.

2. Object-Oriented Programming(00):
In this framework, all real-world entities are represented by Classes. Objects are instances of classes
so each object encapsulates a state and behaviour. State implies the fields, attributes of the object
and behaviour is what you do with the state of the object and they are the methods. Objects interact
with each other by passing messages.

3. Logical Programming
Logical programming is a computer programming paradigm that has its foundations in mathematical
logic in which program statements express facts and rules about problems within a system.
Rules are written as logical clauses with a head and a body. They also follow a declarative rather than
an imperative approach. However, what does that mean?
To understand how a problem can be solved in logical programming, you need to know about the
building blocks - Facts and Rules -
Let us understand the difference between Imperative and declarative programming.
Imagine you walk into your favourite coffee place and you would like to order some coffee.
The imperative approach will be:
Enter the coffee shop
. Queue in the line and wait for the barista asking you for your order
. Order
. Yes, for takeaway, please
• Pay
. Present your loyalty card to collect points
. Take your order and walk away

The declarative approach:


• A large latte for takeaway, please
So rather than providing a step by step instruction (imperative), you tell the system what you need and
let it try to come up with a solution (declarative).
Prolog follows the Logical paradigm and is probably the most famous language in the logical
programming family.
Prolog has been enormously influential in the domains of theorem proving, expert systems, natural
language processing and in the field of artificial intelligence (notably IBM's Watson2) in general
Prolog, like SQL, has two main aspects, one to express the data and another to query it. The basic
constructs of logical programming, terms, and statements, are inherited from logic. There are three
basic statements:
. Facts are fundamental assertions about the problem domain (e.g. "Socrates is a man")
. Rules are inferences about facts in the domain (e.g. "All men are mortal.")
. Queries are questions about that domain (e.g. "Is Socrates mortal?")
4. Functional Programming
Functional programming contains only functions without mutating the state or data. It means that
there are no global data/variables. Composing and applying function is the main driving force in this
paradigm. A function can take another as an argument and return a new function. The first high-level
functional programming language, developed in the 195os, was LISP. This language laid the
foundation for many characteristics of modern functional programming languages.
Example: Factorial program using LISP
Functional programming consists only of PURE functions. So, what do you understand by Pure
functions?
Pure functions are those which take an argument list as an input and whose output is a return value.
Now you may feel that all functions are pure as any function takes in values and returns a value.

You might also like