Code Smells

Code Smells

  • What are they?
    • Signs that your code can be made better
    • Things you should look for when doing a code review
    • Learned from practical experience
    • There are many lists, this is mine of the top ones
    • They are not hard-and fast
  • The smells
    • Large class: Class longer than 100 or so lines
    • Large method: Method longer than 10 lines or so
    • Long parameter list: methods with 4 or more parameters
    • Single Responsiblity Violations: Class, methods should do one thing
    • Global variables: Almost always a very bad sign
    • Bad Name: Non descriptive or very short variable names
    • Unnecessary complexity: Nested conditionals (ifs and case) are questionable
    • Feature envy: A class that uses methods of another class exessively
Note Smells can be ambiguous or language dependent

Exercxise for teams

  • Set up each of your computers with rubocop
  • Do a code review of each of your mazes submissions (don’t believe rubocop)
  • Make a list of the code smells you see (including some not mentioned on my list)
  • Discuss some specific changes you would make to remove smells
  • We will discuss that after 20 minutes of team work.