Voce Tem Orgulho Do Seu Codigo

89
Samuel Crescêncio e Victor Hugo Germano Você tem orgulho do seu código? http://www.flickr.com/photos/caravinagre/1364614919/

description

O quanto você está satisfeito com o código que produz? Mais ainda: o quanto você está satisfeito como profissional? Na busca pela melhoria de nossas aplicações, caímos num grande desafio: melhorar a nós mesmos!Numa conversa franca e descontraída, Samuel e Victor tentarão apresentar idéias sobre como você pode melhorar seu próprio trabalho e sentir orgulho do que faz.

Transcript of Voce Tem Orgulho Do Seu Codigo

Page 1: Voce Tem Orgulho Do Seu Codigo

Samuel Crescêncio e Victor Hugo Germano

Você tem orgulho do seu código?

http://www.flickr.com/photos/caravinagre/1364614919/

Page 2: Voce Tem Orgulho Do Seu Codigo
Page 3: Voce Tem Orgulho Do Seu Codigo

Samuel Crescêncio

Page 4: Voce Tem Orgulho Do Seu Codigo

Victor Hugo Germano

/ victorhg

Page 5: Voce Tem Orgulho Do Seu Codigo
Page 6: Voce Tem Orgulho Do Seu Codigo
Page 7: Voce Tem Orgulho Do Seu Codigo

/* I realize that this program is a messy compilation of inefficient coding, and perhaps even stands as something blasphemous in your eyes. Coming midterms forced me to write the program as is because this format required the least amount of thinking as well as the least amount of time. Therefore, I only ask one thing of you: Be gentle. */

http://www.thedailywtf.com

Page 8: Voce Tem Orgulho Do Seu Codigo

Public static int getTestcell() { int i, neighbor, male, female, empty, value, num; male = 0; female = 0; empty = 0; value = 0; num = 0; if (spotvalue[n] == 0) { neighbor = n; if (n == 0) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor + 20] == 0) empty = empty + 1; else {

if (spotvalue[neighbor + 20] == 1) male = male + 1; if (spotvalue[neighbor + 20] == 2) female = female + 1; } if (spotvalue[neighbor + 21] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 21] == 1) male = male + 1; if (spotvalue[neighbor + 21] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 19) { if (spotvalue[neighbor - 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 1] == 1) male = male + 1; if (spotvalue[neighbor - 1] == 2) female = female + 1; } if (spotvalue[neighbor + 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 20] == 1) male = male + 1; if (spotvalue[neighbor + 20] == 2) female = female + 1; } if (spotvalue[neighbor + 19] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 19] == 1) male = male + 1; if (spotvalue[neighbor + 19] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 380) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor - 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 20] == 1) male = male + 1; if (spotvalue[neighbor - 20] == 2) female = female + 1; } if (spotvalue[neighbor - 19] == 0) empty = empty + 1;

Page 9: Voce Tem Orgulho Do Seu Codigo

if (spotvalue[neighbor + 20] == 1) male = male + 1; if (spotvalue[neighbor + 20] == 2) female = female + 1; } if (spotvalue[neighbor + 21] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 21] == 1) male = male + 1; if (spotvalue[neighbor + 21] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 19) { if (spotvalue[neighbor - 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 1] == 1) male = male + 1; if (spotvalue[neighbor - 1] == 2) female = female + 1; } if (spotvalue[neighbor + 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 20] == 1) male = male + 1; if (spotvalue[neighbor + 20] == 2) female = female + 1; } if (spotvalue[neighbor + 19] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 19] == 1) male = male + 1; if (spotvalue[neighbor + 19] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 380) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor - 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 20] == 1) male = male + 1; if (spotvalue[neighbor - 20] == 2) female = female + 1; } if (spotvalue[neighbor - 19] == 0) empty = empty + 1;

Page 10: Voce Tem Orgulho Do Seu Codigo

} } else { value = 0; return value; } } if (n == 19) { if (spotvalue[neighbor - 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 1] == 1) male = male + 1; if (spotvalue[neighbor - 1] == 2) female = female + 1; } if (spotvalue[neighbor + 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 20] == 1) male = male + 1; if (spotvalue[neighbor + 20] == 2) female = female + 1; } if (spotvalue[neighbor + 19] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 19] == 1) male = male + 1; if (spotvalue[neighbor + 19] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 380) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor - 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 20] == 1) male = male + 1; if (spotvalue[neighbor - 20] == 2) female = female + 1; } if (spotvalue[neighbor - 19] == 0) empty = empty + 1;

