refactor

Refactor code by applying design patterns and removing dead code.

6|8|Updated Apr 22, 2023
One-click install
npx skills add https://github.com/Ansteorra/KMP --skill refactor-ansteorra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/Ansteorra/KMP/tree/main/.github/skills/refactor
Command: npx skills add https://github.com/Ansteorra/KMP --skill refactor-ansteorra

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses code that is difficult to understand, maintain, or extend by systematically improving its structure, readability, and type safety without altering its external behavior.

Core Features & Use Cases

  • Code Smell Remediation: Identifies and fixes common issues like long methods, duplicated code, and primitive obsession.
  • Design Pattern Application: Introduces patterns like Strategy and Chain of Responsibility to improve flexibility and organization.
  • Type Safety Enhancement: Migrates code from untyped to strongly typed systems for increased robustness.
  • Use Case: You have a complex function that has grown over time and is now hard to debug. Use this Skill to break it down into smaller, more manageable, and testable functions, improving overall code health.

Quick Start

Use the refactor skill to improve the structure of the provided code snippet.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I fix long methods and nested conditionals to improve code maintainability?

To improve code maintainability, you can apply surgical refactoring techniques that break down long methods and simplify nested conditionals into smaller, more manageable, and testable functions without altering external behavior.

What is primitive obsession in code refactoring and how do I resolve it?

Primitive obsession is a code smell where primitives are overused for domain concepts. Refactoring resolves it by migrating untyped data to strongly typed systems, introducing design patterns, and enhancing type safety for increased robustness.

How do I remove duplicated code and large classes without changing program behavior?

You can remove duplicated code and large classes by applying the Golden Rules of Refactoring. This process systematically improves internal structure, readability, and organization while strictly preserving the original external program behavior.

When should I introduce design patterns like Strategy or Chain of Responsibility during refactoring?

Introduce design patterns like Strategy or Chain of Responsibility during refactoring when you need to improve code flexibility and organization, specifically to replace complex conditional logic with more maintainable structural designs.

Can refactoring help migrate untyped code to a strongly typed system?

Yes, refactoring can migrate untyped code to a strongly typed system. This enhancement directly increases type safety, removes dead code, and improves overall code health and robustness without changing external behavior.