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




Você tem orgulho do
    seu código?

Samuel Crescêncio e Victor Hugo Germano
Samuel Crescêncio
Victor Hugo Germano




      / victorhg
/* 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
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;
}
      }
      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;
!!!!!!!!!!!!!
Qual o nosso papel?
Qualidade?
Qualidade?
Pra quem?
E nós?
Até quando?




     http://www.flickr.com/photos/danielankers/2639889958/
Até quando?
Mas não é fácil!
http://www.mypix.com.br/site/pixpocketmag/super-geek-cinto-de-utilidades-ou-quase-isso/
Por que seria diferente?
Seu código fede?
“Nos dias de hoje, entregar uma
linha de código sem que ela seja
   testada é Irresponsabilidade
           Profissional”
                         Robert Uncle Bob
Fábrica de Elásticos
Debugging
 sucks!     Testing Rules!
Testes
JUnit

        Testes
JUnit

        Testes
    dbUnit
JUnit


SQLUnit Testes
     dbUnit
JUnit


SQLUnit Testes CppUnit
     dbUnit
JUnit
                 NUnit

SQLUnit Testes CppUnit
     dbUnit
Fitnesse
 JUnit
                    NUnit

SQLUnit Testes CppUnit
     dbUnit
Fitnesse
 JUnit
                    NUnit

SQLUnit Testes CppUnit
     dbUnit
               Selenium
Fitnesse
 JUnit
                       NUnit

SQLUnit Testes CppUnit
         dbUnit
                  Selenium
JMeter
Quão Sexy é o
 seu código?
Quão Sexy é o
 seu código?
O código
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", _smtpHost);
Session session = Session.getDefaultInstance(props, null);
 
// create a message
Address 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 newMessage
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
transport.sendMessage(newMessage, _toList);
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/
A API
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/
Email email = new Email ( );
email.setFrom( “test@localhost.net”);
email.setTo (“destino@localhost.net”);
email.setSubject (“Teste email”);
email.setMessage (“Mensagem”);
email.send();



            http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
new EmailMessage( )
  .from("teste@localhost.net")
  .to("destination@address.com")
  .withSubject("Fluent Mail Example")
  .withBody("What a nice code!")
  .send();



           http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
Quão Sexy é
o seu código?
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
long time = october(20, 2008);




http://www.flickr.com/photos/schoeband/3861094589/sizes/l/   http://www.slideshare.net/gvespucci/refactoring-an-introduction
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/
Como medir
Clean Code??
Como medir
   Clean Code??

cleanCode = WTF / sec
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", _smtpHost);
Session session = Session.getDefaultInstance(props, null);
 
// create a message
Address 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 newMessage
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
transport.sendMessage(newMessage, _toList);
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", _smtpHost);              WTF?!
Session session = Session.getDefaultInstance(props, null);
 
// create a message
Address 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 newMessage
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
transport.sendMessage(newMessage, _toList);
// create some properties and get the default Session
Properties props = new Properties();
props.put("mail.smtp.host", _smtpHost);              WTF?!
Session session = Session.getDefaultInstance(props, null);
 
// create a message
Address replyToList[] = { new InternetAddress(replyTo) };
Message newMessage = new MimeMessage(session);
if (_fromName != null)
     newMessage.setFrom(new InternetAddress(from,

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

else
         _fromName + " on behalf of " + replyTo));
                                                     WTF?!
     newMessage.setFrom(new InternetAddress(from));
     newMessage.setReplyTo(replyToList);
     newMessage.setRecipients(Message.RecipientType.BCC,
             _toList);
     newMessage.setSubject(subject);
     newMessage.setSentDate(sentDate);
 
// send newMessage                                   WTF?!
Transport transport = session.getTransport(SMTP_MAIL);
transport.connect(_smtpHost, _user, _password);
transport.sendMessage(newMessage, _toList);
new EmailMessage( )
  .from("teste@localhost.net")
  .to("destination@address.com")
  .withSubject("Fluent Mail Example")
  .withBody("What a nice code!")
  .send();



           http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
TDD
Test all the Fucking
        time!
Automatização!
Automatização!   Ant / Gant / Python
Automatização!   Ant / Gant / Python

                   Maven / Javagems
Automatização!   Ant / Gant / Python

                   Maven / Javagems

                    JUnit / Selenium
Automatização!   Ant / Gant / Python

                   Maven / Javagems

                    JUnit / Selenium

                      Cuise Control
Automatização!   Ant / Gant / Python

                   Maven / Javagems

                    JUnit / Selenium

                      Cuise Control

                         Findbugs
Doxygen

  Collaboration
  Call Hierarchy
  Dot Representation
  Documentation


http://www.stack.nl/~dimitri/doxygen
Código Coletivo




                                                                             pair programming




http://www.flickr.com/photos/menlopics/3928252097/in/set-72157607305293501/
Estude! Atualize-se!
Integração Contínua
Integração Contínua




Injeção de Dependência
Integração Contínua
                         DSLs




Injeção de Dependência
Integração Contínua
                         DSLs


Design Patterns




Injeção de Dependência
Integração Contínua
                         DSLs
             Design by Contract
Design Patterns




Injeção de Dependência
Integração Contínua
                         DSLs
             Design by Contract
Design Patterns
               Orientação a Ojetos


Injeção de Dependência
Integração Contínua
                         DSLs
             Design by Contract
Design Patterns
               Orientação a Ojetos
   TDD


Injeção de Dependência
Integração Contínua
                         DSLs
             Design by Contract
Design Patterns
               Orientação a Ojetos
   TDD
        Uma linguagem nova por ano
Injeção de Dependência
Trabalhe em Equipe!!!
      Scrum Master
Obrigado!

        @victorhg
 http://google.com/profiles/victorhg


          @oncast
samuel.crescencio@oncast.com.br
Dúvidas?

Voce Tem Orgulho Do Seu Codigo

  • 1.
    http://www.flickr.com/photos/caravinagre/1364614919/ Você tem orgulhodo seu código? Samuel Crescêncio e Victor Hugo Germano
  • 3.
  • 4.
  • 7.
    /* I realizethat 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
  • 8.
    Public static intgetTestcell() { 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 {
  • 9.
    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;
  • 10.
    } } 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)
  • 11.
    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
  • 12.
    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;
  • 13.
  • 14.
  • 17.
  • 19.
  • 21.
  • 22.
    Até quando? http://www.flickr.com/photos/danielankers/2639889958/
  • 23.
  • 25.
    Mas não éfácil!
  • 26.
  • 28.
    Por que seriadiferente?
  • 29.
  • 31.
    “Nos dias dehoje, entregar uma linha de código sem que ela seja testada é Irresponsabilidade Profissional” Robert Uncle Bob
  • 32.
  • 33.
    Debugging sucks! Testing Rules!
  • 34.
  • 35.
    JUnit Testes
  • 36.
    JUnit Testes dbUnit
  • 37.
  • 38.
  • 39.
    JUnit NUnit SQLUnit Testes CppUnit dbUnit
  • 40.
    Fitnesse JUnit NUnit SQLUnit Testes CppUnit dbUnit
  • 41.
    Fitnesse JUnit NUnit SQLUnit Testes CppUnit dbUnit Selenium
  • 42.
    Fitnesse JUnit NUnit SQLUnit Testes CppUnit dbUnit Selenium JMeter
  • 43.
    Quão Sexy éo seu código?
  • 44.
    Quão Sexy éo seu código?
  • 45.
  • 46.
    // create someproperties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", _smtpHost); Session session = Session.getDefaultInstance(props, null);   // create a message Address 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 newMessage Transport transport = session.getTransport(SMTP_MAIL); transport.connect(_smtpHost, _user, _password); transport.sendMessage(newMessage, _toList);
  • 47.
    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/
  • 48.
  • 49.
    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/
  • 50.
    Email email =new Email ( ); email.setFrom( “test@localhost.net”); email.setTo (“destino@localhost.net”); email.setSubject (“Teste email”); email.setMessage (“Mensagem”); email.send(); http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
  • 51.
    new EmailMessage( ) .from("teste@localhost.net") .to("destination@address.com") .withSubject("Fluent Mail Example") .withBody("What a nice code!") .send(); http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
  • 52.
    Quão Sexy é oseu código?
  • 53.
    O que estecó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
  • 54.
    long time =october(20, 2008); http://www.flickr.com/photos/schoeband/3861094589/sizes/l/ http://www.slideshare.net/gvespucci/refactoring-an-introduction
  • 55.
    What is aClean 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/
  • 56.
  • 57.
    Como medir Clean Code?? cleanCode = WTF / sec
  • 58.
    // create someproperties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", _smtpHost); Session session = Session.getDefaultInstance(props, null);   // create a message Address 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 newMessage Transport transport = session.getTransport(SMTP_MAIL); transport.connect(_smtpHost, _user, _password); transport.sendMessage(newMessage, _toList);
  • 59.
    // create someproperties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", _smtpHost); WTF?! Session session = Session.getDefaultInstance(props, null);   // create a message Address 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 newMessage Transport transport = session.getTransport(SMTP_MAIL); transport.connect(_smtpHost, _user, _password); transport.sendMessage(newMessage, _toList);
  • 60.
    // create someproperties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", _smtpHost); WTF?! Session session = Session.getDefaultInstance(props, null);   // create a message Address replyToList[] = { new InternetAddress(replyTo) }; Message newMessage = new MimeMessage(session); if (_fromName != null) newMessage.setFrom(new InternetAddress(from, else _fromName + " on behalf of " + replyTo)); WTF?! newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate);   // send newMessage Transport transport = session.getTransport(SMTP_MAIL); transport.connect(_smtpHost, _user, _password); transport.sendMessage(newMessage, _toList);
  • 61.
    // create someproperties and get the default Session Properties props = new Properties(); props.put("mail.smtp.host", _smtpHost); WTF?! Session session = Session.getDefaultInstance(props, null);   // create a message Address replyToList[] = { new InternetAddress(replyTo) }; Message newMessage = new MimeMessage(session); if (_fromName != null) newMessage.setFrom(new InternetAddress(from, else _fromName + " on behalf of " + replyTo)); WTF?! newMessage.setFrom(new InternetAddress(from)); newMessage.setReplyTo(replyToList); newMessage.setRecipients(Message.RecipientType.BCC, _toList); newMessage.setSubject(subject); newMessage.setSentDate(sentDate);   // send newMessage WTF?! Transport transport = session.getTransport(SMTP_MAIL); transport.connect(_smtpHost, _user, _password); transport.sendMessage(newMessage, _toList);
  • 62.
    new EmailMessage( ) .from("teste@localhost.net") .to("destination@address.com") .withSubject("Fluent Mail Example") .withBody("What a nice code!") .send(); http://guilherme.pro/2009/04/05/why-i-dont-write-code-comments/
  • 64.
  • 65.
    Test all theFucking time!
  • 67.
  • 68.
    Automatização! Ant / Gant / Python
  • 69.
    Automatização! Ant / Gant / Python Maven / Javagems
  • 70.
    Automatização! Ant / Gant / Python Maven / Javagems JUnit / Selenium
  • 71.
    Automatização! Ant / Gant / Python Maven / Javagems JUnit / Selenium Cuise Control
  • 72.
    Automatização! Ant / Gant / Python Maven / Javagems JUnit / Selenium Cuise Control Findbugs
  • 73.
    Doxygen Collaboration Call Hierarchy Dot Representation Documentation http://www.stack.nl/~dimitri/doxygen
  • 75.
    Código Coletivo pair programming http://www.flickr.com/photos/menlopics/3928252097/in/set-72157607305293501/
  • 76.
  • 78.
  • 79.
  • 80.
    Integração Contínua DSLs Injeção de Dependência
  • 81.
    Integração Contínua DSLs Design Patterns Injeção de Dependência
  • 82.
    Integração Contínua DSLs Design by Contract Design Patterns Injeção de Dependência
  • 83.
    Integração Contínua DSLs Design by Contract Design Patterns Orientação a Ojetos Injeção de Dependência
  • 84.
    Integração Contínua DSLs Design by Contract Design Patterns Orientação a Ojetos TDD Injeção de Dependência
  • 85.
    Integração Contínua DSLs Design by Contract Design Patterns Orientação a Ojetos TDD Uma linguagem nova por ano Injeção de Dependência
  • 86.
  • 88.
    Obrigado! @victorhg http://google.com/profiles/victorhg @oncast samuel.crescencio@oncast.com.br
  • 89.