Otimizacao prematura-agile-brazil-12

Post on 14-Jul-2015

629 views 0 download

Transcript of 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

Código Limpo

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; }}

Orientação a Objetos

Métodos pequenos

Classes pequenas

SOLID

DRY

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

KISS

“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

Testes automatizados

Testes de Unidade

Testes de integração

Testes End-to-end

TDD

TesteImplemente

Refatore

“Working software is the primary measure of progress.”

“Software funcionando é a principal medida de progresso”

– Agile Manifesto

Integração Contínua

Build pipeline

Entrega contínua

Por que fazemos código limpo?

Por que sim!

Por que é legal!

Por que é uma arte!

Para facilitar a manutenção!!!

Para otimizar a maintainability!

“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

Early = cedo

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

– Donald E. Knuth

“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

“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%.”

“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

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

Primeiro deploy com valor pro cliente

Segundo deploy com valor pro cliente

Terceiro deploy com valor pro cliente

Quarto deploy com valor pro cliente

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

“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

“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%.”

Conheça as boas práticas!

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

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

A mudança mais simples primeiro

Melhorias contínuas!

O que muda maistende a ficar melhor

O que muda poucofica com o código menos limpo

Otimize constantemente

Mas não otimize tudo

Obrigado!

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