code-refactoring
Structured patterns and techniques for improving code quality through safe, behavior-preserving refactoring.
- Covers common code smells including long methods, deeply nested conditionals, primitive obsession, and feature envy with before/after examples
- Provides core refactoring techniques: extract method, replace conditional with polymorphism, introduce parameter objects, and replace magic numbers with constants
- Emphasizes safe refactoring workflow: ensure test coverage first, make small focused changes, run tests after each step, and commit frequently
- Includes decision framework for when to refactor (before features, after tests pass, during code review) and when to avoid it (without tests, under tight deadlines, on code being replaced)
Code Refactoring
Refactoring Principles
When to Refactor
- Before adding new features (make change easy, then make easy change)
- After getting tests passing (red-green-refactor)
- When you see code smells
- During code review feedback
When NOT to Refactor
- Without tests covering the code
- Under tight deadlines with no safety net
- Code that will be replaced soon
- When you don't understand what the code does
Common Code Smells
Long Methods
More from skillcreatorai/ai-agent-skills
code-review
Automated code review for pull requests using specialized review patterns. Analyzes code for quality, security, performance, and best practices. Use when reviewing code changes, PRs, or doing code audits.
963backend-development
Backend API design, database architecture, microservices patterns, and test-driven development. Use for designing APIs, database schemas, or backend system architecture.
484expo-app-design
Build beautiful cross-platform mobile apps with Expo Router, NativeWind, and React Native.
361code-documentation
Writing effective code documentation - API docs, README files, inline comments, and technical guides. Use for documenting codebases, APIs, or writing developer guides.
333database-design
Database schema design, optimization, and migration patterns for PostgreSQL, MySQL, and NoSQL databases. Use for designing schemas, writing migrations, or optimizing queries.
323best-practices
>-
320