Refactoring

The classic definition (from Martin Fowler) is that refactoring is changing the design of existing code without changing its observable behavior.

Why is this desirable? Because different designs are easy to extend in different ways, they have different performance, they vary inn ease of maintenance, etc. By keeping behavior constant, our software still “does” the same thing while we work one other dimensions.

Start Here

Numbers represented as a grid (part of the Refactoring Grid)

Refactoring, A Whole-Team Guide” – This article gives an overview of refactoring, without going deep into the programmer side of things.

Refactoring, A Whole-Team Guide – One-page summary of the article.

Refactoring: An Example, Extended” – A walkthrough of a refactoring.

Refactoring Presentation (PPT)” – Very old presentation that introduces refactoring.

Refactoring Challenge – The Amazing Maze” – Take a crazy BASIC program that’s a bunch of if’s, gotos, and simple assignments, with the goal of refactoring to an algorithm that makes sense. (It’s not an ideal exercise; you spend a lot of time turning unstructured code into something you can make sense of.)

Refactoring Grid” – A physical analogy to the “rules” of refactoring.

Principles

Extract Method showing a test client

Data Flow Analysis for Refactoring

Harmony and Identity: Generalizing Code” – on Industrial Logic’s blog.

Home-Grown Refactorings – Be Careful!

The Impact of Refactoring on Tests” – originally published at InformIT.com.

Isolate-Improve-Inline: The 3-I Refactoring Tactic” – on Industrial Logic’s blog.

Limits of Refactoring: What IS Behavior?” – “Observable behavior” is a subtle thing.

Local Refactorings” – Focus on refactorings with local impact.

Refactoring and Generalization in TDD” – originally published in Better Software.

Refactoring and Programming-Language Semantics” –

Refactoring: Forcing the Right Extract Method

Refactorings Require New Tests

Scratch Refactoring” – Sometimes it’s faster to do it twice.

Speculative Generality

Subjunctive Programming

Transliterating Old-School BASIC

When Software Smells Bad” – with Kevin Rutherford. Originally published in Better Software.

Refactoring Catalog

Instead of calling a fixed function, pass it in and call it indirectly

Extracting Parameterized Unit Tests

Loop Unrolling: While ⇒ If-While

Hazardous Code Death Spiral (and a Cure)” – on Industrial Logic’s blog.

The Nested-If Swap Refactoring” – on Industrial Logic’s blog.

Refactor: Change Signature on a Protocol [Interface]

Refactor: Duplicate and Customize

Refactor: Parallel Arrays to Array of Objects

Refactor Template Method to Strategy

Refactoring: Pull Common Code from Conditional

Refactoring: Replace Method with Method Object

Refactorings from Writing Efficient Programs

The Swap Statement Refactoring” – on Industrial Logic’s blog.

Wrapping a Type, All the Way

Refactoring Catalog – Functional and Lambdas

Lambda for Control Structures, a Refactoring

Lambda to Reduce Coupling

Nested Loops to Functional Pipeline

Refactoring: Extract Local Lambda

Swift Refactorings

Split a class into a class + extension

These are focused on some syntax found in Swift; they may apply to other languages as well. (For example, C# has extension classes.)

Refactoring in Swift

Divide Class into Class + Extension (Swift Refactoring)

Extract Protocol Refactoring (Swift) – Elevate Common Behavior

My Books

Refactoring Workbook by Bill Wake

Refactoring in Ruby – InformIT Interview

Refactoring Workbook

Review – Refactoring Workbook

Reviews

Review – Refactoring to Patterns” – by Joshua Kerievsky.

Review – Working Effectively with Legacy Code” – by Michael Feathers.

Review – Refactoring” – by Martin Fowler.

Resources on Refactoring

Resources on Refactoring” – links to others’ material on refactoring.

Smell to Refactoring Cheat Sheet – Industrial Logic

Refactoring Thumbnails” – from Sven Gorts.