praetorian-inc/public-workflows/adhering-to-dry

Claude Code and agent skill by praetorian-inc/public-workflows

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when writing new code or eliminating code duplication through DRY refactoring - applies Rule of Three and extract patterns

Install

npx vskill@latest install praetorian-inc/public-workflows/adhering-to-dry

SKILL.md

DRY Refactoring

Process

  1. Identify - Exact copies, similar patterns, parallel hierarchies, naming patterns (data1/data2, handleXClick)
  2. Analyze - Coupling, cohesion, frequency (Rule of Three: wait for 3+ occurrences), volatility
  3. Refactor - Choose technique below, extract incrementally, test after each step

Techniques

Extract Function - Same logic in multiple places

ts
getFullName(user: User) => `${user.firstName} ${user.lastName}`

Extract Variable - Repeated expression

ts
const isWorkingAge = user.age >= 18 && user.age < 65;

Parameterize - Code differs only in values

ts
validateField(value: string, pattern: RegExp)
// Use: validateField(email, EMAIL_REGEX)

Extract Class - Related functions scattered

ts
class UserRewards {
calculateDiscount(user, amount) {}
getLoyaltyPoints(user) {}
}

Polymorphism - Repeated switch/if-else

ts
interface PaymentProcessor {
process(amount: number): void;
}
class CreditProcessor implements PaymentProcessor {}

Strategy Pattern - Duplicated algorithm selection

ts
const strategies = { date: byDate, name: byName };
items.sort(strategies[sortType] ?? byPriority);

Pull Up Method - Identical methods in subclasses

ts
class BaseUser {
getDisplayName() {}
}
class AdminUser extends BaseUser {}

Detection

Code Smells: Numbered variables (data1, data2), parallel function names (handleXClick), near-identical code differing only in constants, repeated validation/error handling, parallel class structures, large switches in multiple places, repeated null checks, magic numbers

Rule of Three: Wait for 3+ occurrences before abstracting

When NOT to DRY

  • Coincidental similarity - Different domains/business rules that happen to look alike (will diverge)
  • Premature abstraction - Pattern isn't clear yet; early abstraction often guesses wrong
  • Single use - Appears 1-2 times, unlikely to grow
  • Test clarity - Readable test setup beats DRY
  • Over-engineering - Don't abstract every 2-3 line similarity

Patterns

  • Configuration over code - Data structures eliminate conditionals
  • Template Method - Base defines skeleton, subclasses vary steps
  • Dependency Injection - Parameterize dependencies
  • Builder - Complex object construction

Best Practices

  • Refactor after green tests
  • One refactoring at a time
  • Commit frequently
  • Name for intent not implementation
  • Consider performance
  • Review abstractions with team

Related Techniques

  • Balance DRY against YAGNI — don't abstract speculative features before they exist.
  • Balance DRY against simplicity — avoid over-engineering; the simplest version that removes the duplication wins.
  • Apply DRY during the refactor step after tests are green, so changes stay safe.
  • Before writing new code, search the codebase for an existing implementation to reuse rather than duplicate.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/praetorian-inc/public-workflows/adhering-to-dry/badge)](https://verified-skill.com/skills/praetorian-inc/public-workflows/adhering-to-dry)

Something wrong with this skill or its page? Tell us.