Skip to content
cognitive-load logo

認知負擔評估工具

cognitive-load

認知負擔評估工具。作為決策樹、代理人、Code Review 的基本參考標準。用於: (1) 任務複雜度評估, (2) 代理人升級判斷, (3) 任務拆分建議, (4) 程式碼品質評估

SKILL.md

Full skill instructions

認知負擔評估工具

核心理念

所有程式碼設計原則的終極目標:降低閱讀者的認知負擔

認知負擔是指閱讀者在理解程式碼時需要同時記住的資訊量。當認知負擔超過人類工作記憶的容量(約 7 個項目),理解和維護程式碼就會變得困難。


量化標準快速參考

任務複雜度閾值

指標低複雜度中複雜度高複雜度(需拆分)
變數狀態數1-34-5> 5
修改檔案數1-34-5> 5
架構層級數12> 2
依賴模組數0-12-3> 3
呼叫追蹤層1-23> 3

代理人升級閾值

指標閾值行動
需追蹤概念數> 7升級到 PM
無法 5 分鐘理解是升級到 PM
跨 2+ 架構層是請求拆分或協作

並行派發判斷

條件可並行需序列
架構層級同一層跨層
邏輯依賴無有
操作類型重命名/格式化設計變更

認知負擔的來源

1. 變數狀態追蹤

每個變數都是閱讀者需要「記住」的項目:

情況認知負擔建議
變數數 <= 3低維持
變數數 4-5中考慮重構
變數數 > 5高必須拆分

2. 呼叫層級追蹤

追蹤呼叫鏈需要「堆疊」記憶:

層級認知負擔建議
1-2 層低維持
3 層中考慮扁平化
> 3 層高必須重構

3. 命名品質

不佳的命名增加「翻譯」負擔:

問題範例解決
縮寫不明btn, mgr, idxbutton, manager, index
含義模糊data, info, value具體化:userData, bookInfo
型別前綴strName, intCount直接用 name, count

4. 條件分支複雜度

每個分支都是需要考慮的「路徑」:

分支數認知負擔建議
1-2低維持
3-4中考慮策略模式
> 4高必須重構

降低認知負擔的原則

原則 1:單一責任

一個函式只做一件事,讓讀者只需理解一個概念

檢查問題:「這個函式做了幾件事?」

原則 2:自說明命名

名稱本身就是文件,讓讀者不需要額外資訊

檢查問題:「不看實作,能從名稱理解功能嗎?」

原則 3:避免副作用

函式的行為應該可預測,讓讀者不需要追蹤隱藏狀態

檢查問題:「這個函式有沒有修改輸入以外的東西?」

原則 4:扁平化結構

減少巢狀,讓讀者不需要追蹤深層上下文

檢查問題:「最深的巢狀層級是多少?(應 <= 3)」

原則 5:資訊就近原則

相關的資訊應該放在一起,讓讀者不需要跳轉尋找

檢查問題:「理解這段程式碼需要跳到幾個地方?」


自我檢查清單

任務開始前

  • 我需要同時記住多少個概念?(應 < 7)
  • 我需要閱讀多少個檔案才能完成?(應 < 5)
  • 我能用一句話說明這個任務嗎?
  • 5 分鐘後我還記得任務目標嗎?

程式碼撰寫時

  • 這個函式需要追蹤幾個變數?(應 < 5)
  • 讀者能在當下理解這段程式碼嗎?
  • 函式名稱說明「做什麼」而非「怎麼做」?
  • 巢狀層級是否超過 3 層?

Code Review 時

  • 新程式碼是否增加了模組的複雜度?
  • 有沒有更簡單的方式達成同樣目的?
  • 命名是否清晰自說明?
  • 是否需要額外註解才能理解?(應該不需要)

與其他方法論的關係

方法論認知負擔視角
DRY減少重複 = 減少需要記憶的版本
SOLID每個原則都在降低特定類型的認知負擔
Clean Code可讀性 = 低認知負擔
自然語言程式設計讓程式碼像閱讀文章一樣自然

使用方式

評估任務複雜度

# 在開始任務前,快速評估
# 回答以下問題:

1. 這個任務需要修改幾個檔案?
2. 需要追蹤幾個變數狀態?
3. 跨越幾個架構層級?
4. 依賴幾個其他模組?

# 如果任一項超過閾值,考慮拆分任務

程式碼品質評估

# 在 Code Review 時,檢查:

1. 函式長度(應 5-15 行)
2. 參數數量(應 <= 3)
3. 巢狀深度(應 <= 3)
4. 變數數量(應 < 5)

相關文件


Last Updated: 2026-01-28 Version: 1.1.0

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View