Geralmente aplicativos buscam resolver uma única tarefa. Mas conforme o passar do tempo, a aplicação tende a ganhar novas features e otimizações, consequentemente ela tende a crescer. Mais features e mais usuários significam mais código. E quanto mais código você escreve, mais código você precisa manter e reescrever. Nos livros "Effective Java" e "Android programming - pushing limits", Joshua Bloch e Erik Hellman, respectivamente, demonstram boas práticas para o desenvolvimento em Java e na plataforma Android. A idéia é fazer um apanhado das melhores práticas trazidas por estes livros. Detalharei o que deve o que não deve ser feito ao aplicar tais práticas.
5. Globalcode – Open4education
Agenda
• What the difference in performance between for
loops?
• How to deal with several parameters classes?
• How to make static classes safe?
• How to avoid the unecessary objects creation?
• Inside classes
• Inside for loops
• When concatenating strings
13. Globalcode – Open4education
For loops in ArrayLists
X
1061 ms 1183 ms
For each
100000 strings logged in the console performance test
Manual for-loop
19. Globalcode – Open4education
Javabeans Pattern
● Easy to read
● Precludes the possibility of making a class imutable
● Imutability -> "All of the information contained in each instance is
provided when it is created and is fixed for the lifetime of the object"
32. Globalcode – Open4education
Why use static initialisers?
● Calendar, Date and Timezone
instances created only once
● Executing 10 milion times :
○ 1st version took 32000ms
○ 2nd version took 130 ms
250 times faster!