返回 Skill 列表
extension
分类: 开发与工程无需 API Key

code-minimization

遵循YAGNI原则编写最少必要的代码,以防止臃肿和过度设计。在实现功能时使用此原则,以保持代码库精简,并避免过早优化或推测性功能。

person作者: jakexiaohubgithub

Code Minimization

Instructions

Write minimum code

Implement what's needed NOW, not what MIGHT be needed.

Avoid:

  • Premature optimization
  • Speculative features
  • Over-abstraction
  • Unnecessary complexity

YAGNI principle

You Aren't Gonna Need It

Example

<!-- CUSTOMIZE: Replace with {{MAIN_TECH_STACK}}-appropriate examples -->

Python Example

# ❌ Over-engineered
class ValidatorFactory:
    def create(self, type):
        if type == 'basic': return BasicValidator()
        elif type == 'advanced': return AdvancedValidator()
        # 10 more types... (only use BasicValidator!)

# ✅ Minimal
class EntityValidator:
    def validate(self, entity):
        return entity.required_field is not None

JavaScript/Node.js Example

// ❌ Over-engineered
class ValidatorFactory {
    create(type) {
        if (type === 'basic') return new BasicValidator();
        else if (type === 'advanced') return new AdvancedValidator();
        // 10 more types... (only use BasicValidator!)
    }
}

// ✅ Minimal
class EntityValidator {
    validate(entity) {
        return entity.requiredField !== null && entity.requiredField !== undefined;
    }
}

Go Example

// ❌ Over-engineered
type ValidatorFactory struct{}

func (f *ValidatorFactory) Create(validatorType string) Validator {
    switch validatorType {
    case "basic":
        return &BasicValidator{}
    case "advanced":
        return &AdvancedValidator{}
    // 10 more types... (only use BasicValidator!)
    }
    return nil
}

// ✅ Minimal
type EntityValidator struct{}

func (v *EntityValidator) Validate(entity *Entity) bool {
    return entity.RequiredField != ""
}

Guidelines

Do: Solve current requirements simply Don't: Add "maybe later" features


For detailed patterns, see reference.md For more examples, see examples.md