Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
70 views

Chapter 1 L2 Programming Paradigm

The document discusses different programming paradigms including imperative, declarative, object-oriented, functional, logic, and database paradigms. It provides definitions and examples for each paradigm. Imperative programming is based on changing state through assignment and includes procedural and parallel approaches. Declarative programming focuses on what needs to be done rather than how. Logic programming solves problems like puzzles through knowledge bases.

Uploaded by

Daryll De Guzman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Chapter 1 L2 Programming Paradigm

The document discusses different programming paradigms including imperative, declarative, object-oriented, functional, logic, and database paradigms. It provides definitions and examples for each paradigm. Imperative programming is based on changing state through assignment and includes procedural and parallel approaches. Declarative programming focuses on what needs to be done rather than how. Logic programming solves problems like puzzles through knowledge bases.

Uploaded by

Daryll De Guzman
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

ITEC 60: Integrated Programming

and Technologies 1
Chapter 1: Programming Paradigm
What is a paradigm?

• “Archetype, exemplar, and idea, according to which all


things were made” – Oxford English Dictionary

• “Example or pattern” –Webster Dictionary


What is a paradigm?

• In the programming language context

“pattern for modeling and solving problems”

“the way we think of problems and how they are


going to be solved”
PROGRAMMING PARADIGM

Imperative Programming Paradigm Declarative Programming Paradigm

Procedural programming paradigm Logic programming paradigms

Object oriented programming Functional programming paradigms

Database/Data driven programming


Parallel processing approach
approach
Imperative Programming Paradigm

• It is one of the oldest programming paradigm.

• based on Von Neumann architecture.

• works by changing the program state through assignment


statements.
Imperative Programming Paradigm

• performs step by step task by changing state.

• consist of several statements and after execution of all


the result is stored
Advantage of Imperative Programming Paradigm

1. Very simple to implement

2. It contains loops, variables etc.


Disadvantage of Imperative Programming Paradigm

1. Complex problem cannot be solved

2. Less efficient and less productive

3. Parallel programming is not possible


Examples of Imperative Programming Paradigm

1. C : developed by Dennis Ritchie and Ken Thompson

2. Fortran : developed by John Backus for IBM

3. Basic : developed by John G Kemeny and Thomas E Kurtz


Example: Average of five number in C

int marks[5] = { 12, 32, 45, 13, 19 };


int sum = 0;
float average = 0.0;
for (int i = 0; i < 5; i++) {
sum = sum + marks[i];
}
average = sum / 5;
Three categories of Imperative Programming
Paradigm

1. Procedural Programming Paradigm

2. Object Oriented Programming Paradigm

3. Parallel Processing Approach


Procedural programming paradigm

• The procedure is the principal building block of the program.

• The states of computation are represented by the stack with the


active procedure being found at the top.

• No restriction has been made on duplicate items on the stack so


recursion is allowed.

• It relies on procedures or subroutines to perform computations.

• also known as imperative programming.


Examples of Procedural programming
paradigm

1. C : developed by Dennis Ritchie and Ken Thompson

2. C++ : developed by Bjarne Stroustrup

3. Java : developed by James Gosling at Sun Microsystems

4. Pascal : developed by Niklaus Wirth


Example: Factorial in C++
#include <iostream>
using namespace std;
int main()
{
int i, fact = 1, num;
cout << "Enter any Number: ";
cin >> number;
for (i = 1; i <= num; i++) {
fact = fact * i;
}
cout << "Factorial of " << num << " is: " << fact << endl;
return 0;
}
Object oriented programming

• written as a collection of classes and object which are meant for


communication.

• The smallest and basic entity is object and all kind of computation
is performed on the objects only.

• emphasis is on data rather procedure.


Advantage of Object Oriented Programming

1. Data security

2. Inheritance

3. Code reusability

4. Flexible and abstraction is also present


Examples of Object Oriented programming
paradigm

1. Simula : first OOP language


2. Java : developed by James Gosling at Sun Microsystems
3. C++ : developed by Bjarne Stroustrup
4. Objective-C : designed by Brad Cox
5. Visual Basic .NET : developed by Microsoft
6. Python : developed by Guido van Rossum
7. Ruby : developed by Yukihiro Matsumoto
8. Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg
Example:
import java.io.*;
class create{ public void create(int userid, String name,
public static void main(String[] args) { String emailid, char sex, long mobile)
System.out.println(“Create!"); {
Signup s1 = new Signup(); System.out.println(“Lets create your account\n");
s1.create(22, “anna", “anna2@gmail.com", 'F', 89002); this.userid = 132;
} this.name = “Maria";
} this.emailid = “maria@gmail.com";
class Signup { this.sex = 'F';
int userid; this.mobile = 900558981;
String name; System.out.println("your account has been created");
String emailid; }
char sex; }
long mobile;
Parallel processing approach

• the processing of program instructions by dividing them


among multiple processors.

• posses many numbers of processor with the objective of


running a program in less time by dividing them.

• seems to be like divide and conquer


Declarative Programming Paradigm

• a style of building programs that expresses logic of computation


without talking about its control flow.

• It often considers programs as theories of some logic.

• focus is on what needs to be done rather how it should be done


basically emphasize on what code is actually doing.

• the only difference between imperative (how to do) and


declarative (what to do) programming paradigms.
Logic programming paradigms

• It can be termed as abstract model of computation. It would solve


logical problems like puzzles, series etc. In logic programming we
have a knowledge base which we know before and along with the
question and knowledge base which is given to machine, it
produces result.

• In logical programming the main emphasize is on knowledge base


and the problem. The execution of the program is very much like
proof of mathematical statement,
Example: Prolog (PROgramming in LOGic)

sum of two number in prolog:

predicates
sumoftwonumber(integer, integer)
clauses

sum(0, 0).
sum(n, r):-
n1=n-1,
sum(n1, r1),
r=r1+n
Functional Programming Paradigm

• Operate only through functions which return one value given a list
of parameters.

• Functions themselves are considered values that can be passed to


other functions
Example of Functional Programming
Paradigm:

1. JavaScript : developed by Brendan Eich

2. Haskwell : developed by Lennart Augustsson, Dave Barton

3. Scala : developed by Martin Odersky

4. Erlang : developed by Joe Armstrong, Robert Virding

5. Lisp : developed by John Mccarthy


Database/Data driven programming approach

• A database program is the heart of a business information system


and provides file creation, data entry, update, query and reporting
functions.

• There are several programming languages that are developed


mostly for database application.
Example:

CREATE DATABASE databaseAddress;


CREATE TABLE Address (
PersonID int,
LastName varchar(200),
FirstName varchar(200),
Address varchar(200),
City varchar(200),
State varchar(200)
);

You might also like