视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
poka-yoke【文档与办公】Mistake-proof code, config and process: make the wrong action impossible or self-announcing rather than documented.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Shigeo Shingo's insight, from the Toyota Production System: people will always make mistakes; that is not the problem worth solving. The problem is letting a mistake become a defect. So you stop trying to make humans more careful and start redesigning the work so the mistake either cannot physically happen or announces itself immediately.
A poka-yoke ("poh-kah yoh-kay", ポカヨケ) is a device: a jig, a shape, a counter: not an instruction. In software: a type, a constraint, a hook, a schema, a state machine. The single most important consequence:
A comment, a docstring, a wiki page, a code review checklist, or a line in CLAUDE.md saying "don't do X" is not a poka-yoke. It is training. Training degrades. A device does not. If your proposed fix relies on someone remembering something, keep going.
Every real poka-yoke answers two questions. Use both when you classify a hazard or propose a device. They are the difference between this method and generic code review.
This is a strict preference ladder. Always reach for the highest rung you can afford.
| Rung | Name | What it does | Software examples |
|---|---|---|---|
| 1 | Control | The mistake is impossible. The work cannot proceed. | Type won't compile · NOT NULL / CHECK / unique constraint · required function argument · private constructor + smart constructor · PreToolUse hook returns deny · protected branch |
| 2 | Warning | The mistake is possible but announced at the moment it happens. | Lint error in the editor · failing CI gate · runtime assertion that throws · confirmation prompt naming the exact thing being destroyed |
| 3 | Detection | The mistake ships, and something finds it afterward. | Tests · monitoring · alerting · reconciliation job |
| 0 | (not a poka-yoke) | Relies on a human remembering. | Docs · comments · training · "be careful" · review checklists |
Shingo's rule: prefer control over warning, always, and only settle for warning when control is genuinely too expensive, then say why out loud. In software the honest reason is usually "the language can't express it" or "it would break every existing caller," and both are worth stating explicitly so the tradeoff is visible.
Shingo's three detection methods map cleanly onto software. These are your inspection lenses, run all three over any interface and you will find hazards that a general code review misses.
| Method | Factory floor | The question to ask code | Software devices |
|---|---|---|---|
| Contact | The part physically won't seat unless it's the right shape and orientation | Can the wrong thing fit? | Distinct types instead of shared primitives · branded/newtype IDs · parse-don't-validate at boundaries · units in the type · discriminated unions instead of bags of optionals |
| Fixed-value | A counter says all 6 screws were fitted | Can the wrong count or an incomplete set pass? | Exhaustive match/switch over an enum · required fields · "all migrations applied" check · row-count guard on a bulk write · checksums · config validated as a whole at boot |
| Motion-step | A sensor confirms step 3 happened before step 4 | Can the steps happen in the wrong order, or be skipped? | Typestate · builder that cannot .build() until required steps run · state machines with illegal transitions unrepresentable · idempotency keys · RAII / defer / context managers · transactions |
Shingo separated source inspection from informative inspection, which finds the defect only after it exists and comes in two forms. Ranked best first, that is three places you can put the device.
Push every device as far up this list as it will go. A CI gate that catches a bad migration is good; a schema that makes the bad migration unwritable is better and costs less forever.
Apply the method directly to the subject in front of you. A Terraform module, a support runbook, a spreadsheet everyone edits, a release checklist, a prompt template, an onboarding process, a physical workflow: the method works on any of them, because Shingo developed it on an assembly line, for people fitting springs into switches, and not for software at all.
Applying it directly means four steps, in order:
Then apply the two rules in How to talk about this below: name the mistake rather than the mistaken, and never let the answer come out as "be more careful" or "document it". Those are rung zero, and the whole method exists because they do not work.
If the request is bare, /poka-yoke with nothing attached, look at what is actually in
front of you: the current diff, the file under discussion, the thing the conversation has been
about. Say what you picked in one line before starting, so it is cheap to redirect you. If
there is genuinely no subject, ask what they want mistake-proofed rather than guessing.
Two habits keep the analysis honest and keep people from getting defensive:
Name the mistake, not the mistaken. "This signature lets a caller swap the two IDs" is actionable and true. "The developer should have been more careful" is neither. Shingo was emphatic that blaming the operator is how organizations avoid fixing the process. Write findings about the code's affordances, never about who wrote it.
Say which rung you achieved, and what stopped you going higher. A recommendation that reads "added a runtime assertion (warning), control would need a newtype, which touches 40 call sites" gives the reader a real decision. One that reads "added validation" does not.
Suppose a destructive API accepts deleteAccount(accountId: string, tenantId: string).
The two identifiers can be swapped, and the call can target an account outside the caller's
tenant.
Propose before you edit. Show the hazard, the proposed device, and the rung it reaches, then wait for a go-ahead before changing files: the whole point of this method is that it changes the shape of an interface, and that is precisely the kind of change people want to see first. Once approved, apply it and record the prevented mistake where future maintainers can verify the constraint without mistaking the explanation itself for the device.
The exception is when someone has explicitly asked you to write new code: mistake-proofing is the code they asked for, so build it, then narrate which hazards you designed out and why.