imperative and-functional-programming

23
Imperative and Functional Programming Rameses Francia Mark Anthony Sencio

Upload: rameses-francia

Post on 20-Mar-2017

150 views

Category:

Education


3 download

TRANSCRIPT

Page 1: Imperative and-functional-programming

Imperative and Functional

ProgrammingRameses Francia

Mark Anthony Sencio

Page 2: Imperative and-functional-programming

Imperative and Functional

•Programming paradigm.

Page 3: Imperative and-functional-programming

programming paradigm.

•Fundamental style of computer programming.

•Paradigm differ in concepts and abstractions used to represent the elements of program.

Page 4: Imperative and-functional-programming

Imperative programmingHow 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 .

Page 5: Imperative and-functional-programming

Imperative programmingHow it stated?

Fortrancompiled language

•Named variables•Complex expressions•Subprograms

•many other features now common in imperative languages. 

Page 6: Imperative and-functional-programming

Imperative Programming languages

•Basic•C•Assembly•Java

•Ada•PASCAL•Forton

Page 7: Imperative and-functional-programming

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.

Page 8: Imperative and-functional-programming

IMPERATIVE PROGRAMMING IS THE

MOST POPULAR

Page 9: Imperative and-functional-programming

Imperative programming is the easiest

Page 10: Imperative and-functional-programming

IMPERATIVE PROGRAMMING IS THE

WORST

Page 11: Imperative and-functional-programming

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

Page 12: Imperative and-functional-programming

How it works in PL’s?

Page 13: Imperative and-functional-programming

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)

}

})

Page 14: Imperative and-functional-programming

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)

}

})

Page 15: Imperative and-functional-programming

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)

}

})

Page 16: Imperative and-functional-programming

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)

}

})

Page 17: Imperative and-functional-programming

Sample program of a imperative using java programming

Java Code

SciCal.txt

Page 18: Imperative and-functional-programming

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

Page 19: Imperative and-functional-programming

Functional programmingbrief 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)

Page 20: Imperative and-functional-programming

Functional programmingHOW 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)

Page 21: Imperative and-functional-programming

Functional programming languages

Impure

•C++•C#•Java•Lisp•Python

Pure• Haskell• Charity• Curry • Miranda• sequencel

Page 22: Imperative and-functional-programming

main = putStrLn "Hello, world!"

Page 23: Imperative and-functional-programming

05/02/23

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.