Code Complexity Reduction

D

Daniel Okoye

@daniel-okoye

·

Reduce code complexity by reasoning through refactoring approaches.

99 copies0 forks
Reduce complexity of this code step by step.

Complex code:
{{complex_code}}

Complexity metrics:
- Cyclomatic complexity: {{cyclomatic}}
- Cognitive complexity: {{cognitive}}
- Lines of code: {{loc}}

Think through systematically:

1. SMELL IDENTIFICATION: What code smells are present?

2. RESPONSIBILITY ANALYSIS: Does this code do too many things?

3. CONTROL FLOW: Can nested conditionals be simplified?

4. EXTRACTION: What methods or classes should be extracted?

5. POLYMORPHISM: Can conditionals be replaced with polymorphism?

6. EARLY RETURNS: Can guard clauses reduce nesting?

7. NAMING: Do names clearly express intent?

8. DUPLICATION: Is there hidden duplication?

9. TESTING: Will refactoring improve testability?

10. REFACTORING PLAN: Ordered sequence of refactoring steps.

11. EXPECTED IMPROVEMENT: Target complexity after refactoring.

Details

Category

Coding

Use Cases

Code refactoring guidanceComplexity reduction planningCode quality improvement

Works Best With

claude-opus-4.5gpt-5.2gemini-2.0-flash
Created Updated Shared

Create your own prompt vault and start sharing