tdc2016sp - trilha programação funcional

Post on 15-Feb-2017

55 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Globalcode–Open4education

Impactos no design utilizando programação funcional

Luiz Costagutomcosta@gmail.com / @gutomcosta

twitter.com/gutomcosta github.com/gutomcosta

www.sagadoprogamador.com.br medium.com/saga-do-programador

orientação a objetos

conjunto de ideias

encapsulamento polimorfismo

objetos herançaestado ...

programação funcional

conjunto de ideias

funções higher-order functions

imutabilidade lazy evaluationrecursão ...

Dois estilos de escrita

código imperativo

Foco no “como fazer”

código declarativo

Foco no “o que fazer”

código declarativo

Foco no “o que fazer”

“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

“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

“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

..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

building blocks

first class functions

uma variável?

invocando uma função

função como parâmetro

invoca a função

mesma função variando comportamento

dados e funções separados

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

argumento ou retorna uma função

Como First Class Functions e Higher

Order Functions podem impactar nas decisões

de design?

OO foco na estruturaComo substituir uma implementação em

runtime?

FP foco na transformaçãotransformação?

listas, map, reduce, filter

map

capitalize capitalize capitalize

Jose Paulo Luiz

jose luizpaulo

TextTextTextText

clojure.string

focus on results, not steps

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

Filter clojure.string

1 2 3 4 5 6 7 8 9

ArgentumAnálise de Candlesticks, bolsa de valores

Candlesticks

ArgentumDomain Model

como representar os conceitos?

Negócio, Candlestick

define uma abstração

dados e funções separados

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

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

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

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

decomposição

invariantes

decomposição

dependência de outro namespace

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

abstração

define comportamentos diferentes

como variar o comportamento?

declara as funções

compondo funções

higher order functions

decomposição de função

calculando a média móvel

com diferentes building blocks, é

preciso repensar as decisões de design

OO e FP Juntos?

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

-Michael Feathers, blog post

Functional Core, imperative shell.“Destroy all software - episode 72”

-Gary Bernhardt, destroy on software screen cast series

conclusão

Functional Programming is more a mindset than a particular set

of tools or languages.“Functional Thinking”

-Neal Ford - IBM Developer Works series

Obrigado

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

top related