Programming Paradigms - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Programming Paradigms

Description:

Licensed under Creative Commons Attribution Sharealike Noncommercial ... Creative Commons Sharealike Attributions Noncommercial ... Perks. Intelligent People. ... – PowerPoint PPT presentation

Number of Views:294
Avg rating:3.0/5.0
Slides: 48
Provided by: rake3
Category:

less

Transcript and Presenter's Notes

Title: Programming Paradigms


1
Programming Paradigms
By, Janeve George janeve.g_at_directi.com
Nilesh Mevada nilesh.m_at_directi.com
(http//www.directi.com http//wiki.directi.com
http//careers.directi.com)?
Licensed under Creative Commons Attribution
Sharealike Noncommercial
1
2
Few Instruction
  • It's a workshop not a presentation !!!
  • Parking Lot
  • Perks

2
Creative Commons Sharealike Attributions
Noncommercial
3
Aim of the session
  • Introduction to programming concepts and
    techniques
  • Differentiate between various programming
    paradigms

Q Why there are so many programming
paradigms? A Q Isn't there 'one language'
that would suffice? A Q How can we deal with
understanding so many paradigms? A
3
Creative Commons Sharealike Attributions
Noncommercial
4
Flow of the session
  • Programming Paradigm Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

4
Creative Commons Sharealike Attributions
Noncommercial
5
Flow of the session
  • Programming Paradigm - Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

5
Creative Commons Sharealike Attributions
Noncommercial
6
Programming Paradigm - Definition
  • What are Programming Paradigms?
  • Fundamental style of computer programming.
    (wikipedia.org)?
  • It serves as a pattern or model for a
    programming? language

6
Creative Commons Sharealike Attributions
Noncommercial
7
Flow of the session
  • Programming Paradigm - Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

7
Creative Commons Sharealike Attributions
Noncommercial
8
Why bother about 'Programming Paradigms'?
8
Creative Commons Sharealike Attributions
Noncommercial
9
Why bother about 'Programming Paradigms'?
9
Creative Commons Sharealike Attributions
Noncommercial
10
Why bother about 'Programming Paradigms'?
10
Creative Commons Sharealike Attributions
Noncommercial
11
Why bother about 'Programming Paradigms'?
  • Tools (Programming Languages) may not suffice to
    deal with the real life problems.
  • They might not support the solution at all or
    only partially.
  • Learning new programming languages becomes easier
  • To bring innovations in programming technologies

11
Creative Commons Sharealike Attributions
Noncommercial
12
Flow of the session
  • Programming Paradigm - Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

12
Creative Commons Sharealike Attributions
Noncommercial
13
Appreciating 'Programming paradigms'
  • An example of how a trivial concept can
    affect/support a computation and hence a
    particular style of programming...

Execution Flow
Int X Int Y X Print( Y )
?
13
Creative Commons Sharealike Attributions
Noncommercial
14
Flow of the session
  • Programming Paradigm - Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

14
Creative Commons Sharealike Attributions
Noncommercial
15
Programming Concepts An Overview
Set of Programming Concepts Procedures Functions
Higher/1st Order Evaluation Eager/Lazy Variable
s Single/Multi store Scope Scope of
variables Typing State Internal/External Objects
Classes Concurrency on on on.....
15
Creative Commons Sharealike Attributions
Noncommercial
16
Programming Concepts An Overview
Set of Programming Concepts
Programming Model
Embraced by
Followed by
Programming Language(s)?
Subset of Concepts
16
Creative Commons Sharealike Attributions
Noncommercial
17
Programming Concepts An Overview
Set of Programming Concepts
OO Programming Model
Embraced by
Followed by
OO Programming Language(s)?
Subset of Concepts
  • Java
  • Ruby
  • Oz
  • C
  • Scala
  • Etc...
  • Objects
  • Classes
  • Inheritance
  • Polymorphism
  • Explicit State
  • Etc...

17
Creative Commons Sharealike Attributions
Noncommercial
18
Programming Concepts An Overview
Set of Programming Concepts
Functional Programming Model
Followed by
Embraced by
Functional Programming Language(s)?
Subset of Concepts
  • Lazy/Eager Evaluation
  • Functions
  • Higher Order Func.
  • Etc...
  • Haskell
  • Erlang
  • ML
  • Scheme
  • Etc...

18
Creative Commons Sharealike Attributions
Noncommercial
19
Programming Concepts An Overview
19
Creative Commons Sharealike Attributions
Noncommercial
20
Programming Concepts An Overview
20
Creative Commons Sharealike Attributions
Noncommercial
21
Programming Concepts An Overview
  • Few important concepts
  • Eager Evaluation
  • Lazy Evaluation
  • Procedures
  • Functions
  • External State
  • Internal State
  • Concurrency
  • Static vs Dynamic Typing

21
Creative Commons Sharealike Attributions
Noncommercial
22
Programming Concepts Eager Evaluation
  • An expression which is evaluated as soon as it
    gets bound to a variable
  • Importance
  • Simple
  • Commonly found
  • Easy implementation for languages
  • Problems
  • Expressions are always evaluated
  • Languages supporting easy evaluation
  • Almost all including java, c, c, etc.

22
Creative Commons Sharealike Attributions
Noncommercial
23
Programming Concepts Eager Evaluation
.... List Gen( int N ) ArrayList list new
ArrayList() list.add( N ) list.addAll(
Gen(N1) ) return list void myMethod ()
List K Gen(1) System.out.println(
"Elements " K.getElementAt( 3 ) ) ....
23
Creative Commons Sharealike Attributions
Noncommercial
24
Programming Concepts Lazy Evaluation
  • An expression is evaluated only when needed
  • Also known as delayed evaluation or call-by-need.
  • Importance
  • To deal with potentially infinite data.
  • Generally, calculations are not repeated.
  • Problems
  • Difficult at glance
  • Difficult to predict time/space complexity
  • Languages supporting Lazy Evaluation
  • Haskell, Oz, Scheme, OCamel

24
Creative Commons Sharealike Attributions
Noncommercial
25
Programming Concepts Lazy Evaluation
declare fun lazy Gen N N Gen
N1 end declare K Gen 1 Browse Elements
Nth K 3
25
Creative Commons Sharealike Attributions
Noncommercial
26
Programming Concepts Procedures
  • A code construct which can
  • Execute a set of statements in an order
  • Accept zero or more arguments
  • Return zero or more results
  • Produce a side effect
  • Importance
  • One of the most basic building block of any
    programming language
  • A means of telling the system how to execute some
    behavior
  • May be used as to abstract out functions, objects
    classes
  • Languages that support procedures
  • C, C, C, Oz

proc Max X Y ?Z if XgtY then ZX else ZY
end end
26
Creative Commons Sharealike Attributions
Noncommercial
27
Programming Concepts Procedures
local Default MaxOrDefault in Default10 proc
MaxOrDefault Arg ?Result if Arg gt Default
then Result Arg else Result
Default end end local Result
in MaxOrDefault 5 Result Browse
Result end end
27
Creative Commons Sharealike Attributions
Noncommercial
28
Programming Concepts Functions
  • A code construct which can
  • Execute a set of statements in a given order
  • Accept zero or more arguments
  • Returns only one result and no side effect
  • Pure functions avoid state and mutable data
  • Importance
  • A basic building block of many programming
    language
  • A means of telling the system how to execute some
    behavior
  • Can replicate a pure mathematical model
  • Languages that support Functions
  • Haskell, OCamel, ML, Oz

fun Max X Y if XgtY then ZX else ZY
end end Z Max 10, 20
28
Creative Commons Sharealike Attributions
Noncommercial
29
Programming Concepts Functions (Higher Order)?
  • Higher Order Functions
  • Accepts functions as arguments along with other
    types
  • Can return a function as result
  • Ordering means...
  • 1st order - having no functions as args
  • 2nd order - can have 1st order functions as
    args
  • nth order - can have n-1th order functions as
    args
  • We can build abstraction using Higher Order
    Functions

map f map f (xxs) f x map f
xs numbers 7,9,13 inc x x 1 more_numbers
map inc numbers
29
Creative Commons Sharealike Attributions
Noncommercial
30
Programming Concepts Functions (Higher Order)?
listsum 0 listsum (xxs) x listsum
xs listprod 1 listprod (xxs) x
listprod xs
fold op init init fold op init (xxs) x
op fold op init xs listsum fold ()
0 listprod fold () 1
30
Creative Commons Sharealike Attributions
Noncommercial
31
Programming Concepts External and Internal State
  • Explicit State
  • State remembrance across calls
  • Importance
  • One of the base concept for Object Orientation
  • Implicit state
  • Defined by the function for its internal
    calculations.
  • Importance
  • Storing temporary results which otherwise might
    require repetitive calls.
  • Languages that support external state
  • Object Oriented languages like Java, Smalltalk,
    etc
  • Languages that have global variables
  • Languages that support internal state
  • All languages that have variables in procedures /
    functions

31
Creative Commons Sharealike Attributions
Noncommercial
32
Programming Concepts External and Internal State
fun Sum Numbers Result NewCell 0
Input NewCell Numbers proc Sum
case _at_Input of nil then skip X Y
then Result _at_Result X
Input Y Sum end end
in Sum _at_Result end
32
Creative Commons Sharealike Attributions
Noncommercial
33
Programming Concepts Concurrency
  • Multiple and independent executions
  • From real-life problems point of view, the
    definition adds this clause and communicates
    only when needed
  • Importance
  • relates more to real-life problems
  • response time improved due to parallel executions
  • Problems
  • race condition
  • Languages that support concurrent execution
  • Java, Oz

thread ConcurrentFlow1 GenerateNumbers 1
10 end
33
Creative Commons Sharealike Attributions
Noncommercial
34
Programming Concepts Concurrency
fun GenerateNumbers FromArg ToArg Delay
100 if FromArg gt ToArg then nil else FromA
rg GenerateNumbers FromArg1
ToArg end end thread ConcurrentFlow1
GenerateNumbers 1 10 end thread ConcurrentFlow
2 GenerateNumbers 11 20 end Browse
ConcurrentFlow1 Browse ConcurrentFlow2
34
Creative Commons Sharealike Attributions
Noncommercial
35
Programming Concepts Concurrency
.... public void main(String args) throws
InterruptedException Temp temp new
Temp() createAConcurrentFlow(1,
10) createAConcurrentFlow(11,
20) .... private void createAConcurrentFlow(int
FromArg, int ToArg) new Runnable() public
void run() try new Temp().GenerateNumbe
rs(FromArg, ToArg) catch
(InterruptedException e) ....
35
Creative Commons Sharealike Attributions
Noncommercial
36
Programming Concepts Static Typing
  • Type checking is performed during compile-time
  • Variables should be defined before they're used.
  • Variables can be cast into other types
  • Variables don't get converted
  • Importance
  • Improved error-catching ability, efficiency,
    security
  • partial program verification
  • Problems
  • reducing expressiveness of the programming
    language
  • restrictions for the programmer on the programs
    he can write
  • Languages that use static typing
  • C, C, C, Java, ML, Pascal, Haskell

36
Creative Commons Sharealike Attributions
Noncommercial
37
Programming Concepts Static Typing
int num, sum // explicit declaration num 5 //
now use the variables sum 10 sum sum num
37
Creative Commons Sharealike Attributions
Noncommercial
38
Programming Concepts Dynamic Typing
  • Type checking is performed during runtime
  • It's not necessary to define the variable before
    used
  • Variables can be converted to other types
    implicitly
  • Importance
  • variables can be bound to any first-class-citizen
    in the lang. (proc, func, mix of data-types,
    etc.)?
  • independent compilations of the program (since no
    type checking at compile time)?
  • Problems
  • more type-error-prone code at run-time.
  • Languages that uses dynamic typing
  • JavaScript, Lisp, Perl, PHP, Prolog, Python, Ruby

38
Creative Commons Sharealike Attributions
Noncommercial
39
Programming Concepts Dynamic Typing
foo() x 1 x 'hello'
39
Creative Commons Sharealike Attributions
Noncommercial
40
Flow of the session
  • Programming Paradigm Definition
  • Why bother about 'Programming Paradigms'?
  • Appreciating 'Programming paradigms'
  • Programming Concepts
  • An Overview
  • Eager and Lazy Evaluation
  • Procedures
  • Functions
  • External and Internal State
  • Concurrency
  • Static vs Dynamic Typing
  • Some Real-Life Problems
  • Search (Java vs Prolog)?
  • Higher Order Functions (Java vs Haskell)?

40
Creative Commons Sharealike Attributions
Noncommercial
41
Some Real-Life Problems Prolog vs Java
Facts male(hrithik). male(shahrukh). male(
salman). male(abhishek). male(akshay). male(aamir)
. female(diya). female(aishwarya). female(katrina
). female(malaika). parent(hrithik,shahrukh). par
ent(hrithik,salman). parent(hrithik,diya). parent(
shahrukh,abhishek). parent(shahrukh,akshay). paren
t(salman,aishwarya). parent(salman,katrina). paren
t(salman,aamir). parent(diya,malaika).
Rules father(X,Y) - parent(X,Y),
male(X). mother(X,Y) - parent(X,Y),
female(X). grandparent(X,Y) - parent(X,Z),
parent(Z,Y). paternalgrandfather(X,Y) -
father(X,Z), father(Z,Y). sibling(X,Y) -
parent(Z,X), parent(Z,Y). brothers(X,Y) -
sibling(X,Y),male(X),male(Y), \ (XY).
Queries cmd mother(diya,malaika) Outupt
yes/no cmd mother(Mother,Child). Output
lists (mother,child) pair found in facts
according to associations defined
41
Creative Commons Sharealike Attributions
Noncommercial
42
Some Real-Life Problems Statistics
42
Creative Commons Sharealike Attributions
Noncommercial
43
How to approach Programming Paradigm?
  • Our Way was...
  • Concepts first, Languages Later.
  • Other effective ways...
  • Mastering any one programming model (e.g. Object
    Oriented) and then comparing it with others (e.g.
    functional, procedural, etc.)?

43
Creative Commons Sharealike Attributions
Noncommercial
44
References
  • Books
  • Concepts, Techniques Models Of Computer
    Programming by Peter Van Roy Seif Haridi
  • Links On Web
  • http//wikipedia.org
  • http//www.infocheese.com/programmingparadigms.htm
    l

44
Creative Commons Sharealike Attributions
Noncommercial
45
What we expect post this session
  • Experimentation with other programming languages
  • Functional language -gt Haskell / ML / Scheme
  • Object Oriented language -gt Java, C, C, Scala
  • Aspect Oriented language -gt AspectJ, AspectC
  • Logic language -gt Prolog / Mercury
  • Mixed languages -gt Scala, Oz
  • Sharing your experiences with us...
  • A testimonial

I want to thank you and DIRECTI for conducting
such a marvelous session and I am very much
indebted for that. I fell in love with LISP
programming language and found that it was very
much ideal for signal processing algos. The
approach u have suggested was just great and the
book you have suggested was really really great.
- Chinni Krishna, Mukt '08 Session Attendee
45
Creative Commons Sharealike Attributions
Noncommercial
46
Questions???janeve.g_at_directi.com
nilesh.m_at_directi.comhttp//directi.comhttp//ca
reers.directi.com Download slides
http//wiki.directi.com
46
47
Retrospective!!!janeve.g_at_directi.com
nilesh.m_at_directi.comhttp//directi.comhttp//ca
reers.directi.com Download slides
http//wiki.directi.com
47
Write a Comment
User Comments (0)
About PowerShow.com