Skip to content

Instantly share code, notes, and snippets.

@elle
Last active September 12, 2021 11:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elle/664f3f30271b1a0555fa to your computer and use it in GitHub Desktop.
Save elle/664f3f30271b1a0555fa to your computer and use it in GitHub Desktop.
Notes from Poodnyc 2015 workshop

Rules for Horizontal Refactoring

  • If you go red, undo
  • Only change one line at a time
  1. Find two strings that are the most alike
  2. Find the smallest difference
  3. Make the smallest change that make the tests pass

How to make a small change

  1. Parse: run code, check if errors
  2. Execute without using result
  3. Execute using the result
  4. Delete unused code
Is code open?
Y -> make change
N -> can I make it open?
     Y -> make change
     N -> Fix easy sin, and start over again, is code open?

Lessons from Day 1

  • Simple: don't be too clever, "drunk me doesn't understand"
  • Green Green Green: lean on green, don't fight red, avoid rabbit holes
  • Small easy steps: find most alike, fix the smallest sin, start with small steps instead of trying to fix big complex problems, fix easy things first to make the hard things easy
  • Dare to be boring: step by step refactoring recipe can seem so simple it will almost be boring
  • Don't abstract prematurely
  • Don't plan for unknown future
  • Meaningful variable names within the domain help with understanding the domain
  • It is almost always 90% maintenance / 10% new code
  • Terse is not better
  • Try to avoid procedural if/else flow

SOLID

  • SRP: Single Responsibility Principle
  • Open/Close
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

Lessons from Day 2

Know the code smell => Know the recipe to refactor

Examples of code smells:

  • Too many private methods is a code smell that there might be another object hiding in there
  • Primitive obsession
  • Data clumps
  • Duplication
  • Classes and methods that do too much
  • Methods that return different objects

Emergent design

Boring is better -> identify code shapes -> look for code smells -> principled refactoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment