SlideShare a Scribd company logo
It’s the end of 
Design Patterns 
as we know it 
(and I feel fine) 
Today: 
Introducing Monads 
Luiz Borba 
http://borba.blog.br
Part 1 
Deconstructing 
Design Patterns
1994
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
PHP (95)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
PHP (95)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
DESKTOP 
PHP (95)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
WEB 
PHP (95)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
PHP (95)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88) 
PHP (95)
" 
I always knew that one day 
Smalltalk 
would replace Java. 
I just didn’t know 
it would be called 
Ruby 
" 
(Kent Beck)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88)
It’s the 
Mainstream, 
stupid!
Always 
Controversial
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
Ralph Johnson and Singleton
Are 
Design Patterns 
missing languages features?
Are 
Design Patterns 
how languages evolve? 
(Jeff Atwood)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
COBOL (61) 
FORTRAN (57) 
CLIPPER (85) 
C (72) 
SMALLTALK (72) 
C++ (83) 
PASCAL (86) 
LISP (58) 
PERL (87) 
MS BASIC (75) 
OBJECT PASCAL (95) 
ML (73) 
HASKELL (90) 
JAVA (95) RUBY (95) 
PYTHON (91) 
ALGOL (58) 
POWERBUILDER (92) 
BASIC (64) 
VISUAL BASIC (91) 
SQLWINDOWS (88)
2010
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
imperative languages 
Java 
C 
Fortran 
C++ 
add 
abstractions
subtract 
abstractions 
Lisp 
ML 
Haskell 
functional languages 
imperative languages 
Java 
C 
Fortran 
C++ 
add 
abstractions
subtract 
abstractions 
Lisp 
ML 
Haskell 
functional languages 
imperative languages 
Java 
C 
Fortran 
C++ 
add 
abstractions 
Scala 
Java 8 
C# 
F# 
hybrid languages
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
Haskell: 
[x | x <- xs, x < 10]
Haskell: 
[x | x <- xs, x < 10] 
C#: 
from x in xs where x < 10 select x;
Haskell: 
[x | x <- xs, x < 10] 
C#: 
from x in xs where x < 10 select x; 
Java 8: 
xs.stream().filter(x -> x < 10)
2014
Erlang 
Javascript 
Java 8 
Swift 
Objective-C 
C# 
C 
PHP 
Python 
Ruby 
Dart 
Elixir 
Coffeescript 
Scala 
Go 
Clojure 
Rust 
Groovy 
C++ 
Haskell 
F#
Erlang 
Javascript 
Java 8 
Swift 
Objective-C 
C# 
C 
PHP 
Python 
Ruby 
Dart 
Elixir 
Coffeescript 
Scala 
Go 
Clojure 
Rust 
Groovy 
C++ 
Haskell 
F#
It's the end of design patterns as we know it (and i feel fine)
We need to rewrite the 
design patterns book
Part 2 
Introducing Monads
It's the end of design patterns as we know it (and i feel fine)
Once you understand 
Monadsfor yourself 
you lose the ability 
to explain them to others 
(Douglas Crockford) 
" 
"
A Monad is just 
a monoid in the 
category of 
endofunctors
WTF?
It's the end of design patterns as we know it (and i feel fine)
WARM UP
What’s a 
Stack?
Value
Operations
Rules 
+ = 
stack.push(value).top == value 
stack.isEmpty == true 
stack.push(value).isEmpty == false
and.. 
We can implement them 
however we like 
We can use them without 
knowing their implementation
What’s a 
Queue?
What are 
Stack & 
Queue?
ABSTRACT 
TYPES 
DATA
Javascript 
Promises
Asynchronous 
programming is 
becoming the norm in 
modern, 
connected applications" 
(Anders Hejlsberg) 
"
var FS = require('fs'), 
request = require('request'); 
function getResults(pathToFile, callback) { 
FS.readFile(pathToFile, 'utf8', function(err, data) { 
if (err) return callback(err); 
var response1, response2; 
request.post('http://service1.example.com?data=' + data), function(err, response, body) { 
if(err) return callback(err); 
response1 = response; 
next(); 
}); 
request.post('http://service2.example.com?data=' + data), function(err, response, body) { 
if(err) return callback(err); 
response2 = response; 
next(); 
}); 
function next(){ 
if(response1 && response2){ 
callback(null, [response1, response2]); 
} 
} 
}); 
}
asyncCall(function(err, data1){ 
if(err) return callback(err); 
anotherAsyncCall(function(err2, data2){ 
if(err2) return calllback(err2); 
oneMoreAsyncCall(function(err3, data3){ 
if(err3) return callback(err3); 
// are we done yet? 
}); 
}); 
});
asyncCall() 
.then(function(data1){ 
// do something... 
return anotherAsyncCall(); 
}) 
.then(function(data2){ 
// do something... 
return oneMoreAsyncCall(); 
}) 
.then(function(data3){ 
// the third and final async response 
}) 
.fail(function(err) { 
// handle any error resulting from any of the above calls 
}) 
.done();
var promise = new Promise(initialFunction) 
var anotherPromise = promise.then(functionB) 
var yetAnotherPromise = anotherPromise.then(functionC) 
...
var promise = new Promise(initialFunction) 
var anotherPromise = promise.then(functionB) 
var yetAnotherPromise = anotherPromise.then(functionC) 
...
var promise = new Promise(initialFunction) 
var anotherPromise = promise.then(functionB) 
var yetAnotherPromise = anotherPromise.then(functionC) 
...
Java 8 
Optional
String version = computer 
.getSoundcard() 
.getUSB() 
.getVersion();
String version = "UNKNOWN"; 
if(computer != null){ 
Soundcard soundcard = computer.getSoundcard(); 
if(soundcard != null){ 
USB usb = soundcard.getUSB(); 
if(usb != null){ 
version = usb.getVersion(); 
} 
} 
}
String name = Optional.of(computer) 
.map(Computer::getSoundcard) 
.map(Soundcard::getUSB) 
.map(USB::getVersion) 
.orElse("UNKNOWN");
String name = Optional.of(computer) 
.map(Computer::getSoundcard) 
.map(Soundcard::getUSB) 
.map(USB::getVersion) 
.orElse("UNKNOWN");
String name = Optional.of(computer) 
.map(Computer::getSoundcard) 
.map(Soundcard::getUSB) 
.map(USB::getVersion) 
.orElse("UNKNOWN");
Promises and Optional 
are Monads
A Monad is a structure 
that puts a value in a 
computational context
Monad<A> unit(A a)
Monad<A> unit(A a)
Monad<A> unit(A a)
Monad<B> bind(M<A> ma, 
Function<A, M<B>> f)
Monad<B> bind(M<A> ma, 
Function<A, M<B>> f)
Monad<B> bind(M<A> ma, 
Function<A, M<B>> f)
Monad: 
Value, Operations and Rules 
unit(x) = Monad x 
unit(x).bind(f) = Monad f(x) 
unit(x).bind(f).bind(g) = Monad g(f(x))
Haskell 
I/O
Unit & Bind in Haskell 
return :: Monad m => a -> m a 
(>>=) :: Monad m => m a -> (a -> m b) -> m b 
(>>) :: Monad m => m a -> m b -> m b
I/O Example 
main :: IO () 
main = 
putStrLn "What is your name?" >> 
getLine >>= 
name -> putStrLn ("Hello, " ++ name)
Sequence 
main :: IO () 
main = do 
putStrLn "What is your name?" 
name <- getLine 
putStrLn ("Hello, " ++ name)
What is that? 
main :: IO () 
main = do 
putStrLn "What is your name?" 
name <- getLine 
putStrLn ("Hello, " ++ name)
Imperative code 
in functional style
PARADIGM MIX, 
stupid! 
It’s the
It's the end of design patterns as we know it (and i feel fine)
It's the end of design patterns as we know it (and i feel fine)
One more thing…
Accidental Monad 
BuilderResult<Group> groupBuilder = new Builder<Group>(Group.class) 
.daoContext(daoContext) 
.user(loginUser) 
.comments(body.getCreateComments()) 
.set(Field.name).with(name).validations(required(), unique()) 
.set(Field.owners).with(ownerIds).converting(convertToOwner()) 
.validations(required()) 
.set(Field.description).with(body.getDesc()).withoutValidation() 
.build();
"Six of one or half 
dozen of the other"
Set<PersistenceEventListener> result = new HashSet<>(); 
for (String channel: channels) { 
List<PersistenceEventListener> channelListeners = 
listenersPerChannel.get(channel); 
if (channelListeners != null) { 
result.addAll(channelListeners); 
} 
} 
return result; 
X 
return listenersPerChannel.entrySet().stream() 
.filter(e -> Arrays.asList(channels).contains(e.getKey())) 
.map(e -> e.getValue()) 
.flatMap(l -> l.stream()) 
.collect(Collectors.toSet());
Moral of the Story
Languages are evolving
Programmers must evolve 
along with the languages and 
enjoy learning new things
It’s the end of Design Patterns 
as we know it (and I feel fine) 
Thank you! 
Luiz Borba 
http://borba.blog.br

