jigar gaglani. programming paradigm is a fundamental style of computer programming paradigms...
TRANSCRIPT
![Page 1: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/1.jpg)
Jigar Gaglani
![Page 2: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/2.jpg)
Programming paradigm is a fundamental style of computer programming
Paradigms differ in concepts and abstractions used to represent the elements of program
![Page 3: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/3.jpg)
Procedural/Imperative Functional Logic Object-Oriented
![Page 4: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/4.jpg)
Derived from latin word imperare means “to command”
It is based on commands that update variables in storage
Is a programming paradigm that describes computation in terms of statements that change a program state.
![Page 5: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/5.jpg)
It defines sequences of commands for the computer to perform
Imperative programming is characterized by programming with a state and commands
![Page 6: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/6.jpg)
In imperative programming, a name may be assigned to a value and later reassigned to another value.
A name is tied to two bindings, a binding to a location and to a value.
The location is called the l-value and the value is called the r-value.
![Page 7: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/7.jpg)
For example, • X := X+2
Assignment changes the value at a location.
A program execution generates a sequence of states
![Page 8: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/8.jpg)
The unstructured commands contains:• assignment command, • sequential composition of commands, • a provision to identify a command with a
label,• unconditional and conditional GOTO
commands
![Page 9: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/9.jpg)
The unconditional goto command has the form: • goto LABELi
The sequence of instructions next executed begin with the command labeled with LABELi.
The conditional goto command has the form: • if conditional expression then goto LABELi
![Page 10: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/10.jpg)
The goal of structured programming is to provide control structures that make it easier to reason about imperative programs.
![Page 11: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/11.jpg)
an IF statement corresponds to an If condition then command and a DO statement corresponds to a While condition Do command.
• IF guard --> command FI=if guard then
command• DO guard --> command OD=while guard do
command
![Page 12: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/12.jpg)
An imperative program can only be understood in terms of its execution behavior.
Thus, the whole program may need to be examined in order to understand even a small portion of code.
![Page 13: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/13.jpg)
The program is built from one or more procedures
It provides a programmer a means to define precisely each step in the performance of a task.
![Page 14: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/14.jpg)
The ability to re-use the same code at different places in the program without copying it.
An easier way to keep track of program flow than a collection of "GOTO" or "JUMP" statements
![Page 15: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/15.jpg)
Declarative programming is a non-imperative style of programming
Does not explicitly list command or steps that need to be carried out to achieve the results.
![Page 16: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/16.jpg)
For example:• List<int> collection = new List<int>
{1,2,3,4,5 };
Imperative programming• List<int> results = new List<int>();• foreach(var num in collection){ if (num % 2 != 0) results.Add(num);}
![Page 17: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/17.jpg)
Declarative programming• var results = collection.Where( num=>num
%2 != 0);
Does not step through the collection
![Page 18: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/18.jpg)
Procedural• Assembler, Fortran, Cobol, C, etc
Non-Procedural• SQL, Visual Basic, etc etc.
![Page 19: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/19.jpg)
It treats computation as the evaluation of mathematical functions and avoids state and mutable data.
It emphasizes the application of functions, in contrast to the imperative programming style
![Page 20: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/20.jpg)
Functional programming is all about expressions.
Functions are used as objects in FP.
Functional Programming is about abstraction and reducing complexity
![Page 21: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/21.jpg)
spam = ['pork','ham','spices']numbers = [1,2,3,4,5]def eggs(item): return item
map(aFunction, aSequence)
![Page 22: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/22.jpg)
L = map(eggs, spam)print L
Same thing could have been done by: • for i in spam: L.append(i)
print L
![Page 23: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/23.jpg)
If we want to create a new list of only odd numbers :• def isOdd(n): return (n%2 != 0)• L = filter(isOdd, numbers)• print L
Alternatively• def isOdd(n): return (n%2 != 0)• for i in numbers:• if isOdd(i):• L.append(i)• print L
![Page 24: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/24.jpg)
It is the use of mathematical logic for computer programming
The problem-solving task is split between the programmer and theorem-prover
![Page 25: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/25.jpg)
To study logic programming means to study proofs.
It is based upon the fact of a backwards reasoning proof
Eg. :• If B1 and … and Bn then H
![Page 26: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/26.jpg)
Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics
It is based on Facts and Rules
![Page 27: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/27.jpg)
Simple Facts:• Facts either consist of a particular item or a
relation between items.
For Eg :• the fact that it is sunny is represented by writing
the program : sunny.
We can now ask a query of Prolog by asking • ?- sunny.
![Page 28: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/28.jpg)
facts consist of a relation and the items that this refers to, called arguments
A general model is shown below:
relation(<argument1>,<argument2>,....,<argumentN> ).
![Page 29: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/29.jpg)
The basic Prolog terms are an integer, an atom, a variable or a structure.
Example : • likes(john,mary).
In the above fact john and mary are two atomes.
![Page 30: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/30.jpg)
Consider the following sentence : • 'All men are mortal'
We can express this as :• mortal(X) :- human(X).
Let us define the fact that Socrate is a human. • mortal(X) :- human(X).
human(socrate).
![Page 31: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/31.jpg)
Now if we ask to prolog : • ?- mortal(socrate).
What prolog will respond ?
Why ?
![Page 32: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/32.jpg)
One of Prolog's most useful features is the simple way it lets us state generalizations.
Example:• enjoys(vincent,X) :- burger(X).
Vincent enjoys burgers, except Big Kahuna burgers, how do we state this in Prolog?
![Page 33: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/33.jpg)
As a first step, let's introduce another built in predicate fail/0
fail enables us to write some interesting programs, and in particular, it lets us define exceptions to general rules
![Page 34: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/34.jpg)
Consider the following code: • enjoys(vincent,X) :- big_kahuna_burger(X),!,
fail.enjoys(vincent,X) :- burger(X). burger(X) :- big_mac(X).burger(X) :- big_kahuna_burger(X). big_mac(a).big_kahuna_burger(b).big_mac(c).
![Page 35: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/35.jpg)
The first two lines describe Vincent's preferences.
The last 4 lines describe a world containing 3 burgers, a, b, and c
![Page 36: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/36.jpg)
This is what happens:
• ?- enjoys(vincent,a).yes ?- enjoys(vincent,b).no ?- enjoys(vincent,c).yes
![Page 37: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/37.jpg)
The key is the combination of ! and fail in the first line
This cut-fail combination lets us define a form of negation called negation as failure
General notation: • neg(Goal) :- Goal,!,fail.
neg(Goal).
![Page 38: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/38.jpg)
For any Prolog goal, neg(Goal) will succeed precisely if Goal does not succeed.
Using our new neg predicate, we can describe Vincent's preferences as:• enjoys(vincent,X) :- burger(X), neg(big_kahu
na_burger(X)).
![Page 39: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/39.jpg)
Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of datafields and methods together with their interactions – to design applications and computer programs.
![Page 40: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/40.jpg)
It is a paradigm where we focus real life objects while programming any solution.
We actually write behaviours of our programming objects, those behaviours are called methods in objected oriented programming.
![Page 41: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/41.jpg)
They enable programmers to create modules that do not need to be changed when a new type of object is added.
A programmer can simply create a new object that inherits many of its features from existing objects.
![Page 42: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/42.jpg)
Class Object Instance Method Message passing Inheritance Abstraction Encapsulation Polymorphism Decoupling
![Page 43: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/43.jpg)
Encapsulation:• a logical boundary around methods and
properties Inheritance Re-usability
• method overloading and overriding Information Hiding
• is achieved through "Access Modifiers"
![Page 44: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/44.jpg)
What are the differences between these programming paradigms, and are they better suited to particular problems or do any use-cases favor one over the others?
![Page 45: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/45.jpg)
![Page 46: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/46.jpg)
![Page 47: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/47.jpg)
![Page 48: Jigar Gaglani. Programming paradigm is a fundamental style of computer programming Paradigms differ in concepts and abstractions used to represent](https://reader035.vdocuments.us/reader035/viewer/2022062722/56649f355503460f94c5312f/html5/thumbnails/48.jpg)
http://en.wikipedia.org/wiki/Imperative_programming
http://www.emu.edu.tr/aelci/Courses/D-318/D-318-Files/plbook/imperati.htm
http://en.wikipedia.org/wiki/Procedural_programming
http://www.ocaml-tutorial.org/functional_programming
http://boklm.eu/prolog/page_4.html http://cs.union.edu/~striegnk/learn-prolog-
now/html/node90.html