impactos no design com programação funcional

Post on 26-May-2015

787 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Orientação a Objetos é sem dúvidas o paradigma de programação mais utilizado, mas ultimamente temos visto um crescimento significativo no uso de linguagens funcionais. O objetivo desta palestra é mostrar uma abordagem de design que mostra problemas comuns que temos em orientação a objetos dentro do mundo funcional. Para isso, vamos utilizar um sistema que simula algumas operações de bolsa de valores para mostrar como as decisões tomadas em design OO podem ser mapeadas no mundo funcional através da linguagem Clojure.

TRANSCRIPT

impactos no design com programação

funcionalLuiz Costa

@gutomcostawww.sagadoprogramador.com.br

Sunday, October 20, 13

Sunday, October 20, 13

Programação Funcional?

Sunday, October 20, 13

Programação Funcional?

Sunday, October 20, 13

Programação Funcional?

Sunday, October 20, 13

Programação Funcional?

Sunday, October 20, 13

Programação Funcional?

Sunday, October 20, 13

Programação Funcional?

e alguns novatosSunday, October 20, 13

orientação a objetos

Sunday, October 20, 13

Sunday, October 20, 13

conjunto de ideias

Sunday, October 20, 13

conjunto de ideias

encapsulamento polimorfismo

objetos herançaestado ...

Sunday, October 20, 13

programação funcional

Sunday, October 20, 13

Sunday, October 20, 13

conjunto de ideias

Sunday, October 20, 13

conjunto de ideias

funções higher-order functions

imutabilidade lazy evaluationrecursão ...

Sunday, October 20, 13

código imperativo

Sunday, October 20, 13

código imperativo

Sunday, October 20, 13

código imperativo

Sunday, October 20, 13

código imperativo

Sunday, October 20, 13

código imperativo

Foco no “como fazer”

Sunday, October 20, 13

código declarativo

Sunday, October 20, 13

código declarativo

Foco no “o que fazer”

Sunday, October 20, 13

código declarativo

Sunday, October 20, 13

código declarativo

Foco no “o que fazer”

Sunday, October 20, 13

“When writing a modular program to solve a problem, one first divides the problem into subproblems, then solves the subproblems, and finally combines the solutions. The ways in which one can divide up the original problem depend directly on the ways in which one can glue solutions together.”

“Why functional programming matters”-John Hughes in Research topics in functional programming, 1990

Sunday, October 20, 13

“When writing a modular program to solve a problem, one first divides the problem into subproblems, then solves the subproblems, and finally combines the solutions. The ways in which one can divide up the original problem depend directly on the ways in which one can glue solutions together.”

“Why functional programming matters”-John Hughes in Research topics in functional programming, 1990

Sunday, October 20, 13

“When writing a modular program to solve a problem, one first divides the problem into subproblems, then solves the subproblems, and finally combines the solutions. The ways in which one can divide up the original problem depend directly on the ways in which one can glue solutions together.”

“Why functional programming matters”-John Hughes in Research topics in functional programming, 1990

Sunday, October 20, 13

..argue in the remainder of this paper that functional languages provide two new, very important kinds of glue.

“Why functional programming matters”-John Hughes in Research topics in functional programming, 1990

higher order function lazy evaluation

Sunday, October 20, 13

building blocks

Sunday, October 20, 13

Sunday, October 20, 13

uma variável?

Sunday, October 20, 13

first class functions

uma variável?

Sunday, October 20, 13

Sunday, October 20, 13

invocando uma função

função como parâmetro

Sunday, October 20, 13

invoca a funçãoSunday, October 20, 13

Sunday, October 20, 13

dados e funções separados

Sunday, October 20, 13

mesma função variando comportamento

dados e funções separados

Sunday, October 20, 13

higher order functionuma funcão que recebe outra função como

argumento ou retorna uma função

Sunday, October 20, 13

functional style

Sunday, October 20, 13

OO foco na estruturaComo substituir uma implementação em

runtime?

Sunday, October 20, 13

FP foco na transformaçãotransformação?

Sunday, October 20, 13

listas, map, reduce, filter

Sunday, October 20, 13

map

TextTextTextText

Sunday, October 20, 13

map

TextTextTextText

clojure.string

Sunday, October 20, 13

