1.2 KiB
1.2 KiB
Simplify Code Appendix
Extended examples and pattern notes live here to keep SKILL.md lean.
Pattern Details
- Extract Method: split large functions into named units.
- Guard Clauses: replace deep nesting with early returns.
- Decompose Conditional: extract complex conditions and branches.
- Replace Magic Numbers: promote literals to named constants.
- Rename for Clarity: explicit, searchable, domain terms.
- Remove Dead Code: delete commented or unreachable code.
- Parameter Object: group related arguments when signatures are too long.
Language-Specific Reminders
- JavaScript/TypeScript: prefer
const, pure helpers, and array transforms. - Python: prefer clear names, type hints where useful, and small functions.
- Java/C#: prefer focused classes and guard clauses.
- Go: keep functions small, explicit error paths.
Anti-Patterns
- Large-bang rewrites
- Behavioral changes without explicit requirement
- Premature abstractions
- Clever code at cost of readability
Suggested Validation Loop
- Build/test baseline
- Apply one simplification pass
- Re-run build/tests
- Repeat
If a pass introduces failures, stop and document in simplification-report.md.