Class 6 - Refactoring & Pair Programming Flashcards

1
Q

Refactoring

A

The process of restructuring code while not changing its original functionality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When does refactoring happen in the context of TDD?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Two Hats metaphor for refactoring

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

TDD Refactoring

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Litter-Pickup Refactoring

A

Cleaning up a messy area of the codebase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Camp Site Rule (Litter-Pickup Refactoring)

A

Always leave code better than when you found it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Comprehension Refactoring

A

Changing a piece of code to make it easier to understand for other developers. Easy to understand code is cheap to use and modify.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Preparatory Refactoring

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Planned Refactoring

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Long-Term Refactoring

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

When is it a bad idea to refactor your code?

A

If you do not believe you will recoup your investment later by quicker work later on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a common sign you need to refactor your codebase?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pair Programming

A

Two programmers working together on the same task

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the benefits of pair programming?

A
  • Knowledge sharing
  • Reflection
  • Keeping focus
  • Code review “on-the-go”
  • Two modes of thinking
  • Collective code ownership
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Reflection (Benefit of Pair Programming)

A

Pair programming encourages discussing instead of just thinking. Saying and explaining things out loud pushes us to reflect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Keeping focus (Benefit of Pair Programming)

A

It is easier to get distracted when working solo. Working in a pair can prevent you from spending too much time on something that is not important.

17
Q

Knowledge Sharing (Benefit of Pair Programming)

A

People working together share knowledge to solve a problem. Two minds discussing a problem increases the likelihood a solution will be found.

18
Q

Code review “on-the-go” (Benefit of Pair Programming)

A

Another person reading the code increases the chances that an error/typo will be caught. Refactoring is more natural with two different perspectives

19
Q

Two modes of thinking (Benefit of Pair Programming)

A
  • Driver (person coding): Brain in “tactical” mode
  • Navigator: Thinks more strategically
20
Q

Collective code ownership (Benefit of Pair Programming)

A

Pair programming ensures that every line of code was touched or seen by at least 2 people. Result: Anyone on the team feels comfortable changing code almost anywhere.

21
Q

What are the different pairing styles in pair programming?

A
  • Driver and Navigator
  • Ping Pong
  • Strong-Style Pairing
22
Q

Driver and Navigator

A

Driver (writes code): Talks through what they are doing, thinks about task at hand
Navigator (reviews code): Gives directions, shares thoughts, and thinks about large issues/bugs/next steps

23
Q

Ping Pong

A
  • Person A writes a failing test
  • Person B writes the implementation to make it pass
  • Person B writes a failing test (for some other feature)
  • Person A writes the implementation to make it pass
    (Repeat cycle above as necessary)
24
Q

Strong-Style Pairing

A

Similar to the “Driver and Navigator” style with more defined roles:
- Navigator: Person with more experience
- Driver: Novice (with the language/framework/codebase)

Eventually, it should be possible to switch roles (since knowledge transfers from navigator to driver)