The introduction part of my course on Functional Programming with Java8 which includes theoretical and historical aspect of Functional Programming. Rest will be issued as a course with separate slides soon.
2. “Every problem in computer science can be solved
by adding another level of indirection.”
- David Wheeler
3. Programming Paradigms
• Machine Code
• Procedural Languages
• Object Oriented Languages
• Functional Languages
• Domain Specific Languages
4. What is FP ?
In computer science, functional programming is a
programming paradigm—a style of building the structure and
elements of computer programs—that treats computation as
the evaluation of mathematical functions and avoids
changing-state and mutable data.
6. FP: Why Now ?
• Moore’s Law runs out (in terms of CPU speeds)
• Increasing need for;
• Concurrency & Parallelism
• Distributed Computing
• Scalability
7. Benefits of FP
• Concurrency/Parallelism without tears
• Succinct, concise, understandable programming model
• Different programming perspective
• Reusability, testability
• Becoming more accessible
8. Functional Languages
• Haskell *
• Clean *
• Lisp/Scheme
• ML/OCaml
• F#
• Erlang
• Java
• Scala
• C++ (11+)
• JavaScript
* Pure
9. Sample:
Imperative Approach
class Player { String name; int score; Player(..){..} }
void declareWinner(Player p) {
System.out.println(p.name + “ is the winner! ”);
}
void winner(Player p1, Player p2) { // Impure
if(p1.score > p2.score)
declareWinner(p1);
else
declareWinner(p2);
}
winner(new Player(“Ram”, 10), new Player(“John”, 20));
10. Sample:
Functional Core + Impure Layers
class Player { String name; int score; Player(..){..} }
void declareWinner(Player p) {
System.out.println(p.name + “ is the winner! ”);
}
Player maxScore(Player p1, Player p2) {
return p1.score > p2.score ? p1 : p2;
}
Player winner(Player p1, Player p2) {
declareWinner(maxScore(p1, p2));
}
winner(new Player(“Ram”, 10), new Player(“John”, 20));