SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

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

Editor's Notes

  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