applying-code-principles
Fundamental software principles - SOLID, DRY, Occam's Razor, Miller's Law, YAGNI. Triggers: 原則, シンプル, 複雑, アーキテクチャ, リファクタリング, 保守性, コード品質, design pattern, best practice, clean code
When & Why to Use This Skill
This Claude skill automates the application of fundamental software engineering principles such as SOLID, DRY, YAGNI, and Occam's Razor. It helps developers maintain high code quality and optimal architecture by providing project-specific thresholds for complexity, ensuring long-term maintainability and reducing technical debt through systematic refactoring guidance and clean code practices.
Use Cases
- Architectural Code Reviews: Automatically evaluate pull requests against SOLID and DRY principles to ensure modularity and minimize logic duplication.
- Complexity Management: Apply Miller's Law to identify and refactor overly complex functions or classes that exceed cognitive load limits (e.g., more than 7 arguments or 9 methods).
- Preventing Over-engineering: Use YAGNI and Occam's Razor thresholds to challenge the necessity of new features or complex abstractions before they are implemented.
- Refactoring Strategy: Provide a prioritized roadmap for cleaning up legacy code based on established safety, simplicity, and maintainability hierarchies.
- Design Pattern Validation: Ensure that new interfaces and abstractions are only introduced when justified by multiple implementations, preventing 'interface bloat'.
| name | applying-code-principles |
|---|---|
| description | > |
| Triggers | 原則, シンプル, 複雑, アーキテクチャ, リファクタリング, 保守性, コード品質, |
| allowed-tools | Read, Grep, Glob |
Code Principles
Claude knows all principles. This file defines project-specific thresholds and priority.
Priority Order
When principles conflict:
- Safety First - Security, data integrity
- YAGNI - Don't build what you don't need
- Occam's Razor - Simplest solution
- SOLID - For complex systems
- DRY - Eliminate duplication (not at cost of clarity)
- Miller's Law - Respect 7±2 cognitive limit
Quick Decision Questions
- "Is there a simpler way?" (Occam's Razor)
- "Understandable in <1 min?" (Miller's Law)
- "Duplicating knowledge?" (DRY)
- "Needed now?" (YAGNI)
- "Single reason to change?" (SOLID/SRP)
Thresholds
Miller's Law
| Target | Ideal | Max | Limit |
|---|---|---|---|
| Function args | 3 | 5 | 7 |
| Class methods | 5 | 7 | 9 |
| Conditionals | 3 | 5 | 7 |
DRY
- Rule of Three: Abstract on 3rd duplication
SOLID
- Create interface only when 2nd implementation appears
- No single-implementation interfaces
YAGNI
Before adding, confirm:
- Problem exists now? → No = don't build
- Failed in production? → No = no error handling yet
- User requested? → No = no feature yet
- Measured evidence? → No = no optimization yet