Different Paradigms For Problem Solving
Different Paradigms For Problem Solving
Paradigm is a model that has distinct features, frameworks, patterns, and style which help
you solve a particular problem.
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.
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:
Logical programming can be used to express knowledge in a way that does not
depend on the
implementation, making programs more flexible, compressed and understandable.
It enables knowledge to be separated from use, i.e. the machine architecture can be
changed
without changing programs or their underlying code.
It can be altered and extended in natural ways to support special forms of
knowledge, such
as meta-level of higher-order knowledge.
It can be used in non-computational disciplines relying on reasoning and precise
means of
expression.
3. Functional Programming
Functional programming is a programming paradigm where you have a style of
building the structure and elements of computer programs. Here you treat
computation as an evaluation of mathematical functions and you avoid changing-
state and mutable data.
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.
For example, if a function relies on the global variable or class member’s data, then it
is not pure. And in such cases, the return value of that function is not entirely
dependent on the list of arguments received as input and can also have side effects.
So, what do you understand by the term side effect? A side effect is a change in the
state of an application that is observable outside the called function other than its
return value. For example: Modifying any external variable or object property such as
a global variable, or a variable in the parent function scope chain.
Pure functions – As seen above, if the input is an array, the output will be a new
array and the input array will not be modified. So in case of pure functions, the output
depends only on the input.
Here’s a function in the language Scala that takes values and returns their sum.
Recursion-A recursive function is a function that calls itself during its execution. This
enables the function to repeat itself several times, the result being outputted at the
end of each iteration. Below is an example of a recursive function.
end function
The function Count() above uses recursion to count from any number between 1 and
9, to the number 10. For example, Count(1) would return 2,3,4,5,6,7,8,9,10. Count(7)
would return 8,9,10.
4. Object-Oriented Programming(OO):
In this framework, all real-world entities are represented by Classes. Objects are
instances of classes so each object encapsulates a state and behavior. State implies
the fields, attributes of the object and behavior is what you do with the state of the
object and they are the methods. Objects interact with each other by passing
messages.
Features of OO:
Programming languages that have implemented the OO paradigm are: Ruby, Java,
C++, Python, Simula(the first OOP language)