跳到正文
Skillpedia
通用编程15k · #10981

principle-minimize-reader-load

它能做什么

为智能体提供一条让代码便于人阅读的规则。适合因包装层、间接调用或共享状态而难以追踪代码的团队。

适用场景

  • ✓当代码难以从问题追踪到答案的时候。
  • ✓当某个包装层只有一个调用方,或某个适配器没有第二种用途的时候。
  • ✓当全局或可变状态使行为难以预测的时候。

技能链接

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-minimize-reader-load/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-minimize-reader-load/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“这个模块有五层包装,做的都是同样的事情。请把它简化,让新开发者能够看懂。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会统计从问题到答案之间的层数,以及读者必须追踪的隐藏状态。它会合并那些成本高于收益的包装层,优先使用纯函数,并把状态的作用范围缩小到最小的有用范围。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Minimize Reader Load

Maintainability is the work a reader must do to understand code. Track two axes: layers to trace (indirections between the question and the answer) and state to hold (hidden or mutable context the reader must keep in their head). LOC, cyclomatic complexity, and "clean architecture" are proxies. Reader load is the thing that matters. The two axes are independent. A flat file with 50 globals can be as hard to reason about as a 6-layer adapter stack. Guard both. This is the human analog of Guard the Context Window. Working memory is finite for readers too.

  • Collapse layers that cost more than they save: wrappers with one caller, adapters with no second implementation, speculative indirection that was never needed. Inline them.
  • Make adjacent layers change the abstraction. A layer that repeats the same methods and arguments adds reader load without compression. Collapse pass-through layers.
  • Demand interface compression. A broad interface that hides little complexity makes readers learn both the surface and the implementation. Prefer boundaries that hide meaningful decisions.
  • Shrink state scope: prefer pure functions (returns over mutations), locals over fields, fields over module state, and module state over globals. Derive instead of sync.
  • Name the invariant at the boundary, not in every consumer, so the reader learns it once.
  • Before adding a layer or a piece of state, ask: does it reduce reader load elsewhere by at least as much?

The test: can a new reader answer "where does X come from?" and "what can change X?" in under 30 seconds? If not, cut layers or cut state.

常见问题

代码行数是目标吗?

不是。该技能认为,读者付出的理解成本比代码行数或复杂度评分更重要。

什么时候应该删除一层?

当它增加了读者的理解负担,却没有真正的收益时,例如只有一个调用方的包装层。

状态怎么办?

优先使用纯函数和局部变量,而不是字段、模块状态和全局变量。

详情

作者的原始描述

Apply when reviewing or shaping code that's hard to trace. Count layers between question and answer, and hidden state in the reader's head; collapse one-caller wrappers and shrink mutable scope.

repo: cursor/plugins

热度

GitHub 星标
15k
排名
#10981
许可证
—
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能