Imperative and-functional-programming

ramesesfrancia 318 views 23 slides Mar 14, 2016
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

Programming Paradigm


Slide Content

Imperative and
Functional Programming
Rameses Francia
Mark Anthony Sencio

Imperative and Functional
•Programming paradigm.

programming paradigm.
•Fundamental style of computer programming.
•Paradigm differ in concepts and abstractions used to
represent the elements of program.

Imperative programming
How it stared?
•Latin word “imperare” means to “to command”
•Machine languages of the original computers
•FORTRAN

John Backus at IBM starting in 1954
•the first major programming language to remove the
obstacles presented by machine code .

Imperative programming
How it stated?
Fortran
compiled language
•Named variables
•Complex expressions
•Subprograms
•many other features now common in imperative languages. 

Imperative Programming languages
•Basic
•C
•Assembly
•Java
•Ada
•PASCAL
•Forton

Imperative Programming
•based on commands that update variables in storage.
•assignment changes the value at a location.
•a program execution generates a sequence of states.

IMPERATIVE
PROGRAMMING IS
THE MOST POPULAR

Imperative
programming is
the easiest

IMPERATIVE
PROGRAMMING IS
THE WORST

Because….
• ERROR-PRONE
• NOT SCALABLE
• TOO COMPLICATED

How it works in PL’s?

getRemoteData(“example.com”, { data, error in
if error == nil {
parseData(data, { parsed, error in
if error == nil {
handleParsedData(parsed)
} else {
displayError(error)
}
})
} else {
dislpayError(error)
}
})

getRemoteData(“example.com”, { data, error in
if error == nil {
parseData(data, { parsed, error in
if error == nil {
if parsedDataValid(parsed) {
handleParseData(parsed)
} else {
displayError(error)
}
})
} else {
dislpayError(error)
}
})

getRemoteData(“example.com”, { data, error in
if error == nil {
parseData(data, { parsed, error in
if error == nil {
if ParsedDataValid(parsed) {
saveParsedDataIncache (parsed, { error in
if error == nil {
handleParseData(parsed)
} else {
displayError(error)
}
})
} else {
dislpayError(error)
}
})

getRemoteData(“example.com”, { data, error in
if error == nil {
parseData(data, { parsed, error in
if error == nil {
if ParsedDataValid(parsed) {
saveParsedDataInCache(parsed, { error in
if error == nil {
handleParseData(parsed), { error
in
if error == nil {
displaySuccess()
} else {
displayError(error)
}
})
} else {
dislpayError(error)
}
})

Sample program of a imperative
using java programming
Java Code
SciCal.txt

functional programming
•Is when functions, not objects or procedures, are used as
the fundamental building blocks of a program.
•Abstraction and reducing complexity
•Lambda calculus
•Haskell

Functional programming
brief history
•Lambda calculus(Church and Rosser 1936)
•LISP(McCarthy 1960)
•Algol 60(Naure et al. 1963)
•ISWIM(Landin 1966)
•PAL(Evans 1968)
•SASL(Turner 1973-83)
•Development in Edinburgh(1969-80) –NPL, early ML, HOPE
•Miranda(1986)
•Haskell(1992)

Functional programming
HOW IT WORKS IN PL?
•Computations is carried out entirely through evaluation of
expressions.
•Emphasizes the composition and arrangement of functions,
often without specifying explicit steps
•Program correctness
•Shorter programs(lower lines to effect ratio)

Functional programming languages
Impure
•C++
•C#
•Java
•Lisp
•Python
Pure
•Haskell
•Charity
•Curry
•Miranda
•sequencel

main = putStrLn "Hello, world!"

03/14/16
Sample program of a Functional
using Haskell Language
•ThreadScope is a tool for performance
profiling of parallel Haskell programs.
The ThreadScope program allows us to debug
the parallel performance of Haskell
programs. Using ThreadScope we can check
to see that work is well balanced across the
available processors and spot performance
issues relating to garbage collection or poor
load balancing.