Page 11: Voce Tem Orgulho Do Seu Codigo

female = female + 1; } if (spotvalue[neighbor + 19] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 19] == 1) male = male + 1; if (spotvalue[neighbor + 19] == 2) female = female + 1; } if (male >= 1 && male <=2) { if (male == female) { num = rand.nextInt(2); value = num + 1; return value; } else { value = 0; return value; } } else { value = 0; return value; } } if (n == 380) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor - 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 20] == 1) male = male + 1; if (spotvalue[neighbor - 20] == 2) female = female + 1; } if (spotvalue[neighbor - 19] == 0) empty = empty + 1;

Page 12: Voce Tem Orgulho Do Seu Codigo

{ value = 0; return value; } } if (n == 380) { if (spotvalue[neighbor + 1] == 0) empty = empty + 1; else { if (spotvalue[neighbor + 1] == 1) male = male + 1; if (spotvalue[neighbor + 1] == 2) female = female + 1; } if (spotvalue[neighbor - 20] == 0) empty = empty + 1; else { if (spotvalue[neighbor - 20] == 1) male = male + 1; if (spotvalue[neighbor - 20] == 2) female = female + 1; } if (spotvalue[neighbor - 19] == 0) empty = empty + 1;

Page 13: Voce Tem Orgulho Do Seu Codigo

!!!!!!!!!!!!!

Page 14: Voce Tem Orgulho Do Seu Codigo

Qual o nosso papel?

Page 15: Voce Tem Orgulho Do Seu Codigo
Page 16: Voce Tem Orgulho Do Seu Codigo
Page 17: Voce Tem Orgulho Do Seu Codigo

Qualidade?

Page 18: Voce Tem Orgulho Do Seu Codigo
Page 19: Voce Tem Orgulho Do Seu Codigo

Qualidade? Pra quem?

Page 20: Voce Tem Orgulho Do Seu Codigo
Page 21: Voce Tem Orgulho Do Seu Codigo

E nós?

Page 22: Voce Tem Orgulho Do Seu Codigo

http://www.flickr.com/photos/danielankers/2639889958/

Até quando?

Page 23: Voce Tem Orgulho Do Seu Codigo

Até quando?

Page 24: Voce Tem Orgulho Do Seu Codigo
Page 25: Voce Tem Orgulho Do Seu Codigo

Mas não é fácil!

Page 27: Voce Tem Orgulho Do Seu Codigo
Page 28: Voce Tem Orgulho Do Seu Codigo

Por que seria diferente?

Page 29: Voce Tem Orgulho Do Seu Codigo

Seu código fede?

Page 30: Voce Tem Orgulho Do Seu Codigo
Page 31: Voce Tem Orgulho Do Seu Codigo

“Nos dias de hoje, entregar uma linha de código sem que ela seja

testada é Irresponsabilidade Profissional”

Robert Uncle Bob

Page 32: Voce Tem Orgulho Do Seu Codigo

Fábrica de Elásticos

Page 33: Voce Tem Orgulho Do Seu Codigo

Debugging sucks! Testing Rules!

Page 34: Voce Tem Orgulho Do Seu Codigo

Testes

Page 35: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

Page 36: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

Page 37: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

SQLUnit

Page 38: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

SQLUnit CppUnit

Page 39: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

NUnit

SQLUnit CppUnit

Page 40: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

NUnit

Fitnesse

SQLUnit CppUnit

Page 41: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

NUnit

Fitnesse

Selenium

SQLUnit CppUnit

Page 42: Voce Tem Orgulho Do Seu Codigo

TestesJUnit

dbUnit

NUnit

Fitnesse

Selenium

SQLUnit CppUnit

JMeter

Page 43: Voce Tem Orgulho Do Seu Codigo

Quão Sexy é o seu código?

Page 44: Voce Tem Orgulho Do Seu Codigo

Quão Sexy é o seu código?

Page 45: Voce Tem Orgulho Do Seu Codigo

O código

Page 46: Voce Tem Orgulho Do Seu Codigo

// create some properties and get the default SessionProperties props = new Properties();props.put("mail.smtp.host", _smtpHost);Session session = Session.getDefaultInstance(props, null); // create a messageAddress replyToList[] = { new InternetAddress(replyTo) };Message newMessage = new MimeMessage(session);if (_fromName != null) newMessage.setFrom(new InternetAddress(from, _fromName + " on behalf of " + replyTo));else newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate); // send newMessageTransport transport = session.getTransport(SMTP_MAIL);transport.connect(_smtpHost, _user, _password);transport.sendMessage(newMessage, _toList);

Page 47: Voce Tem Orgulho Do Seu Codigo

Session session = this.loadDefaultConfiguration(); 

Message email = this.createEmailMessage( fromName, replyTo, subject, message );

 this.sendMessage(session, email);

http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/

Page 48: Voce Tem Orgulho Do Seu Codigo

A API

Page 49: Voce Tem Orgulho Do Seu Codigo

class Email { public Email() { ... } public void setFrom(String from) { ... } public void setTo(String to) { ... } public void send() { // YOUR HOT CODE HERE }}

http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/

Page 50: Voce Tem Orgulho Do Seu Codigo

Email email = new Email ( );email.setFrom( “[email protected]”);email.setTo (“[email protected]”);email.setSubject (“Teste email”);email.setMessage (“Mensagem”);email.send();

http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/

Page 51: Voce Tem Orgulho Do Seu Codigo

new EmailMessage( ) .from("[email protected]") .to("[email protected]") .withSubject("Fluent Mail Example") .withBody("What a nice code!") .send();

http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/

Page 52: Voce Tem Orgulho Do Seu Codigo

Quão Sexy é o seu código?

Page 53: Voce Tem Orgulho Do Seu Codigo

O que este código faz?

java.util.Calendar c =

java.util.Calendar.getInstance();

c.set(2005, java.util.Calendar.NOVEMBER, 20);

long time = c.getTime();

http://www.slideshare.net/gvespucci/refactoring-an-introduction

Page 54: Voce Tem Orgulho Do Seu Codigo

long time = october(20, 2008);

http://www.slideshare.net/gvespucci/refactoring-an-introductionhttp://www.flickr.com/photos/schoeband/3861094589/sizes/l/

Page 55: Voce Tem Orgulho Do Seu Codigo

What is a Clean Code?

“Quando você olha para o código, percebe que ele faz exatamente o que você esperava”

Howard Cunningham

http://railsconf.blip.tv/file/2089545/

Page 56: Voce Tem Orgulho Do Seu Codigo

Como medir Clean Code??

Page 57: Voce Tem Orgulho Do Seu Codigo

Como medir Clean Code??

cleanCode = WTF / sec

Page 58: Voce Tem Orgulho Do Seu Codigo

// create some properties and get the default SessionProperties props = new Properties();props.put("mail.smtp.host", _smtpHost);Session session = Session.getDefaultInstance(props, null); // create a messageAddress replyToList[] = { new InternetAddress(replyTo) };Message newMessage = new MimeMessage(session);if (_fromName != null) newMessage.setFrom(new InternetAddress(from, _fromName + " on behalf of " + replyTo));else newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate); // send newMessageTransport transport = session.getTransport(SMTP_MAIL);transport.connect(_smtpHost, _user, _password);transport.sendMessage(newMessage, _toList);

Page 59: Voce Tem Orgulho Do Seu Codigo

// create some properties and get the default SessionProperties props = new Properties();props.put("mail.smtp.host", _smtpHost);Session session = Session.getDefaultInstance(props, null); // create a messageAddress replyToList[] = { new InternetAddress(replyTo) };Message newMessage = new MimeMessage(session);if (_fromName != null) newMessage.setFrom(new InternetAddress(from, _fromName + " on behalf of " + replyTo));else newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate); // send newMessageTransport transport = session.getTransport(SMTP_MAIL);transport.connect(_smtpHost, _user, _password);transport.sendMessage(newMessage, _toList);

WTF?!

Page 60: Voce Tem Orgulho Do Seu Codigo

// create some properties and get the default SessionProperties props = new Properties();props.put("mail.smtp.host", _smtpHost);Session session = Session.getDefaultInstance(props, null); // create a messageAddress replyToList[] = { new InternetAddress(replyTo) };Message newMessage = new MimeMessage(session);if (_fromName != null) newMessage.setFrom(new InternetAddress(from, _fromName + " on behalf of " + replyTo));else newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate); // send newMessageTransport transport = session.getTransport(SMTP_MAIL);transport.connect(_smtpHost, _user, _password);transport.sendMessage(newMessage, _toList);

WTF?!

WTF?!

Page 61: Voce Tem Orgulho Do Seu Codigo

// create some properties and get the default SessionProperties props = new Properties();props.put("mail.smtp.host", _smtpHost);Session session = Session.getDefaultInstance(props, null); // create a messageAddress replyToList[] = { new InternetAddress(replyTo) };Message newMessage = new MimeMessage(session);if (_fromName != null) newMessage.setFrom(new InternetAddress(from, _fromName + " on behalf of " + replyTo));else newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate); // send newMessageTransport transport = session.getTransport(SMTP_MAIL);transport.connect(_smtpHost, _user, _password);transport.sendMessage(newMessage, _toList);

WTF?!

WTF?!

WTF?!

Page 62: Voce Tem Orgulho Do Seu Codigo

new EmailMessage( ) .from("[email protected]") .to("[email protected]") .withSubject("Fluent Mail Example") .withBody("What a nice code!") .send();

http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/

Page 63: Voce Tem Orgulho Do Seu Codigo
Page 64: Voce Tem Orgulho Do Seu Codigo

TDD

Page 65: Voce Tem Orgulho Do Seu Codigo

Test all the Fucking time!

Page 66: Voce Tem Orgulho Do Seu Codigo
Page 67: Voce Tem Orgulho Do Seu Codigo

Automatização!

Page 68: Voce Tem Orgulho Do Seu Codigo

Ant / Gant / PythonAutomatização!

Page 69: Voce Tem Orgulho Do Seu Codigo

Ant / Gant / Python

Maven / Javagems

Automatização!

Page 70: Voce Tem Orgulho Do Seu Codigo

Ant / Gant / Python

Maven / Javagems

JUnit / Selenium

Automatização!

Page 71: Voce Tem Orgulho Do Seu Codigo

Ant / Gant / Python

Maven / Javagems

Cuise Control

JUnit / Selenium

Automatização!

Page 72: Voce Tem Orgulho Do Seu Codigo

Ant / Gant / Python

Maven / Javagems

Cuise Control

Findbugs

JUnit / Selenium

Automatização!

Page 73: Voce Tem Orgulho Do Seu Codigo

Doxygen

Collaboration

Call Hierarchy

Dot Representation

Documentation

http://www.stack.nl/~dimitri/doxygen

Page 74: Voce Tem Orgulho Do Seu Codigo
Page 75: Voce Tem Orgulho Do Seu Codigo

pair programming

http://www.flickr.com/photos/menlopics/3928252097/in/set-72157607305293501/

Código Coletivo

Page 76: Voce Tem Orgulho Do Seu Codigo

Estude! Atualize-se!

Page 77: Voce Tem Orgulho Do Seu Codigo
Page 78: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Page 79: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

Page 80: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Page 81: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Design Patterns

Page 82: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Design Patterns

Design by Contract

Page 83: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Design Patterns

Design by Contract

Orientação a Ojetos

Page 84: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Design Patterns

Design by Contract

Orientação a OjetosTDD

Page 85: Voce Tem Orgulho Do Seu Codigo

Integração Contínua

Injeção de Dependência

DSLs

Design Patterns

Design by Contract

Orientação a OjetosTDD

Uma linguagem nova por ano

Page 86: Voce Tem Orgulho Do Seu Codigo

Scrum MasterTrabalhe em Equipe!!!

Page 87: Voce Tem Orgulho Do Seu Codigo
Page 89: Voce Tem Orgulho Do Seu Codigo

Dúvidas?