SlideShare uma empresa Scribd logo
1 de 48
Code Wants to be Stoopid!
Who am I?

      • Jim Siegienski

      • 16 years of experience

      • Fortune 50 to Start-ups

      • Application Architect at...
Dave Ramsey Development Team
Dave Ramsey Development Team
BEGIN
  domainlength := LENGTH(domainin);
  firstplace := INSTR(domainin, '|', 1, 1);
  IF firstplace != 0 THEN
    secondplace := INSTR (domainin, '|', 1, 2);
  END IF;
  IF secondplace != 0 THEN
     thirdplace := INSTR (domainin, '|', 1, 3);
  END IF;
  IF thirdplace != 0 THEN
     fourthplace := INSTR (domainin, '|', 1, 4);
  END IF;
  IF fourthplace != 0 THEN
     fifthplace := INSTR (domainin, '|', 1, 5);
  END IF;
  IF fifthplace != 0 THEN
     sixthplace := INSTR (domainin, '|', 1, 6);
  END IF;
  IF sixthplace != 0 THEN
     seventhplace := INSTR (domainin, '|', 1, 7);
  END IF;
  IF firstplace != 0 AND firstplace != domainlength THEN
     firststring := SUBSTR(domainin, 1, (firstplace-1));
  ELSIF firstplace = domainlength THEN
      firststring := SUBSTR (domainin, 1, (firstplace -1  ));
  ELSIF firstplace = 0 AND domainlength !=0 THEN
      firststring := domainin;
        GOTO get_domain_id;
  END IF;
  IF secondplace != 0 AND secondplace != domainlength THEN
     secondstring := SUBSTR(domainin, (firstplace+1), (secondplace - firstplace-1));
  ELSIF secondplace = domainlength THEN
      secondstring := SUBSTR (domainin, (firstplace+1), (secondplace-firstplace -1  ));
  ELSIF secondplace = 0 AND firstplace != 0 THEN
      secondstring := SUBSTR (domainin, (firstplace+1), (domainlength - firstplace));
      GOTO get_domain_id;
  END IF;
  IF thirdplace != 0 AND thirdplace != domainlength THEN
     thirdstring := SUBSTR(domainin, (secondplace+1), (thirdplace - secondplace -1));
  ELSIF thirdplace = domainlength THEN
      thirdstring := SUBSTR (domainin, (secondplace+1), (thirdplace-secondplace -1  ));
  ELSIF thirdplace = 0 AND secondplace != 0 THEN
      thirdstring := SUBSTR (domainin, (secondplace + 1), (domainlength - secondplace));
      GOTO get_domain_id;
  END IF;
private void SetAccount(RequisitionData.RequisitionItem requisitionItem,
                        AccountData.Account account, bool automation)
{
    bool allowSetAccount = false;
 
    if(account != null)
    {
        // if the account entry is being set by automation, ensure that
        // the user hasn't already set a value
        if (automation)
        {
            if (!requisitionItem.IsAccountCodeNull())
            {
                if (requisitionItem.AccountCode == string.Empty)
                    allowSetAccount = true;
                else
                    allowSetAccount = true;
            }
            else
                allowSetAccount = true;
        }
        else
            allowSetAccount = true;
 
        if (allowSetAccount)
        {
            requisitionItem.AccountID = account.ID;
            requisitionItem.AccountCode = account.Code;
        }
    }
}
Public Function makeBoolean(ByVal b As Boolean)
  Return b
End Function

Public Function makeByte(ByVal b As Byte)
  Return b
End Function

Public Function makeChar(ByVal c As Char)
  Return c
End Function

Public Function makeDate(ByVal d As Date)
  Return d
End Function

Public Function makeDecimal(ByVal d As Decimal)
  Return d
End Function

Public Function makeUShort(ByVal u As UShort)
  Return u
End Function
"Any fool can write code that a
  computer can understand. Good
programmers write code that humans
          can understand."




            Martin Fowler
class ContactController {

