Refactor Tractor Workshop presentations and workshop

Refactor Tractor Workshop

Structure

10 Warmup
15 Presentations
5 Pomodoro
5 Smell Review
25 Code-along / Workshop
5 Pomodoro
40 Paired practice
15 Review

Learning Goals

  • Revisit and reinforce the general points and goals of refactoring.
  • Communicate a technical problem.
  • Recognize common mistakes and bad practices in JS.
  • Develop strategies to refactor those mistakes.

Warmup

With your Quantified Self partner, take 10 minutes to identify a chunk of code (<= 10 lines) that you know is smelly, but haven’t had time or don’t know how to refactor it.

Develop talking points for a three minute presentation that address the following:

  • Why/how the code “smells”
    • What rules or conventions it violates (e.g., DRY)
  • The headaches (if any) this code has introduced to your project
  • How you might refactor or deal with it
  • Why refactoring would be worth the time and effort

Split speaking time evenly between you and your partner

Presentations

Each group present their “smellyscript” to the other groups to practice technical communication (3 minutes).

Review presented topics

Low Hanging fruits

  • Leftover debugger statements
  • Commented out code
  • Wonky whitespace
  • Mismatched or too many semicolons
  • Inconsistent use of function syntax
  • Inconsistent use of var vs const & let
  • Dead, unused code

Other Code smells

  • Comments - fine line between comments that illuminate and comments that obscure. why vs what
  • Long Methods - short methods are easier to read, understand and trouble shoot
  • Long Parameter List - the more parameters the more complex
  • Duplicated Code - DRY, DRY, DRY
  • Conditional Complexity - large conditional logic blocks
  • Uncommunicative Name - does the method name succinctly describe what it does

Code-along 1-2 topics

Paired Practice

In your assigned pair (given by instructor):

  1. Checkout a refactoring branch for Person A’s project
  2. Work on refactoring Person A’s code snippet from their presentation for 20 minutes.
  3. Repeat steps 1 and 2 for Person B

Review

With your Quantified Self partner, discuss the following (15 minutes):

  • How your workshop pair approached refactoring
  • Your main takeaway from today’s workshop

Resources

Check out this compilation of refactoring techniques in JS.