More Related Content

PDF
Dias do futuro presente da programação
KEY
Incremental Development with Lisp: Building a Game and a Website
PDF
EROSについて
PDF
JavaOne 2013 - Clojure for Java Developers
PDF
Ruby is an Acceptable Lisp
ODP
Turtle Graphics in Groovy
PDF
Clojure for Java developers - Stockholm
PDF
D vs OWKN Language at LLnagoya
Dias do futuro presente da programação
Incremental Development with Lisp: Building a Game and a Website
EROSについて
JavaOne 2013 - Clojure for Java Developers
Ruby is an Acceptable Lisp
Turtle Graphics in Groovy
Clojure for Java developers - Stockholm
D vs OWKN Language at LLnagoya

What's hot (20)

PDF
JavaScript Survival Guide
PDF
JavaScript Patterns
PDF
P6 OO vs Moose (&Moo)
PDF
R/C++ talk at earl 2014
PDF
ClojureScript: The Good Parts
ODP
Introduction to Functional Programming with Clojure
PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
PDF
Javascript engine performance
ODP
Clojure made simple - Lightning talk
PPTX
Дмитрий Нестерук, Паттерны проектирования в XXI веке
PDF
Csp scala wixmeetup2016
PPTX
Introduction to modern c++ principles(part 1)
PPTX
Hacking Go Compiler Internals / GoCon 2014 Autumn
PDF
Large Scale JavaScript with TypeScript
PDF
How to write Ruby extensions with Crystal
PDF
scala-gopher: async implementation of CSP for scala
PDF
Using R in remote computer clusters
PDF
Clojurian Conquest
PDF
Антон Нонко, Классические строки в C++
PDF
Clojure intro
JavaScript Survival Guide
JavaScript Patterns
P6 OO vs Moose (&Moo)
R/C++ talk at earl 2014
ClojureScript: The Good Parts
Introduction to Functional Programming with Clojure
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Javascript engine performance
Clojure made simple - Lightning talk
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Csp scala wixmeetup2016
Introduction to modern c++ principles(part 1)
Hacking Go Compiler Internals / GoCon 2014 Autumn
Large Scale JavaScript with TypeScript
How to write Ruby extensions with Crystal
scala-gopher: async implementation of CSP for scala
Using R in remote computer clusters
Clojurian Conquest
Антон Нонко, Классические строки в C++
Clojure intro
Ad

