Skip to content

Commit

Permalink
split loop learning hour and refactoring description
Browse files Browse the repository at this point in the history
  • Loading branch information
emilybache committed Dec 11, 2024
1 parent 9802199 commit 2e190b8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _code_smells/divergent_change.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: code_smell
title: Divergent Change
name: divergent_change
source: Martin Fowler
---

Expand All @@ -9,4 +10,4 @@ This is not so much something you can see from reading the code, rather it's som

This code smell does actually stem from a design problem though. Divergent change is a sign that module or class is not cohesive enough.

Note: this is similar but different to [Shotgun Surgery](shotgun_surgery.html) which is a sign your design has a coupling problem.
Note: this is similar but different to [Shotgun Surgery](shotgun_surgery.html) which is a sign your design has a coupling problem.
1 change: 1 addition & 0 deletions _code_smells/loop.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
layout: code_smell
title: Loops
name: loops
source: Martin Fowler
---

Expand Down
13 changes: 13 additions & 0 deletions _learning_hours/refactoring/split_loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
theme: refactoring
title: Split Loop
name: split_loop
code_smell: divergent_change
kata: theatrical_players
difficulty: 3
author: emilybache
---

# Split Loop

This learning hour is still being developed.
32 changes: 32 additions & 0 deletions _refactorings/split_loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: refactoring
title: Split Loop
source: Emily Bache
source_url: https://refactoring.com/catalog/splitLoop.html
code_smells: loops,divergent_change
learning_hours: split_loop
---

# Split Loop
This is one of the refactorings in Martin Fowler's book. Often this refactoring opens up for a lot of other useful changes.

## Examine
A loop is of itself a code smell, but even more so when it does more than one thing, which implies Diverent Change.

## Prepare
Identify the loop you want to split, and in particular which lines within it that hang together and need to be separated from the others. You may need to do some 'introduce variable' refactorings and 'slide statement' refactorings to gather all the relevant parts of the loop together.

## Implement

* Tests all passing
* Select the whole loop and duplicate it.
* In one copy of the loop, delete everything except the lines you want to split.
* In the other copy of the loop, delete only the lines you want to split.
* Tests all passing.

## Clear
Double-check the remaining logic in the original loop makes sense and that you didn't delete too much by mistake.

## Follow up
Often you now want to extract a method for the new loop, or turn it into a pipeline.
You might identify another part of the old loop that also needs to be split.
8 changes: 8 additions & 0 deletions newsletter_and_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
layout: tdd_guide
title: Newsletter
---

# Newsletter and Free Guide to TDD Heuristics

Please use the form below to sign up for our newsletter and receive your free guide.

0 comments on commit 2e190b8

Please sign in to comment.