SlideShare une entreprise Scribd logo
1  sur  101
Télécharger pour lire hors ligne
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
Ralph Johnson and Singleton
Are 
Design Patterns 
missing languages features?
Are 
Design Patterns 
how languages evolve? 
(Jeff Atwood)
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
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
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#
We need to rewrite the 
design patterns book
Part 2 
Introducing Monads
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?
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
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

Contenu connexe

Tendances

Javascript engine performance
Javascript engine performanceJavascript engine performance
Javascript engine performance
Duoyi Wu
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
Moriyoshi Koizumi
 
Large Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScriptLarge Scale JavaScript with TypeScript
Large Scale JavaScript with TypeScript
Oliver Zeigermann
 

Tendances (20)

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

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

Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 

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

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

Plus de Luiz Borba

Plus de Luiz Borba (20)

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

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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)
  • 14.
  • 15.
  • 16. Ralph Johnson and Singleton
  • 17. Are Design Patterns missing languages features?
  • 18. Are Design Patterns how languages evolve? (Jeff Atwood)
  • 19.
  • 20.
  • 21.
  • 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
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 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
  • 37.
  • 38.
  • 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#
  • 45.
  • 46. We need to rewrite the design patterns book
  • 48.
  • 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?
  • 52.
  • 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
  • 92.
  • 93.
  • 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