refactoring

Apply Martin Fowler's behavior-preserving transformations to refactor code safely.

6|Updated Dec 28, 2023
One-click install
npx skills add https://github.com/staticWagomU/dotfiles --skill refactoring-staticwagomu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring
Source: https://github.com/staticWagomU/dotfiles/tree/main/config/claude/skills/refactoring
Command: npx skills add https://github.com/staticWagomU/dotfiles --skill refactoring-staticwagomu

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactoring is essential to improve code structure and readability without changing external behavior, enabling safer evolution of a codebase.

Core Features & Use Cases

  • Behavior-preserving transformations: extract method, rename for clarity, move code between modules, and extract classes to reduce duplication and improve modularity.
  • Guided TDD-aligned workflow: identify code smells (duplication, long methods, feature envy), select an appropriate pattern from Fowler's catalog, and apply changes incrementally with tests as a safety net.
  • Structural improvements before behavioral changes: makes future changes easier and reduces risk by maintaining observable behavior while reorganizing code.

Quick Start

Start by selecting a single smell in a small scope, apply one validated refactor step, then run the test suite to ensure behavior remains unchanged.

Frequently Asked Questions about refactoring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing its external behavior?

To refactor code without changing behavior, apply Martin Fowler's behavior-preserving transformations like extract method or rename for clarity. You must validate changes incrementally using tests as a safety net to ensure observable behavior remains unchanged.

When should I use behavior-preserving refactoring during a TDD workflow?

Use behavior-preserving refactoring during the TDD refactor phase after tests pass. It helps eliminate duplication, long methods, and feature envy by applying structured transformations while maintaining the green test state.

What is the best way to fix code smells like feature envy and long methods?

The best way to fix code smells like feature envy and long methods is selecting an appropriate pattern from Martin Fowler's catalog and applying changes incrementally. Extract methods or move code between modules to improve modularity and reduce duplication.

Do I need a test suite to safely apply code refactoring patterns?

Yes, you need a test suite to safely apply code refactoring patterns. Tests act as a non-functional safeguard and validation mechanism, ensuring that behavior-preserving transformations do not alter the public behavior of your codebase.

Can I extract classes and move code between modules to improve maintainability?

Yes, you can extract classes and move code between modules to improve maintainability. These behavior-preserving transformations reduce duplication and improve modularity by reorganizing code structure before implementing any behavioral changes.

Why does refactoring code before adding new features reduce risk?

Refactoring code before adding new features reduces risk by making future changes easier through structural improvements. Maintaining observable behavior while reorganizing code ensures the codebase evolves safely without introducing regressions.