伪代码设计与逐步细化
design-pseudocode
通过逐步细化来设计例程——编码前先用伪代码表达设计意图,随后将其提升为代码注释。在设计复杂函数或非简单算法时使用。
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 60
- Forks
- 6
01 前言 Front Matter
- args
- [target or description]
- name
- design-pseudocode
- created
- 1782172800000
- modified
- 1782172800000
- reviewed
- 1782172800000
- description
- Design a routine by stepwise refinement — pseudocode the intent before coding, then promote it to comments. Use when designing a complex function or non-trivial algorithm.
- allowed-tools
- Read, Grep, Glob, Bash(git diff *), TodoWrite
- argument-hint
- a routine to design (free text), or a stub file|diff; omit for current change
03 SKILL.md 正文
Design by Pseudocode
From Code Complete (McConnell), the Pseudocode Programming Process: before writing a non-trivial routine, design it in pseudocode — intent-level English statements, one per step — refining top-down until each line is obvious to translate into code. You catch the hard cases, the wrong decomposition, and the missing error path while editing prose, which is an order of magnitude cheaper than catching them while editing code. The finished pseudocode then becomes the routine's comments, so the design survives as documentation.
This is a pre-implementation design technique: it decides a routine's internal structure, names its steps, and surfaces its edge cases before a single line of real code is committed.
When to Use This Skill
| Use this skill when... | Use something else instead when... |
|---|---|
| Designing a complex routine or non-trivial algorithm before coding | Verifying whole-project premises before a wave → agent-patterns-plugin:verify-before-plan |
| The decomposition isn't obvious and you want to fail cheap in prose | Choosing a structural design pattern → software-design-plugin:design-patterns |
| Naming steps + edge cases up front, then keeping them as comments | A multi-file refactor plan → workflow-orchestration-plugin:workflow-checkpoint-refactor |
| Reviewing whether a stub's intended logic is sound before it's built | Reviewing already-written code → code-quality-plugin:code-review |
Core Principle
| Step | What you do | What it buys |
|---|---|---|
| 1. Intent | State the routine's contract: inputs, output, one-line job | A clear target before mechanism |
| 2. Refine | Decompose into intent-level steps; refine each until trivial | The decomposition is judged in prose |
| 3. Check edges | Walk error paths, empty/boundary inputs, failure modes | Missing cases found before code |
| 4. Promote | Each pseudocode line becomes a comment; fill code beneath | Design survives as documentation |
Pseudocode is intent, not syntax: "find the first overdue invoice" — not
for (i=0; i<n; i++). If a line is already code-shaped, it's too low; if you
can't translate a line directly to a few statements, it's too high — refine it.
Parameters
Parse $ARGUMENTS:
- Target or description (optional) — a free-text description of the routine to
design, or a stub file/diff whose intended logic to work out. If absent,
default to the current change (
git diff HEAD) and design the routine it stubs.
Execution
Execute this pseudocode design pass:
Step 1: State the contract
One line each: what the routine takes, what it returns/guarantees, and its single
job. If it has more than one job, that's a decomposition signal — design the
pieces separately (pairs well with software-design-plugin:design-by-contract).
Step 2: Refine top-down
Write the routine as a short list of intent-level steps. Refine any step that isn't obvious-to-code into sub-steps. Stop when every line maps to a few statements. Resist writing real syntax — the value is judging the shape before committing to it.
Step 3: Walk the edges
Against the pseudocode, walk: empty/null/boundary inputs, the failure of each external call, and the postcondition under each path. Add the handling as pseudocode lines. A case you can't place is a sign the decomposition is wrong — revise the steps, not just patch the end.
Step 4: Promote to comments and report
Emit the refined pseudocode as the routine's comment skeleton (each line a comment, code to be filled beneath). Report: the contract, the step decomposition, the edge cases surfaced, and any decomposition smell (a step doing two jobs, a missing error path) found during refinement.
Anti-patterns
| Mistake | Correct approach |
|---|---|
| Writing real code and calling it pseudocode | Intent-level English; if it's syntax, raise the altitude |
| Pseudocode so vague a step hides a whole algorithm | If a line won't translate to a few statements, refine it |
| Skipping the edge-case walk | Step 3 is where pseudocode pays for itself |
| Throwing the pseudocode away after coding | Promote it to comments — the design becomes the docs |
Quick Reference
| Altitude check | Verdict |
|---|---|
Line reads as for/if/while (...) |
Too low — that's code |
| Line maps to 1-5 statements of intent | Just right |
| Line hides a whole sub-algorithm | Too high — refine it |
| A step does two distinct jobs | Decompose into separate routines |
Related
software-design-plugin:design-by-contract— Step 1's contract is the precondition/postcondition pair, made explicitsoftware-design-plugin:design-patterns— when refinement reveals recurring variation, a pattern may be the right step structurecode-quality-plugin:code-review— reviews the code after; this designs it beforeagent-patterns-plugin:verify-before-plan— the project-scale sibling: verify premises before a multi-agent plan, as this refines a routine before code
04 同仓库更多 Skills
session-workflow-capture
Workflow-tool scripts and workflow friction from this session, filed as issues here or in the plugins repo. Use when a session ran Workflow scripts.
kitty-show-image
Show the user an image with a note on what to judge, via a file send or a labelled kitty tab. Use when the user must see an image, or icat fails with no /dev/tty.
kitty-session-persistence
Snapshot and restore kitty terminal sessions on macOS. Use when surviving WindowServer hangs without losing tabs, configuring snapshots, or restoring after a force-reboot.
kitty-remote-control
Safe kitty remote control from an agent — read panes with kitty @ ls/get-text, notify, and never mutate the live terminal unasked. Use when running inside kitty.
docs-reference-check
Dangling doc-reference gate: flag markdown naming repo paths or relative links that no longer exist. Use when docs cite moved/deleted files, or wiring a doc-drift lint.
YouTube 视频上传与编辑
youtube-upload
通过 Data API v3 将视频上传到 YouTube,并在之后编辑其标题、描述、标签或缩略图。适用于发布 YouTube 视频或修改其标题。