Class 6 - Refactoring & Pair Programming Flashcards
Refactoring
The process of restructuring code while not changing its original functionality
When does refactoring happen in the context of TDD?
First, developers need to add a test. Then, they need to write code to make the test pass. Only then can developers refactor code (make it clean)
Two Hats metaphor for refactoring
Programmers can choose between two “hats”: a refactoring “hat” and an adding functions “hat”. They can swap frequently between hats; however, they can only wear one hat at a time.
TDD Refactoring
The most common type of refactoring programmers use.
1. Write test
2. Make test work (focus just on adding a new functionality without worrying about code structure)
3. Refactor (concentrate on good design)
Litter-Pickup Refactoring
Cleaning up a messy area of the codebase
Camp Site Rule (Litter-Pickup Refactoring)
Always leave code better than when you found it
Comprehension Refactoring
Changing a piece of code to make it easier to understand for other developers. Easy to understand code is cheap to use and modify.
Preparatory Refactoring
Changing existing code to prepare the codebase for a new functionality you will add in the near future. This allows you to implement new features more efficiently than if you do not prepare for the new feature
Planned Refactoring
Scheduling refactoring as part of your team’s planned work (e.g. refactoring stories). Commonly used to fix larger pieces of problematic code that needed dedicated attention.
Long-Term Refactoring
Refactoring that spans multiple iterations over several months. Since all changes are refactoring, the codebase can remain in a working state even as new features are added. Examples include: replacing a large module, or changing your database persistence framework
When is it a bad idea to refactor your code?
If you do not believe you will recoup your investment later by quicker work later on
What is a common sign you need to refactor your codebase?
If your codebase is difficult to understand and modify, and it is slowing you down, that is a sign you need to refactor to improve your efficiency
Pair Programming
Two programmers working together on the same task
What are the benefits of pair programming?
- Knowledge sharing
- Reflection
- Keeping focus
- Code review “on-the-go”
- Two modes of thinking
- Collective code ownership
Reflection (Benefit of Pair Programming)
Pair programming encourages discussing instead of just thinking. Saying and explaining things out loud pushes us to reflect