0% found this document useful (0 votes)
15 views

Part 1 - Paradigms, Levels, and Importance of Programming

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

Part 1 - Paradigms, Levels, and Importance of Programming

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Paradigms, Levels, and

Importance of Programming
Languages
PART 1 [PARADIGMS]
-Orquesta, R.
Paradigms

Is a “way of” doing things, not a concrete thing or meant to be exclusive. It


could be various, combination or a mixture.
Paradigm: Imperative Programming

Based on Von Neumann architecture, closely related to machine


architecture.
It works by changing the program state through assignment statements. It
performs step by step task by changing state. The main focus is on how to
achieve the goal. The paradigm consists of several statements and after
execution of all the result is stored.
Paradigm: Imperative Programming
Advantage:
• Very simple to implement
• It contains loops
• variables etc.
Disadvantage:
• Complex problem cannot be solved
• Less efficient and less productive
• Parallel programming is not possible
Paradigm: Imperative Programming

Examples of Programming Languages that is using Imperative Programming


Paradigm
• C Programming Language: by Dennis Ritchie & Ken Thompson
• Fortran Programming Language: by John Backus for IBM
• Basic Programming Language: by John G. Kemeny & Thomas E. Kurtz.
Paradigm: Imperative Programming
Example Code:
// 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;
Paradigm: Imperative Programming

Imperative programming is divided into three broad categories:


• Procedural Programming
• Object Oriented Programming
• Parallel Processing.
Paradigm: Procedural Programming

Emphasizes on procedure in terms of underlying machine model. There is no


difference in between procedural and imperative approach.
It has the ability to reuse the code and it was boon at that time when it was in
use because of its reusability.
Paradigm: Procedural Programming
Examples of Programming Languages that is using Procedural Programming
Paradigm
• C Programming Language: by Dennis Ritchie & Ken Thompson
• C++ Programming Language: by Bjarne Stroustrup
• Java Programming Language: by James Gosling of Sun Microsystems
• ColdFusion : by J J Allaire
• Pascal : by Niklaus Wirth
Paradigm: Procedural Programming
Example Code
#include 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;
}
Paradigm: Object Oriented Programming

Is 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. More emphasis is on data not
on the procedure and more flexible than any other paradigm.
Paradigm: Object Oriented Programming
Advantages:
• Data security
• Inheritance
• Code reusability
• Flexible
• Abstraction is also present
Paradigm: Object Oriented Programming
Examples of Programming Language that is using Object Oriented Programming Paradigm

Simula Programming Language: named as the first OOP language


Java Programming Language : by James Gosling of Sun Microsystems
C++ Programming Language : by Bjarne Stroustrup
Objective-C Programming Language : by Brad Cox
Visual Basic .NET Programming Language : by Microsoft
Python Programming Language : by Guido van Rossum
Ruby Programming Language : by Yukihiro Matsumoto
Smalltalk Programming Language : by Alan Kay, Dan Ingalls, and Adele Goldberg
Paradigm: Object Oriented Programming
Example Code
import java.io.*;
class GFG {
public static void main(String[] args) {
System.out.println("GfG!");
Signup s1 = new Signup();
s1.create(22, "riya", "[email protected]", 'F', 89002);
}
}
Paradigm: Object Oriented Programming
Example Code (continue…)
class Signup{int userid; String name; String emailid; char sex; long mob;
public void create(int userid, String name, String emailid, char sex, long mob){
System.out.println("Welcome to GeeksforGeeks\nLets create your account\n");
this.userid = 132;
this.name = "Radha";
this.emailid = "[email protected]";
this.sex = 'F’;
this.mob = 900558981;
System.out.println("your account has been created");
}
}
Paradigm: Parallel Processing Approach

Parallel processing is the processing of program instructions by dividing


them among multiple processors. A parallel processing system posses many
numbers of processor with the objective of running a program in less time by
dividing them. This approach seems to be like divide and conquer.
Examples Programming Language are NESL (one of the oldest one) and
C/C++ also supports because of some library function.
Paradigm: Declarative Programming
In computer science the declarative programming is 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. It may simplify writing parallel programs. The focus is on what needs to be
done not on how it should be done, it basically emphasize on what code is actually doing. It
declare the result we want not on how it was produced.
This is the only difference between imperative (how to do) and declarative (what to do)
programming paradigms. It is a programming by specifying the result you want, not how to get it.
Control flow in declarative programming is implicit. The programmer states only what the result
should look like, not how to obtain it.
Declarative programming paradigm is further divided into three major groups:
• Logic
• Functional
• Database
Paradigm: Logic Programming

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 normal programming
languages, such concept of knowledge base is not available but while using
the concept of artificial intelligence, machine learning we have some models
like Perception model which is using the same mechanism.
Paradigm: Logic Programming
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 code in Prolog
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
select upper(name)
from people
where length(name) > 5
order by name
Paradigm: Functional Programming
The functional programming paradigms has its roots in
mathematics and it is language independent. The key principal of
this paradigm is the execution of series of mathematical
functions. The central model for the abstraction is the function
which is meant for some specific computation and not the data
structure. Data are loosely coupled to functions. The function
hides their implementation. Function can be replaced with their
values without changing the meaning of the program. Some of
the languages like Perl, Javascript mostly uses this paradigm.
Paradigm: Functional Programming
Examples of Programming Language that is using Functional Programming Paradigm
• JavaScript : by Brendan Eich
• Haskwell : by Lennart Augustsson & Dave Barton
• Scala : by Martin Odersky
• Erlang : by Joe Armstrong & Robert Virding
• Lisp : by John Mccarthy
• ML : by Robin Milner
• Clojure : by Rich Hickey
Paradigm: Database/Data Driven
Programming Approach
This programming methodology is based on data and its movement.
Program statements are defined by data rather than hard-coding a series of
steps. 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. For example SQL. It is applied to streams structured
data, for filtering, transforming, aggregating (such as computing statistics),
or calling other programs. So it has its own wide application.
Paradigm: Database/Data Driven
Programming Approach
Example of Database/Data Driven programming approach

CREATE DATABASE databaseAddress;


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

You might also like