Similar to It's the end of design patterns as we know it (and i feel fine) (20)

PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
PDF
Introduction to Scalding and Monoids
PDF
Monadologie
PDF
Scala @ TechMeetup Edinburgh
PDF
Introduction to Scala
KEY
Scala clojure techday_2011
PDF
Refactoring to Macros with Clojure
PDF
Hw09 Hadoop + Clojure
PDF
Hadoop + Clojure
PDF
A Sceptical Guide to Functional Programming
PDF
Beauty and the beast - Haskell on JVM
PDF
TypeScript Introduction
PDF
Being functional in PHP (DPC 2016)
PDF
Swift - One step forward from Obj-C
PDF
Kotlin: forse è la volta buona (Trento)
PDF
Emerging Languages: A Tour of the Horizon
PPTX
Writing Hadoop Jobs in Scala using Scalding
PPTX
Clojure And Swing
PPTX
Kotlin Coroutines and Rx
Столпы функционального программирования для адептов ООП, Николай Мозговой
Introduction to Scalding and Monoids
Monadologie
Scala @ TechMeetup Edinburgh
Introduction to Scala
Scala clojure techday_2011
Refactoring to Macros with Clojure
Hw09 Hadoop + Clojure
Hadoop + Clojure
A Sceptical Guide to Functional Programming
Beauty and the beast - Haskell on JVM
TypeScript Introduction
Being functional in PHP (DPC 2016)
Swift - One step forward from Obj-C
Kotlin: forse è la volta buona (Trento)
Emerging Languages: A Tour of the Horizon
Writing Hadoop Jobs in Scala using Scalding
Clojure And Swing
Kotlin Coroutines and Rx
Ad