           def create = {
                      def json = request.JSON

                       Contact contact = new Contact()
                       //map json to object
                       if (json.first_name) { contact.firstName = json.first_name }
                       if (json.last_name) { contact.lastName = json.last_name }

                       //checking attributes
                       HashSet set = new HashSet()
                       json.each { attribute ->
                                   ContactAttributeType type = new ContactAttributeType()
                                   type.value = attribute.key


                                   if (attribute.key == 'email') {
                                                 attribute.value.each { val ->
                                                             ContactAttribute a = new ContactAttribute()
                                                             a.key = val.key
                                                             a.value = val.value
                                                             a.type = type
                                                             set.add(a)
                                                 }
                                   }

                                   if (attribute.key == 'address') {
                                                 attribute.value.each { val ->
                                                             ContactAttribute a = new ContactAttribute()
                                                             a.key = val.key
                                                             a.value = val.value
                                                             a.type = type
                                                             set.add(a)
                                                 }
                                   }

                       }

                       contact.attributes = set

                       //save
                       if (!contact.save()) {
                                    contact.errors.each {
                                                println it
                                    }
                       }

                       //convert to a map to output
                       Map map = new HashMap()
                       map.put("id", contact.id)
                       map.put("first_name", contact.firstName)
                       map.put("last_name", contact.lastName)

                       contact.attributes.each { att ->

                                   Map m = map.get(att.type.value)
                                   if (!m) {
                                             m = new HashMap()
                                             map.put(att.type.value, m)
                                   }

                                   m.put(att.key, att.value)
                       }

                       render map as JSON
           }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          render map as JSON
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          render map as JSON
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          render map as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          render map as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          render map as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          render serialize(contact) as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          return map
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          render serialize(contact) as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          return map
     }
}
class ContactController {

     def create = {
          def json = request.JSON

          Contact contact = new Contact()

          applyJson(contact, json)

          if (!contact.save()) {
                 contact.errors.each {
                      println it
                 }
          }

          render serialize(contact) as JSON
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
          Map map = new HashMap()
          map.put("id", contact.id)
          map.put("first_name", contact.firstName)
          map.put("last_name", contact.lastName)

          return map
     }
}
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
           Map map = new HashMap()
           map.put("id", contact.id)
           map.put("first_name", contact.firstName)
           map.put("last_name", contact.lastName)

           return map
     }
}
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
           Map map = new HashMap()
           map.put("id", contact.id)
           map.put("first_name", contact.firstName)
           map.put("last_name", contact.lastName)

           return map
     }
}
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
           Map map = new HashMap()
           map.put("id", contact.id)
           map.put("first_name", contact.firstName)
           map.put("last_name", contact.lastName)

           return map
     }
}
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def applyJson = { contact, json ->
          if (json.first_name) { contact.firstName = json.first_name }
          if (json.last_name) { contact.lastName = json.last_name }
     }

     def serialize = { contact ->
           Map map = new HashMap()
           map.put("id", contact.id)
           map.put("first_name", contact.firstName)
           map.put("last_name", contact.lastName)

           return map
     }
}
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def update = { contact ->
          contact = updateContact(contact, request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()
           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def updateContact = { contact, json ->
          applyJson(contact, json)
          if (!contact.save()) {
                 contact.errors.each {
                       println it
                 }
          }
          return contact
     }
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def update = { contact ->
          contact = updateContact(contact, request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()
           applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }

     def updateContact = { contact, json ->
          applyJson(contact, json)
          if (!contact.save()) {
                 contact.errors.each {
                       println it
                 }
          }
          return contact
     }
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def update = { contact ->
          contact = updateContact(contact, request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           return updateJson(contact, json)
     }

     def updateContact = { contact, json ->
          applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def update = { contact ->
          contact = updateContact(contact, request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           return updateJson(contact, json)
     }

     def updateContact = { contact, json ->
          applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }
class ContactController {

     def create = {
           def contact = createContact(request.JSON)

           render serialize(contact) as JSON
     }

     def update = { contact ->
          contact = updateContact(contact, request.JSON)

           render serialize(contact) as JSON
     }

     def createContact = { json ->
           Contact contact = new Contact()

           return updateJson(contact, json)
     }

     def updateContact = { contact, json ->
          applyJson(contact, json)

           if (!contact.save()) {
                  contact.errors.each {
                        println it
                  }
           }
           return contact
     }
class ContactController {

     def ContactService contactService

     def create = {
          def contact = contactService.create(request.JSON)

          render contactService.serialize(contact) as JSON
     }

     def update = { contact ->
          contact = contactService.updateContact(contact, request.JSON)

          render contactService.serialize(contact) as JSON
     }

}
class ContactController {

     def ContactService contactService

     def create = {
          def contact = contactService.create(request.JSON)

          render contactService.serialize(contact) as JSON
     }

     def update = { contact ->
          contact = contactService.updateContact(contact, request.JSON)

          render contactService.serialize(contact) as JSON
     }

}
class ContactController {

     def ContactService contactService

     def create = {
          def contact = contactService.create(request.JSON)

          render contact.serialize() as JSON
     }

     def update = { contact ->
          contact = contactService.updateContact(contact, request.JSON)

          render contact.serialize() as JSON
     }
}
class ContactController {

     def ContactService contactService

     def create = {
          def contact = contactService.create(request.JSON)

          render contact.serialize() as JSON
     }

     def update = { contact ->
          contact = contactService.updateContact(contact, request.JSON)

          render contact.serialize() as JSON
     }
}
Summary
One Thing

• A method should only do one thing

• It should do what it's name says it does

• Comments are a hint you're doing too much
Method Length


• Over 10 lines... Break it apart

• 1,000 lines and beyond - seek help
Duplicate Code

• Combine

• Move it?

• Leverage
"No matter who. No matter what. No
 matter when. Short term. Long term.
   Any term. Writing good code is
ALWAYS faster than writing bad code."




        Robert Martin (AKA Uncle Bob)
“When you’re a carpenter making a
  beautiful chest of drawers, you’re
not going to use a piece of plywood
  on the back, even though it faces
the wall and nobody will ever see it.”


               Steve Jobs
Questions?
Thank You

• Dave Ramsey Team

• Luke Stokes - FoxyCart

• BarCamp Nashville

• Fellow Coders
Resources
• @unclebobmartin

• http://www.objectmentor.com/omTeam/martin_r.html



• @martinfowlern

• http://martinfowler.com/

• 'Refactoring: Improving the Design of Existing Code' by Martin Fowler



• @JimSiegienski

• Jim.Siegienski@gmail.com

Mais conteúdo relacionado

Mais procurados

The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181Mahmoud Samir Fayed
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional SwiftJason Larsen
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기Suyeol Jeon
 
The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180Mahmoud Samir Fayed
 
Functional programming techniques in real-world microservices
Functional programming techniques in real-world microservicesFunctional programming techniques in real-world microservices
Functional programming techniques in real-world microservicesAndrás Papp
 
The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31Mahmoud Samir Fayed
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Leonardo Soto
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureDmytro Zaitsev
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Leonardo Soto
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonUC San Diego
 
Scala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureScala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureHossam Karim
 
Type safe embedded domain-specific languages
Type safe embedded domain-specific languagesType safe embedded domain-specific languages
Type safe embedded domain-specific languagesArthur Xavier
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84Mahmoud Samir Fayed
 
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentVincenzo Barone
 

Mais procurados (20)

Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
ddd+scala
ddd+scaladdd+scala
ddd+scala
 
The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional Swift
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180The Ring programming language version 1.5.1 book - Part 29 of 180
The Ring programming language version 1.5.1 book - Part 29 of 180
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Functional programming techniques in real-world microservices
Functional programming techniques in real-world microservicesFunctional programming techniques in real-world microservices
Functional programming techniques in real-world microservices
 
The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31The Ring programming language version 1.5 book - Part 6 of 31
The Ring programming language version 1.5 book - Part 6 of 31
 
Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)Jython: Python para la plataforma Java (JRSL 09)
Jython: Python para la plataforma Java (JRSL 09)
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasure
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Scala by Luc Duponcheel
Scala by Luc DuponcheelScala by Luc Duponcheel
Scala by Luc Duponcheel
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Scala Domain Modeling and Architecture
Scala Domain Modeling and ArchitectureScala Domain Modeling and Architecture
Scala Domain Modeling and Architecture
 
Type safe embedded domain-specific languages
Type safe embedded domain-specific languagesType safe embedded domain-specific languages
Type safe embedded domain-specific languages
 
The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84The Ring programming language version 1.2 book - Part 20 of 84
The Ring programming language version 1.2 book - Part 20 of 84
 
Libretto
LibrettoLibretto
Libretto
 
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product DevelopmentTom Lazar   Using Zope3 Views And Viewlets For Plone 3.0 Product Development
Tom Lazar Using Zope3 Views And Viewlets For Plone 3.0 Product Development
 

Semelhante a Stoopid code

Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8bryanbibat
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in ScalaDamian Jureczko
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Evgeny Borisov
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHPGuilherme Blanco
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kirill Rozov
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 WorldDaniel Blyth
 
Js in js
Js in jsJs in js
Js in jsAlipay
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)Venkatesh Prasad Ranganath
 
The underestimated power of KeyPaths
The underestimated power of KeyPathsThe underestimated power of KeyPaths
The underestimated power of KeyPathsVincent Pradeilles
 

Semelhante a Stoopid code (20)

Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Scala 2013 review
Scala 2013 reviewScala 2013 review
Scala 2013 review
 
Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2Groovy puzzlers jug-moscow-part 2
Groovy puzzlers jug-moscow-part 2
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
Object Calisthenics Applied to PHP
Object Calisthenics Applied to PHPObject Calisthenics Applied to PHP
Object Calisthenics Applied to PHP
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Scala taxonomy
Scala taxonomyScala taxonomy
Scala taxonomy
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Typelevel summit
Typelevel summitTypelevel summit
Typelevel summit
 
Scala in a Java 8 World
Scala in a Java 8 WorldScala in a Java 8 World
Scala in a Java 8 World
 
Js in js
Js in jsJs in js
Js in js
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
1.5 pattern matching
1.5 pattern matching1.5 pattern matching
1.5 pattern matching
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)Property Based Testing [5] - Software Testing Techniques (CIS640)
Property Based Testing [5] - Software Testing Techniques (CIS640)
 
The underestimated power of KeyPaths
The underestimated power of KeyPathsThe underestimated power of KeyPaths
The underestimated power of KeyPaths
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

Stoopid code

  • 1. Code Wants to be Stoopid!
  • 2. Who am I? • Jim Siegienski • 16 years of experience • Fortune 50 to Start-ups • Application Architect at...
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. BEGIN   domainlength := LENGTH(domainin);   firstplace := INSTR(domainin, '|', 1, 1);   IF firstplace != 0 THEN     secondplace := INSTR (domainin, '|', 1, 2);   END IF;   IF secondplace != 0 THEN      thirdplace := INSTR (domainin, '|', 1, 3);   END IF;   IF thirdplace != 0 THEN      fourthplace := INSTR (domainin, '|', 1, 4);   END IF;   IF fourthplace != 0 THEN      fifthplace := INSTR (domainin, '|', 1, 5);   END IF;   IF fifthplace != 0 THEN      sixthplace := INSTR (domainin, '|', 1, 6);   END IF;   IF sixthplace != 0 THEN      seventhplace := INSTR (domainin, '|', 1, 7);   END IF;   IF firstplace != 0 AND firstplace != domainlength THEN      firststring := SUBSTR(domainin, 1, (firstplace-1));   ELSIF firstplace = domainlength THEN       firststring := SUBSTR (domainin, 1, (firstplace -1  ));   ELSIF firstplace = 0 AND domainlength !=0 THEN       firststring := domainin;         GOTO get_domain_id;   END IF;   IF secondplace != 0 AND secondplace != domainlength THEN      secondstring := SUBSTR(domainin, (firstplace+1), (secondplace - firstplace-1));   ELSIF secondplace = domainlength THEN       secondstring := SUBSTR (domainin, (firstplace+1), (secondplace-firstplace -1  ));   ELSIF secondplace = 0 AND firstplace != 0 THEN       secondstring := SUBSTR (domainin, (firstplace+1), (domainlength - firstplace));       GOTO get_domain_id;   END IF;   IF thirdplace != 0 AND thirdplace != domainlength THEN      thirdstring := SUBSTR(domainin, (secondplace+1), (thirdplace - secondplace -1));   ELSIF thirdplace = domainlength THEN       thirdstring := SUBSTR (domainin, (secondplace+1), (thirdplace-secondplace -1  ));   ELSIF thirdplace = 0 AND secondplace != 0 THEN       thirdstring := SUBSTR (domainin, (secondplace + 1), (domainlength - secondplace));       GOTO get_domain_id;   END IF;
  • 13. private void SetAccount(RequisitionData.RequisitionItem requisitionItem,                         AccountData.Account account, bool automation) {     bool allowSetAccount = false;       if(account != null)     {         // if the account entry is being set by automation, ensure that         // the user hasn't already set a value         if (automation)         {             if (!requisitionItem.IsAccountCodeNull())             {                 if (requisitionItem.AccountCode == string.Empty)                     allowSetAccount = true;                 else                     allowSetAccount = true;             }             else                 allowSetAccount = true;         }         else             allowSetAccount = true;           if (allowSetAccount)         {             requisitionItem.AccountID = account.ID;             requisitionItem.AccountCode = account.Code;         }     } }
  • 14. Public Function makeBoolean(ByVal b As Boolean) Return b End Function Public Function makeByte(ByVal b As Byte) Return b End Function Public Function makeChar(ByVal c As Char) Return c End Function Public Function makeDate(ByVal d As Date) Return d End Function Public Function makeDecimal(ByVal d As Decimal) Return d End Function Public Function makeUShort(ByVal u As UShort) Return u End Function
  • 15. "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." Martin Fowler
  • 16.
  • 17.
  • 18. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() //map json to object if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } //checking attributes HashSet set = new HashSet() json.each { attribute -> ContactAttributeType type = new ContactAttributeType() type.value = attribute.key if (attribute.key == 'email') { attribute.value.each { val -> ContactAttribute a = new ContactAttribute() a.key = val.key a.value = val.value a.type = type set.add(a) } } if (attribute.key == 'address') { attribute.value.each { val -> ContactAttribute a = new ContactAttribute() a.key = val.key a.value = val.value a.type = type set.add(a) } } } contact.attributes = set //save if (!contact.save()) { contact.errors.each { println it } } //convert to a map to output Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) contact.attributes.each { att -> Map m = map.get(att.type.value) if (!m) { m = new HashMap() map.put(att.type.value, m) } m.put(att.key, att.value) } render map as JSON } }
  • 19. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } if (!contact.save()) { contact.errors.each { println it } } Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) render map as JSON } }
  • 20. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } if (!contact.save()) { contact.errors.each { println it } } Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) render map as JSON } }
  • 21. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) render map as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } }
  • 22. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) render map as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } }
  • 23. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) render map as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } }
  • 24. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } render serialize(contact) as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 25. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } render serialize(contact) as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 26. class ContactController { def create = { def json = request.JSON Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } render serialize(contact) as JSON } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 27. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 28. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 29. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 30. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def applyJson = { contact, json -> if (json.first_name) { contact.firstName = json.first_name } if (json.last_name) { contact.lastName = json.last_name } } def serialize = { contact -> Map map = new HashMap() map.put("id", contact.id) map.put("first_name", contact.firstName) map.put("last_name", contact.lastName) return map } }
  • 31. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def update = { contact -> contact = updateContact(contact, request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def updateContact = { contact, json -> applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact }
  • 32. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def update = { contact -> contact = updateContact(contact, request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact } def updateContact = { contact, json -> applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact }
  • 33. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def update = { contact -> contact = updateContact(contact, request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() return updateJson(contact, json) } def updateContact = { contact, json -> applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact }
  • 34. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def update = { contact -> contact = updateContact(contact, request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() return updateJson(contact, json) } def updateContact = { contact, json -> applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact }
  • 35. class ContactController { def create = { def contact = createContact(request.JSON) render serialize(contact) as JSON } def update = { contact -> contact = updateContact(contact, request.JSON) render serialize(contact) as JSON } def createContact = { json -> Contact contact = new Contact() return updateJson(contact, json) } def updateContact = { contact, json -> applyJson(contact, json) if (!contact.save()) { contact.errors.each { println it } } return contact }
  • 36. class ContactController { def ContactService contactService def create = { def contact = contactService.create(request.JSON) render contactService.serialize(contact) as JSON } def update = { contact -> contact = contactService.updateContact(contact, request.JSON) render contactService.serialize(contact) as JSON } }
  • 37. class ContactController { def ContactService contactService def create = { def contact = contactService.create(request.JSON) render contactService.serialize(contact) as JSON } def update = { contact -> contact = contactService.updateContact(contact, request.JSON) render contactService.serialize(contact) as JSON } }
  • 38. class ContactController { def ContactService contactService def create = { def contact = contactService.create(request.JSON) render contact.serialize() as JSON } def update = { contact -> contact = contactService.updateContact(contact, request.JSON) render contact.serialize() as JSON } }
  • 39. class ContactController { def ContactService contactService def create = { def contact = contactService.create(request.JSON) render contact.serialize() as JSON } def update = { contact -> contact = contactService.updateContact(contact, request.JSON) render contact.serialize() as JSON } }
  • 41. One Thing • A method should only do one thing • It should do what it's name says it does • Comments are a hint you're doing too much
  • 42. Method Length • Over 10 lines... Break it apart • 1,000 lines and beyond - seek help
  • 43. Duplicate Code • Combine • Move it? • Leverage
  • 44. "No matter who. No matter what. No matter when. Short term. Long term. Any term. Writing good code is ALWAYS faster than writing bad code." Robert Martin (AKA Uncle Bob)
  • 45. “When you’re a carpenter making a beautiful chest of drawers, you’re not going to use a piece of plywood on the back, even though it faces the wall and nobody will ever see it.” Steve Jobs
  • 47. Thank You • Dave Ramsey Team • Luke Stokes - FoxyCart • BarCamp Nashville • Fellow Coders
  • 48. Resources • @unclebobmartin • http://www.objectmentor.com/omTeam/martin_r.html • @martinfowlern • http://martinfowler.com/ • 'Refactoring: Improving the Design of Existing Code' by Martin Fowler • @JimSiegienski • Jim.Siegienski@gmail.com

Notas do Editor

  1. Welcome!\n
  2. \n\n
  3. \n\n
  4. All Greek to me\n
  5. Spaghetti code\n
  6. Make it fit\n
  7. \n\n
  8. Take chaos\n
  9. Bring order\n
  10. When simplifying:\n1 one thing\n2 length\n3 remove duplicates\n
  11. Jackson pollock as a coder\n
  12. Zen!?\nMake sure you're adding value\n
  13. Too simple\n
  14. \n\n
  15. Fragile\n
  16. Strong\n
  17. Pre release code\n
  18. Simplified for example\n
  19. Mapping\n
  20. Extract\n
  21. Call\n
  22. Serialize\n
  23. Extract\n
  24. Call\n
  25. Revisit create\n
  26. Extract\n
  27. Call\n
  28. Create is now simple\n
  29. Clearer names, easier to add...\n
  30. Update\n
  31. Duplicate code\n
  32. Just reuse update\n
  33. Controller just takes calls\n\n\n
  34. Why is there biz logic?\n
  35. Move business code out\n
  36. Contact knows its own data\n
  37. Let it own it\n
  38. Final\nClear\nReadable\n
  39. \n\n
  40. \n\n
  41. \n\n
  42. \n\n
  43. \n\n
  44. \n\n
  45. \n\n
  46. \n\n
  47. \n\n