code-simplification
Simplify code that works — remove speculative abstraction, dead flexibility, and needless indirection while keeping behaviour identical and verified…
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
Code Simplification Skill
Code accretes defensive complexity: abstractions for futures that never came, options nobody passes, indirection that once had a reason. AI-generated code arrives pre-accreted — interfaces with one implementer, config objects with nine unused knobs. Simplification is its own pass with its own rule: behaviour identical, verified; complexity removed, listed.
What This Skill Produces
- The simplified code — smaller, flatter, same behaviour
- A removal ledger: each simplification, why it was safe, and what future it forecloses (honestly)
- Verification evidence that behaviour held
What to Hunt (in order of payoff)
- Speculative generality — the interface with one implementation, the parameter always called with the same value, the config option no caller sets, the "pluggable" thing nothing plugs into. Rule: the future that justified it must be on a roadmap, not in an imagination. YAGNI is a removal warrant.
- Indirection without insulation — layers that only forward: the wrapper that calls one function, the factory returning one type, the event fired for one listener sitting next door. Each hop costs a reader a jump; collapse hops that don't isolate change.
- Dead and duplicate paths — unreachable branches, handled-nowhere flags, the local re-implementation of a utility that exists (
grepbefore believing anything is unique). - Cleverness taxing readers — the nested ternary, the reduce that should be a loop, the regex doing four jobs. Rewrite for the next reader; "fewer characters" is not "simpler".
- Flatten control flow — guard clauses over nested ifs; early returns over else-pyramids; splitting the function that needs a comment per section into functions named by those comments.
The Safety Discipline (what makes this different from vandalism)
- Behaviour-preserving means verified, not asserted: run the full relevant suite before AND after; if coverage is thin over the code being simplified, add the pinning test first — simplifying untested code is refactoring blind.
- One hunt-class per pass where the code is load-bearing (remove speculation, verify; collapse indirection, verify) — mirrors incremental-implementation's rule.
- Chesterton's fence check on anything weird:
git log/blamethe strange bit before deleting it. Some "needless" complexity is a bug fix wearing an odd shape — if the history shows a fix, keep it and comment WHY it's shaped that way instead. - Public surface needs a wider net: simplifying exported/shared code means checking callers across the codebase, not just the local file.
Output Format
Simplification: [target]
Verification: [suite/build run before → after: identical] · pinning tests added: [n or none-needed because…]
Removal ledger
| What was removed/flattened | Class | Why safe | Future foreclosed (honest) |
|---|---|---|---|
Kept deliberately: [the weird-but-load-bearing bits, with their Chesterton evidence]
Size: [LOC/complexity before → after]
Quality Checks
- [ ] Full verification ran before and after — identical behaviour, evidenced
- [ ] Thinly-tested code got pinning tests before simplification
- [ ] Every removal states the future it forecloses — "none" must be argued, not assumed
- [ ] Strange code was history-checked before deletion (Chesterton's fence)
- [ ] The result is simpler for a READER, not just shorter
Anti-Patterns
- [ ] Do not simplify and change behaviour in one pass — the moment behaviour shifts, this became a rewrite without a spec
- [ ] Do not delete weirdness without checking why it's weird — some of it is a production incident's scar tissue
- [ ] Do not confuse terse with simple — code golf raises the reading tax this skill exists to cut
- [ ] Do not remove flexibility that's actually on the roadmap — YAGNI applies to imagined futures, not planned ones
- [ ] Do not skip the ledger — invisible simplification is indistinguishable from unexplained deletion in review
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。
它属于哪个仓库
plugins/pm-method/skills/code-simplification/SKILL.md同一个仓库里的其他技能
同名技能的其他版本
有 3 个不同仓库或目录里都有叫 code-simplification 的技能。它们内容并不相同,别混用:
- mohitagw15856/pm-claude-skills — Simplify code that works — remove speculative abstraction, dead flexibility, and needless
- mohitagw15856/pm-claude-skills — Simplify code that works — remove speculative abstraction, dead flexibility, and needless