imperative and-functional-programming
TRANSCRIPT
Imperative and Functional
ProgrammingRameses 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 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 .
Imperative programmingHow it stated?
Fortrancompiled 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 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)
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)
Functional programming languages
Impure
•C++•C#•Java•Lisp•Python
Pure• Haskell• Charity• Curry • Miranda• sequencel
main = putStrLn "Hello, world!"
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.