dry-refactor

Eliminate duplicate code using DRY refactoring techniques with test validation.

82|12|Updated Aug 31, 2025
One-click install
npx skills add https://github.com/PaulRBerg/dot-claude --skill dry-refactor
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dry-refactor
Source: https://github.com/PaulRBerg/dot-claude/tree/main/skills/dry-refactor
Command: npx skills add https://github.com/PaulRBerg/dot-claude --skill dry-refactor

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill guides developers in identifying and eliminating code duplication (DRY - Don't Repeat Yourself), leading to cleaner, more maintainable, and less error-prone software.

Core Features & Use Cases

  • Duplication Detection: Helps identify code smells like numbered variables, parallel function names, and near-identical logic.
  • Refactoring Techniques: Provides a catalog of techniques such as Extract Function, Parameterize, Polymorphism, and Strategy Pattern.
  • Strategic Guidance: Advises on when to refactor (Rule of Three) and, crucially, when not to abstract (coincidental similarity, premature abstraction).
  • Use Case: When you notice similar blocks of code appearing multiple times in your project, use this skill to systematically apply refactoring techniques to consolidate logic and improve code structure.

Quick Start

To refactor duplicate logic, identify the repeated code, analyze its coupling, then apply a technique like 'Extract Function' to create a reusable abstraction.

Frequently Asked Questions about dry-refactor

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

FAQPage Schema
How do I identify and eliminate duplicate code in my codebase?

Eliminate duplicate code by identifying repeated logic patterns—like numbered variables (data1, data2) or parallel function names—then apply refactoring techniques such as Extract Function or Extract Variable to consolidate shared behavior into reusable abstractions.

What refactoring techniques should I use to reduce code duplication?

Core techniques include Extract Function, Extract Variable, Parameterize, Extract Class, Polymorphism, and Strategy Pattern. Choose based on coupling and scope; Extract Function works for isolated blocks, while Polymorphism suits diverging behavior across classes.

When should I refactor duplicate code versus leaving it as is?

Apply the Rule of Three: refactor when identical logic appears three or more times. Avoid premature abstraction for coincidental similarities or one-off duplications; refactor incrementally and validate with tests after each step.

How do I detect code smells that indicate duplication?

Watch for numbered variables (data1, data2), similarly named functions (handleXClick patterns), magic numbers, and parallel logic blocks. These smells signal opportunities to extract shared behavior and improve maintainability.

Can I refactor duplicate code without breaking existing functionality?

Yes. Extract incrementally—apply one refactoring technique at a time, then validate with tests after each step. This staged approach catches issues early and ensures your changes maintain existing behavior.