Otimizacao prematura-agile-brazil-12

48
Otimização prematura é a raiz de todos os problemas. Código limpo é otimização? Lucas Cavalcanti @lucascs http://lucas.cavalcanti.me

Transcript of Otimizacao prematura-agile-brazil-12

Page 1: Otimizacao prematura-agile-brazil-12

Otimização prematura é a raiz de todos os problemas. Código limpo é

otimização?

Lucas Cavalcanti@lucascshttp://lucas.cavalcanti.me

Page 2: Otimizacao prematura-agile-brazil-12

Código Limpo

Page 3: Otimizacao prematura-agile-brazil-12

Nomes bonspublic class BATATINHA { public static double[] To_a_fim_de_ir_na_praia(double mIGuXEixxX, double Bolacha, double LEITE) { if (mIGuXEixxX == 0.0) { throw new putzdeupipocomano("po bixo, isso num pode ser zero naum!!!!"); }

// cara, ela ta moh nervosa hoje! Aquela saia justa com o chefe foi tensa. double hoje_a_martinha_ta_nervosa = Bolacha * Bolacha - 4 * LEITE * mIGuXEixxX;

if (hoje_a_martinha_ta_nervosa < 0.0) { throw new putzdeupipocomano("xiiii a bagaça ta negativa"); }

// ontem fui no cinema ver o filme do batman. Kra, o filme é bom pra kct! double variable114 = (-Bolacha + Math.sqrt(hoje_a_martinha_ta_nervosa)) / (2 * mIGuXEixxX); double variable115 = (-Bolacha - Math.sqrt(hoje_a_martinha_ta_nervosa)) / (2 * mIGuXEixxX); double[] AAAAA = new double[2]; AAAAA[0] = variable114; AAAAA[1] = variable115;

// estou com fome agora, acho que vo pedi uma pizza!!!!! return AAAAA; }}

Page 4: Otimizacao prematura-agile-brazil-12

Orientação a Objetos

Page 5: Otimizacao prematura-agile-brazil-12

Métodos pequenos

Page 6: Otimizacao prematura-agile-brazil-12

Classes pequenas

Page 7: Otimizacao prematura-agile-brazil-12

SOLID

Page 8: Otimizacao prematura-agile-brazil-12

DRY

Produtos produtos = new Produtos(); Produto produto = new Produto(); produto.setNomeProduto("Meu produto"); produto.setPrecoProduto(42); produtos.adicionaProduto(produto);

Page 9: Otimizacao prematura-agile-brazil-12

KISS

Page 10: Otimizacao prematura-agile-brazil-12

“Continuous attention to technical excellence and good design enhances

agility.”

“Atenção contínua à excelência técnica e ao bom design

engrandecem a agilidade”

– Agile Manifesto

Page 11: Otimizacao prematura-agile-brazil-12

Testes automatizados

Page 12: Otimizacao prematura-agile-brazil-12

Testes de Unidade

Page 13: Otimizacao prematura-agile-brazil-12

Testes de integração

Page 14: Otimizacao prematura-agile-brazil-12

Testes End-to-end

Page 15: Otimizacao prematura-agile-brazil-12

TDD

TesteImplemente

Refatore

Page 16: Otimizacao prematura-agile-brazil-12

“Working software is the primary measure of progress.”

“Software funcionando é a principal medida de progresso”

– Agile Manifesto

Page 17: Otimizacao prematura-agile-brazil-12

Integração Contínua

Page 18: Otimizacao prematura-agile-brazil-12

Build pipeline

Page 19: Otimizacao prematura-agile-brazil-12

Entrega contínua

Page 20: Otimizacao prematura-agile-brazil-12

Por que fazemos código limpo?

Page 21: Otimizacao prematura-agile-brazil-12

Por que sim!

Page 22: Otimizacao prematura-agile-brazil-12

Por que é legal!

Page 23: Otimizacao prematura-agile-brazil-12

Por que é uma arte!

Page 24: Otimizacao prematura-agile-brazil-12

Para facilitar a manutenção!!!

Page 25: Otimizacao prematura-agile-brazil-12

Para otimizar a maintainability!

Page 26: Otimizacao prematura-agile-brazil-12

“Our highest priority is to satisfy the customer through early and continuous

delivery of valuable software.”

“Nossa maior prioridade é satisfazer o cliente através de entrega contínua e desde cedo

de software de valor.”

– Agile Manifesto

Page 27: Otimizacao prematura-agile-brazil-12

Early = cedo

Page 28: Otimizacao prematura-agile-brazil-12

“Otimização prematura é a raiz de todos os males”

– Donald E. Knuth

Page 29: Otimizacao prematura-agile-brazil-12

“Programmers waste enormous amounts of time

thinking about, or worrying about, the speed of

noncritical parts of their programs, and these attempts

at efficiency actually have a strong negative impact

when debugging and maintenance are considered. We

should forget about small efficiencies, say about 97%

of the time: premature optimization is the root of all

evil. Yet we should not pass up our opportunities in

that critical 3%.”– Donald E. Knuth

Page 30: Otimizacao prematura-agile-brazil-12

“Programmers waste enormous amounts of time

thinking about, or worrying about, the maintainability

of noncritical parts of their programs, and these

attempts at efficiency actually have a strong negative

impact when debugging and maintenance are

considered. We should forget about small efficiencies,

say about 97% of the time: premature optimization is

the root of all evil. Yet we should not pass up our

opportunities in that critical 3%.”

Page 31: Otimizacao prematura-agile-brazil-12

“Programmers waste enormous amounts of time

thinking about, or worrying about, the maintainability

of noncritical parts of their programs, and these

attempts at efficiency actually have a strong negative

impact when early delivery are considered. We should

forget about small efficiencies, say about 80% of the

time: premature optimization is the root of all evil. Yet

we should not pass up our opportunities in that critical

20%.”– Lucas Cavalcanti

Page 32: Otimizacao prematura-agile-brazil-12
Page 33: Otimizacao prematura-agile-brazil-12

http://martinfowler.com/bliki/DesignStaminaHypothesis.html

Page 34: Otimizacao prematura-agile-brazil-12
Page 35: Otimizacao prematura-agile-brazil-12

Primeiro deploy com valor pro cliente

Segundo deploy com valor pro cliente

Terceiro deploy com valor pro cliente

Quarto deploy com valor pro cliente

Page 36: Otimizacao prematura-agile-brazil-12
Page 37: Otimizacao prematura-agile-brazil-12

Primeiro deploy com valor pro cliente

Segundo deploy com valor pro cliente

Terceiro deploy com valor pro cliente

Quarto deploy com valor pro cliente

Quinto deploy com valor pro cliente

Sexto deploy com valor pro cliente

Sétimo deploy com valor pro cliente

Page 38: Otimizacao prematura-agile-brazil-12
Page 39: Otimizacao prematura-agile-brazil-12

“Simplicity – the art of maximizing the amount of work not done – is essential.”

“Simplicidade – a arte de maximizar a quantidade de trabalho não feito – é essencial”

– Agile Manifesto

Page 40: Otimizacao prematura-agile-brazil-12

“Programmers waste enormous amounts of time

thinking about, or worrying about, the maintainability

of noncritical parts of their programs, and these

attempts at efficiency actually have a strong negative

impact when early delivery are considered. We should

forget about small efficiencies, say about 80% of the

time: premature optimization is the root of all evil. Yet

we should not pass up our opportunities in that critical

20%.”

Page 41: Otimizacao prematura-agile-brazil-12

Conheça as boas práticas!

Page 42: Otimizacao prematura-agile-brazil-12

Mas... não tente atingir a perfeição logo de cara

A não ser que já seja a forma natural ;)

Page 43: Otimizacao prematura-agile-brazil-12

A mudança mais simples primeiro

Page 44: Otimizacao prematura-agile-brazil-12

Melhorias contínuas!

Page 45: Otimizacao prematura-agile-brazil-12

O que muda maistende a ficar melhor

Page 46: Otimizacao prematura-agile-brazil-12

O que muda poucofica com o código menos limpo

Page 47: Otimizacao prematura-agile-brazil-12

Otimize constantemente

Mas não otimize tudo

Page 48: Otimizacao prematura-agile-brazil-12

Obrigado!

Lucas Cavalcanti@lucascshttp://lucas.cavalcanti.me