More from Luiz Borba (20)

PDF
Novas ferramentas para analise de dados
PDF
Os paradoxos de Blub, Python, a décima lei de Greenspun e porque você deveria...
PDF
Desconstruindo EJB
PDF
Arquitetura pragmática
PDF
O triunfo dos nerds
PDF
O ciclo da vida
PDF
As coisas mudam
PDF
Merda Acontece
PDF
Build 2013: O que vi por lá
PDF
11 historias e 1 segredo
PDF
Coisas que levei um tempo para aprender
PDF
O futuro
PDF
Windows 8 a nova corrida do ouro
PDF
Assuntos aleatorios que podem mudar sua vida
PDF
Startup tools
PDF
What i dont know about startups
PDF
Todas as coisas que todo programador não pode deixar de saber
PPT
Por que voce precisa (re)aprender linguagens funcionais
PDF
TDD Direto das Trincheiras versao 2
PPT
TDD direto das trincheiras
Novas ferramentas para analise de dados
Os paradoxos de Blub, Python, a décima lei de Greenspun e porque você deveria...
Desconstruindo EJB
Arquitetura pragmática
O triunfo dos nerds
O ciclo da vida
As coisas mudam
Merda Acontece
Build 2013: O que vi por lá
11 historias e 1 segredo
Coisas que levei um tempo para aprender
O futuro
Windows 8 a nova corrida do ouro
Assuntos aleatorios que podem mudar sua vida
Startup tools
What i dont know about startups
Todas as coisas que todo programador não pode deixar de saber
Por que voce precisa (re)aprender linguagens funcionais
TDD Direto das Trincheiras versao 2
TDD direto das trincheiras

Recently uploaded (20)

PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Getting Started with Data Integration: FME Form 101
PDF
project resource management chapter-09.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Hybrid model detection and classification of lung cancer
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
Heart disease approach using modified random forest and particle swarm optimi...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 5: Probability Theory and Statistics
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Web App vs Mobile App What Should You Build First.pdf
A novel scalable deep ensemble learning framework for big data classification...
Getting Started with Data Integration: FME Form 101
project resource management chapter-09.pdf
1. Introduction to Computer Programming.pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
A comparative analysis of optical character recognition models for extracting...
Hybrid model detection and classification of lung cancer
Unlocking AI with Model Context Protocol (MCP)
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
cloud_computing_Infrastucture_as_cloud_p
SOPHOS-XG Firewall Administrator PPT.pptx
A comparative study of natural language inference in Swahili using monolingua...

