# Code Simpler

> 코드 단순화, 복잡도 감소, 심플리파이, 가독성, KISS, 중첩 제거 - Simplifies overly complex code by reducing nesting, cyclomatic complexity, and unnecessary abstractions. Use when code exceeds complexity limits (nesting >3, function >50 lines) or after insight/review reports flag complexity. Do NOT use for full code reviews (use code-reviewer) or dead code removal (use refactor-cleaner).

- Skill: `aimskr/code-simpler` (Agent Skill)
- Install (CLI): `npx skillmds@latest add aimskr/code-simpler`
- Raw SKILL.md: https://api.skillmd.com/api/skills/aimskr/code-simpler/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: aimskr (https://skillmd.com/u/aimskr)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/aimskr/code-simpler

---


# Code Simpler - Complexity Reducer

Simplify overly complex code while preserving correctness.

## When to Use

- Insight 리포트에서 복잡도 지적이 나왔을 때
- 중첩이 깊은 코드 (3단계 이상)
- 함수가 50줄을 초과할 때
- 불필요한 추상화가 감지될 때
- 조건문이 과도하게 복잡할 때

## Simplification Techniques

### 1. Early Return (Guard Clause)

```
// Before: deeply nested
function process(data) {
  if (data) {
    if (data.isValid) {
      if (data.items.length > 0) {
        // actual logic
      }
    }
  }
}

// After: flat
function process(data) {
  if (!data) return;
  if (!data.isValid) return;
  if (data.items.length === 0) return;
  // actual logic
}
```

### 2. Extract Method (Long Functions)

Split when a function does more than one thing:
- Each function = one responsibility
- Name describes WHAT, not HOW
- Max 50 lines per function

### 3. Remove Unnecessary Abstraction

```
// Before: premature abstraction
class UserValidatorFactory {
  create(type) { return new UserValidator(type); }
}

// After: direct usage (if only one validator exists)
function validateUser(user) { ... }
```

### 4. Simplify Conditionals

```
// Before: complex boolean
if (user.age >= 18 && user.hasLicense && !user.isBanned && user.country === 'KR')

// After: named condition
const canDrive = user.age >= 18 && user.hasLicense && !user.isBanned;
const isKorean = user.country === 'KR';
if (canDrive && isKorean)
```

### 5. Replace Loop with Declarative

```
// Before: imperative
const results = [];
for (const item of items) {
  if (item.active) {
    results.push(item.name);
  }
}

// After: declarative
const results = items.filter(i => i.active).map(i => i.name);
```

### 6. Flatten Callback Hell

Replace nested callbacks/promises with async/await or pipeline.

## Process

```
1. Identify complexity (insight report or manual scan)
   ↓
2. Measure: nesting depth, function length, cyclomatic complexity
   ↓
3. Apply simplification technique (one at a time)
   ↓
4. Verify: behavior unchanged, tests still pass
   ↓
5. Repeat until within limits
```

## Complexity Limits

| Metric | Limit | Action |
|--------|-------|--------|
| Nesting depth | 3 levels | Apply early return |
| Function length | 50 lines | Extract method |
| Cyclomatic complexity | 10 | Split into smaller functions |
| File length | 200 lines | Split into modules |
| Parameters | 4 | Use object parameter |

## Principles

1. **One change at a time** - simplify incrementally
2. **Preserve behavior** - never change what the code does
3. **Verify with tests** - run tests after each simplification
4. **Don't over-simplify** - 3 similar lines > premature abstraction
5. **KISS** - the simplest correct solution is the best

## 문서화 (작업 완료 후 자동 실행)

작업 완료 시 `auto-documenter`를 호출하여 프로젝트 문서를 업데이트한다.

## Completion

모든 복잡도 지표가 한도 이내이고 테스트가 통과하면 완료.

## Troubleshooting

**Simplification breaks tests**: Revert immediately. The simplification changed behavior, not just structure. Re-analyze before retrying.
**Unclear if abstraction is "unnecessary"**: Check usage count. If used once → likely unnecessary. If used 3+ times → keep it.
**Team disagrees on complexity threshold**: Defer to project’s existing conventions. If none exist, propose thresholds and get team consensus before applying.

