Programming Paradigms

As a Gd re-entry task, I was assigned to give presentation on Programming Paradigms by giving examples:

Here is its slides:

Here are some programmings which will help you to understand these programming paradigms:

I consider here a single program i.e ‘Fibonacci Series’ to in some programming languages of different paradigms that will help you understand the difference between these paradigms:

Basic Programming Paradigms are:
1) Imperative Paradigm
Procedural Paradigm
Structural Paradigm
2) Declarative Paradigm
Logical Paradigm
Functional Paradigm

Here is a brief description with programs:
1) Imperative Paradigm: Here we describe the sequential steps to solve the problem. i.e First Do this then Do that. i.e How we achieve the problem.
Example: I want a cup of tea, I will call my sister and tell her procedure about making a tea, i.e first take a tea pan, then put it on stove, then fire on the stove, add water, add suger, boil it, add milk… on….
So this style(paradigm) to achieve a problem(Tea in this case) is Imperative.

A fibonacci series program in Pascal language showing Procedural Paradigm.
 PROGRAM Fibonacci;
 First, Second, Temp : int64;
 count : integer;
 First := 0;
 Second := 1;
 for count := 0 to 10 do
 Temp := FIrst + Second;
 First := Second;
 Second := Temp;

A fibonacci series program in fortran language showing Structural Paradigm.
program Fibonacci
 integer :: f1,f2,f3,i
 i = 1
 f1 = 0
 f2 = 1
 f3 = f2 + f1
 f1 = f2
 f2 = f3
 i = i + 1
 if (f1<10) then
 print '(I1, A, $)', f1, ', '
 elseif (f1<100) then
 print '(I2, A, $)', f1, ', '
 print '(I3, A, $)', f1, ', '
 end if
 if (i==17) then
 end if
 end do
 print *, '...'
 end program Fibonacci

2) Declarative Paradigm: Here we describe ‘what to achieve, rather than How to achive’.
Example:I want a cup of tea, I will call my sister, and order her how to make a cup of tea. I am not descibing here producer to make a tea.

A fibonacci series program in Prolog language showing Logical Paradigm.

fib(0, 0).
fib(1, 1).
fib(N, NF) :-
 A is N - 1, B is N - 2,
 fib(A, AF), fib(B, BF),
 NF is AF + BF.

A fibonacci series program in Hasksell language showing Functional Paradigm. 
fib :: Integer -> Integer
fib n
 | n == 0 = 0
 | n == 1 = 1
 | n > 1 = fib (n-1) + fib (n-2)
 fibs :: [Integer]
 fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
 fastfib n = fibs !! n


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s