map

jose luizpaulo

TextTextTextText

clojure.string

Sunday, October 20, 13

map

capitalize

Jose

jose luizpaulo

TextTextTextText

clojure.string

Sunday, October 20, 13

map

capitalize capitalize

Jose Paulo

jose luizpaulo

TextTextTextText

clojure.string

Sunday, October 20, 13

map

capitalize capitalize capitalize

Jose Paulo Luiz

jose luizpaulo

TextTextTextText

clojure.string

Sunday, October 20, 13

focus on results, not steps

“Functional Thinking”-Neal Ford - IBM Developer Works series

Sunday, October 20, 13

Filter clojure.string

Sunday, October 20, 13

Filter clojure.string

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Filter clojure.string

1 2 3 4 5 6 7 8 9

Sunday, October 20, 13

Reduce

10 20 30 400

Sunday, October 20, 13

Reduce

10 20 30 400

função

Sunday, October 20, 13

Reduce

100

função

Sunday, October 20, 13

ArgentumAnálise de Candlesticks, bolsa de valores

Sunday, October 20, 13

Candlesticks

Sunday, October 20, 13

ArgentumDomain Model

Sunday, October 20, 13

antes, um pouco de clojure

muito pouco mesmo ...

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

Clojure

Sunday, October 20, 13

como representar os conceitos?

Negócio, Candlestick

Sunday, October 20, 13

Sunday, October 20, 13

Sunday, October 20, 13

Sunday, October 20, 13

define uma abstração

Sunday, October 20, 13

Sunday, October 20, 13

dados e funções separadosSunday, October 20, 13

dados e funções separadosSunday, October 20, 13

decompose an algorithm into functions that are simple, meaningful and useful.

“Tutorial on Good Lisp Programming Style”-Peter Norvig in 1992

Sunday, October 20, 13

decompose an algorithm into functions that are simple, meaningful and useful.

“Tutorial on Good Lisp Programming Style”-Peter Norvig in 1992

Sunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposição

invariantes

Sunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposiçãoSunday, October 20, 13

decomposição

dependência de outro namespace

Sunday, October 20, 13

ArgentumGeração de gráfico com indicadores

Sunday, October 20, 13

ArgentumGeração de gráfico com indicadores define uma

abstração

Sunday, October 20, 13

ArgentumGeração de gráfico com indicadores define uma

abstração

define comportamentos diferentesSunday, October 20, 13

como variar o comportamento?

Sunday, October 20, 13

declara as funçõesSunday, October 20, 13

compondo funçõesSunday, October 20, 13

compondo funções

decomposição de função

Sunday, October 20, 13

compondo funções

higher order functions

Sunday, October 20, 13

calculando a média móvelSunday, October 20, 13

calculando a média móvelSunday, October 20, 13

calculando a média móvelSunday, October 20, 13

calculando a média móvelSunday, October 20, 13

com diferentes building blocks, é

preciso repensar as decisões de design

Sunday, October 20, 13

OO e FP Juntos?

Sunday, October 20, 13

Functional in the small, OO in the large.“Tell Above, and Ask Below - Hybridizing OO and Functional design”

-Michael Feathers, blog post

Sunday, October 20, 13

Functional Core, imperative shell.“Destroy all software - episode 72”-Gary Bernhardt, destroy on software screen cast series

Sunday, October 20, 13

conclusão

Sunday, October 20, 13

Functional Programming is more a mindset than a particular set

of tools or languages.“Functional Thinking”

-Neal Ford - IBM Developer Works series

Sunday, October 20, 13

Obrigado

Sunday, October 20, 13

ReferênciasSICP - http://mitpress.mit.edu/sicp/full-text/book/book.html

Why functional programming matters - http://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf

Clojure - http://clojure.org/

Functional Thinking - http://www.ibm.com/developerworks/java/library/j-ft1/index.html

Tell Above, and ask Below - http://michaelfeathers.typepad.com/michael_feathers_blog/2012/03/tell-above-and-ask-below-hybridizing-oo-and-functional-design.html

Functional Core, imperative shell - https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell

Tutorial on good lisp programming style - http://www.cs.umd.edu/~nau/cmsc421/norvig-lisp-style.pdf

Sunday, October 20, 13

top related