xiaohongshu
xiaohongshu
cognitive-load
認知負擔評估工具。作為決策樹、代理人、Code Review 的基本參考標準。用於: (1) 任務複雜度評估, (2) 代理人升級判斷, (3) 任務拆分建議, (4) 程式碼品質評估
Full skill instructions
所有程式碼設計原則的終極目標:降低閱讀者的認知負擔
認知負擔是指閱讀者在理解程式碼時需要同時記住的資訊量。當認知負擔超過人類工作記憶的容量(約 7 個項目),理解和維護程式碼就會變得困難。
| 指標 | 低複雜度 | 中複雜度 | 高複雜度(需拆分) |
|---|---|---|---|
| 變數狀態數 | 1-3 | 4-5 | > 5 |
| 修改檔案數 | 1-3 | 4-5 | > 5 |
| 架構層級數 | 1 | 2 | > 2 |
| 依賴模組數 | 0-1 | 2-3 | > 3 |
| 呼叫追蹤層 | 1-2 | 3 | > 3 |
| 指標 | 閾值 | 行動 |
|---|---|---|
| 需追蹤概念數 | > 7 | 升級到 PM |
| 無法 5 分鐘理解 | 是 | 升級到 PM |
| 跨 2+ 架構層 | 是 | 請求拆分或協作 |
| 條件 | 可並行 | 需序列 |
|---|---|---|
| 架構層級 | 同一層 | 跨層 |
| 邏輯依賴 | 無 | 有 |
| 操作類型 | 重命名/格式化 | 設計變更 |
每個變數都是閱讀者需要「記住」的項目:
| 情況 | 認知負擔 | 建議 |
|---|---|---|
| 變數數 <= 3 | 低 | 維持 |
| 變數數 4-5 | 中 | 考慮重構 |
| 變數數 > 5 | 高 | 必須拆分 |
追蹤呼叫鏈需要「堆疊」記憶:
| 層級 | 認知負擔 | 建議 |
|---|---|---|
| 1-2 層 | 低 | 維持 |
| 3 層 | 中 | 考慮扁平化 |
| > 3 層 | 高 | 必須重構 |
不佳的命名增加「翻譯」負擔:
| 問題 | 範例 | 解決 |
|---|---|---|
| 縮寫不明 | btn, mgr, idx | button, manager, index |
| 含義模糊 | data, info, value | 具體化:userData, bookInfo |
| 型別前綴 | strName, intCount | 直接用 name, count |
每個分支都是需要考慮的「路徑」:
| 分支數 | 認知負擔 | 建議 |
|---|---|---|
| 1-2 | 低 | 維持 |
| 3-4 | 中 | 考慮策略模式 |
| > 4 | 高 | 必須重構 |
一個函式只做一件事,讓讀者只需理解一個概念
檢查問題:「這個函式做了幾件事?」
名稱本身就是文件,讓讀者不需要額外資訊
檢查問題:「不看實作,能從名稱理解功能嗎?」
函式的行為應該可預測,讓讀者不需要追蹤隱藏狀態
檢查問題:「這個函式有沒有修改輸入以外的東西?」
減少巢狀,讓讀者不需要追蹤深層上下文
檢查問題:「最深的巢狀層級是多少?(應 <= 3)」
相關的資訊應該放在一起,讓讀者不需要跳轉尋找
檢查問題:「理解這段程式碼需要跳到幾個地方?」
| 方法論 | 認知負擔視角 |
|---|---|
| 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
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
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...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
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...
Display project status, active tracks, and next actions
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.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience