SlideShare ist ein Scribd-Unternehmen logo
1 von 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
Stoopid code
Stoopid code
Stoopid code
Stoopid code
Stoopid code
Stoopid code
Stoopid code
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
Stoopid code
Stoopid code
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 

Kürzlich hochgeladen (20)

VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 

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...
  • 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
  • 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

Hinweis der Redaktion

  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