It's the end of design patterns as we know it (and i feel fine)

  • 1. It’s the end of Design Patterns as we know it (and I feel fine) Today: Introducing Monads Luiz Borba http://borba.blog.br
  • 2. Part 1 Deconstructing Design Patterns
  • 4. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) PHP (95)
  • 5. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) PHP (95)
  • 6. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) DESKTOP PHP (95)
  • 7. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) WEB PHP (95)
  • 8. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) PHP (95)
  • 9. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88) PHP (95)
  • 10. " I always knew that one day Smalltalk would replace Java. I just didn’t know it would be called Ruby " (Kent Beck)
  • 11. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88)
  • 16. Ralph Johnson and Singleton
  • 17. Are Design Patterns missing languages features?
  • 18. Are Design Patterns how languages evolve? (Jeff Atwood)
  • 22. COBOL (61) FORTRAN (57) CLIPPER (85) C (72) SMALLTALK (72) C++ (83) PASCAL (86) LISP (58) PERL (87) MS BASIC (75) OBJECT PASCAL (95) ML (73) HASKELL (90) JAVA (95) RUBY (95) PYTHON (91) ALGOL (58) POWERBUILDER (92) BASIC (64) VISUAL BASIC (91) SQLWINDOWS (88)
  • 23. 2010
  • 34. imperative languages Java C Fortran C++ add abstractions
  • 35. subtract abstractions Lisp ML Haskell functional languages imperative languages Java C Fortran C++ add abstractions
  • 36. subtract abstractions Lisp ML Haskell functional languages imperative languages Java C Fortran C++ add abstractions Scala Java 8 C# F# hybrid languages
  • 39. Haskell: [x | x <- xs, x < 10]
  • 40. Haskell: [x | x <- xs, x < 10] C#: from x in xs where x < 10 select x;
  • 41. Haskell: [x | x <- xs, x < 10] C#: from x in xs where x < 10 select x; Java 8: xs.stream().filter(x -> x < 10)
  • 42. 2014
  • 43. Erlang Javascript Java 8 Swift Objective-C C# C PHP Python Ruby Dart Elixir Coffeescript Scala Go Clojure Rust Groovy C++ Haskell F#
  • 44. Erlang Javascript Java 8 Swift Objective-C C# C PHP Python Ruby Dart Elixir Coffeescript Scala Go Clojure Rust Groovy C++ Haskell F#
  • 46. We need to rewrite the design patterns book
  • 49. Once you understand Monadsfor yourself you lose the ability to explain them to others (Douglas Crockford) " "
  • 50. A Monad is just a monoid in the category of endofunctors
  • 51. WTF?
  • 55. Value
  • 57. Rules + = stack.push(value).top == value stack.isEmpty == true stack.push(value).isEmpty == false
  • 58. and.. We can implement them however we like We can use them without knowing their implementation
  • 60. What are Stack & Queue?
  • 63. Asynchronous programming is becoming the norm in modern, connected applications" (Anders Hejlsberg) "
  • 64. var FS = require('fs'), request = require('request'); function getResults(pathToFile, callback) { FS.readFile(pathToFile, 'utf8', function(err, data) { if (err) return callback(err); var response1, response2; request.post('http://service1.example.com?data=' + data), function(err, response, body) { if(err) return callback(err); response1 = response; next(); }); request.post('http://service2.example.com?data=' + data), function(err, response, body) { if(err) return callback(err); response2 = response; next(); }); function next(){ if(response1 && response2){ callback(null, [response1, response2]); } } }); }
  • 65. asyncCall(function(err, data1){ if(err) return callback(err); anotherAsyncCall(function(err2, data2){ if(err2) return calllback(err2); oneMoreAsyncCall(function(err3, data3){ if(err3) return callback(err3); // are we done yet? }); }); });
  • 66. asyncCall() .then(function(data1){ // do something... return anotherAsyncCall(); }) .then(function(data2){ // do something... return oneMoreAsyncCall(); }) .then(function(data3){ // the third and final async response }) .fail(function(err) { // handle any error resulting from any of the above calls }) .done();
  • 67. var promise = new Promise(initialFunction) var anotherPromise = promise.then(functionB) var yetAnotherPromise = anotherPromise.then(functionC) ...
  • 68. var promise = new Promise(initialFunction) var anotherPromise = promise.then(functionB) var yetAnotherPromise = anotherPromise.then(functionC) ...
  • 69. var promise = new Promise(initialFunction) var anotherPromise = promise.then(functionB) var yetAnotherPromise = anotherPromise.then(functionC) ...
  • 71. String version = computer .getSoundcard() .getUSB() .getVersion();
  • 72. String version = "UNKNOWN"; if(computer != null){ Soundcard soundcard = computer.getSoundcard(); if(soundcard != null){ USB usb = soundcard.getUSB(); if(usb != null){ version = usb.getVersion(); } } }
  • 73. String name = Optional.of(computer) .map(Computer::getSoundcard) .map(Soundcard::getUSB) .map(USB::getVersion) .orElse("UNKNOWN");
  • 74. String name = Optional.of(computer) .map(Computer::getSoundcard) .map(Soundcard::getUSB) .map(USB::getVersion) .orElse("UNKNOWN");
  • 75. String name = Optional.of(computer) .map(Computer::getSoundcard) .map(Soundcard::getUSB) .map(USB::getVersion) .orElse("UNKNOWN");
  • 76. Promises and Optional are Monads
  • 77. A Monad is a structure that puts a value in a computational context
  • 81. Monad<B> bind(M<A> ma, Function<A, M<B>> f)
  • 82. Monad<B> bind(M<A> ma, Function<A, M<B>> f)
  • 83. Monad<B> bind(M<A> ma, Function<A, M<B>> f)
  • 84. Monad: Value, Operations and Rules unit(x) = Monad x unit(x).bind(f) = Monad f(x) unit(x).bind(f).bind(g) = Monad g(f(x))
  • 86. Unit & Bind in Haskell return :: Monad m => a -> m a (>>=) :: Monad m => m a -> (a -> m b) -> m b (>>) :: Monad m => m a -> m b -> m b
  • 87. I/O Example main :: IO () main = putStrLn "What is your name?" >> getLine >>= name -> putStrLn ("Hello, " ++ name)
  • 88. Sequence main :: IO () main = do putStrLn "What is your name?" name <- getLine putStrLn ("Hello, " ++ name)
  • 89. What is that? main :: IO () main = do putStrLn "What is your name?" name <- getLine putStrLn ("Hello, " ++ name)
  • 90. Imperative code in functional style
  • 91. PARADIGM MIX, stupid! It’s the
  • 95. Accidental Monad BuilderResult<Group> groupBuilder = new Builder<Group>(Group.class) .daoContext(daoContext) .user(loginUser) .comments(body.getCreateComments()) .set(Field.name).with(name).validations(required(), unique()) .set(Field.owners).with(ownerIds).converting(convertToOwner()) .validations(required()) .set(Field.description).with(body.getDesc()).withoutValidation() .build();
  • 96. "Six of one or half dozen of the other"
  • 97. Set<PersistenceEventListener> result = new HashSet<>(); for (String channel: channels) { List<PersistenceEventListener> channelListeners = listenersPerChannel.get(channel); if (channelListeners != null) { result.addAll(channelListeners); } } return result; X return listenersPerChannel.entrySet().stream() .filter(e -> Arrays.asList(channels).contains(e.getKey())) .map(e -> e.getValue()) .flatMap(l -> l.stream()) .collect(Collectors.toSet());
  • 98. Moral of the Story
  • 100. Programmers must evolve along with the languages and enjoy learning new things
  • 101. It’s the end of Design Patterns as we know it (and I feel fine) Thank you! Luiz Borba http://borba.blog.br