Saturday, March 6, 2010

Programming Paradigms

Object-oriented programming is one of several programming paradigms. Other programming
paradigms include the imperative programming paradigm (as exemplified
by languages such as Pascal or C), the logic programming paradigm (Prolog), and the
functional programming paradigm (exemplified by languages such as ML, Haskell or
Lisp). Logic and functional languages are said to be declarative languages.
We use the word paradigm to mean “any example or model”.
This usage of the word was popularised by the science historian Thomas Kuhn.
He used the term to describe a set of theories, standards and methods that together
represent a way of organising knowledge—a way of viewing the world.
Thus a programming paradigm is a
. . . way of conceptualising what it means to perform computation and how
tasks to be carried out on a computer should be structured and organised.
We can distinguish between two types of programming languages: Imperative
languages and declarative languages. Imperative knowledge describes how-to knowledge
while declarative knowledge is what-is knowledge.
A program is ”declarative” if it describes what something is like, rather than how
to create it. This is a different approach from traditional imperative programming
languages such as Fortran, and C, which require the programmer to specify an algorithm
to be run. In short, imperative programs make the algorithm explicit and
leave the goal implicit, while declarative programs make the goal explicit and leave
the algorithm implicit.
Imperative languages require you to write down a step-by-step recipe specifing
how something is to be done. For example to calculate the factorial function in an
imperative language we would write something like:
public int factorial(int n) {
int ans=1;
for (int i = 2; i <= n; i++){
ans = ans i;
}
return ans;
}
Here, we give a procedure (a set of steps) that when followed will produce the
answer.

No comments:

Post a Comment