Monday, July 26, 2021


Notes for Code & Coffee on 7/23/2021


Topic for 7/23: POP QUIZ:  Name a few code smells

  • Identified smells:
    • Player 1 - (anonymized players in case they prefer it that way)
      • Overused singleton
      • Overly complex test code (to get 100% coverage)
        • test private ctor throws exception (Bruce’s example)
      • Side effects
      • Pushing to a dev branch that hasn’t been green in three months
        • Broken builds
        • See also disabled tests
    • Player 2
      • Lack of type safe code in Java
        • extra tests required to assert types
      • Git commit messages that just tell exactly what was done
        • maybe useful maybe not
        • “Undoing last commit”
        • For better commits try:
        • Make it easy to make the change (this may be hard) then make the easy change (Kent Beck)
    • Player 3
      • Shotgun surgery
        • Making one change causes need to change in other places
      • Feature envy
        • Got a function doing work and needs or over uses collaborators
      • Long methods
      • Badly named variables
    • Player 4
      • Inconsistent IDE linting settings.
  • What to do about code smells
    • “When I was at x-company that was our job”
      • 2 million line code base
      • 30% dead code
      • 20% duplicate code
        • Copy/Paste coding
        • Aggressively adding huge amounts of dead code
      • Removed dead code and worthless comments
        • 5000 loc -> 400 loc (extreme case)
        • Nothing makes me happier than deleting code
    • Eclipse and Intellij
      • if statements that explicitly compare against true or false.
        • little t true and big true and other notes I missed
      • Do some uncomfortable low risk cleanups
  • Links: