prototype

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prototype

原型

A prototype is throwaway code that answers a question. The question decides the shape.
原型是用于解答问题的一次性代码。问题决定了原型的形态。

Pick a branch

选择分支

Identify which question is being answered — from the user's prompt, the surrounding code, or by asking if the user is around:
  • "Does this logic / state model feel right?"LOGIC.md. Build a tiny interactive terminal app that pushes the state machine through cases that are hard to reason about on paper.
  • "What should this look like?"UI.md. Generate several radically different UI variations on a single route, switchable via a URL search param and a floating bottom bar.
The two branches produce very different artifacts — getting this wrong wastes the whole prototype. If the question is genuinely ambiguous and the user isn't reachable, default to whichever branch better matches the surrounding code (a backend module → logic; a page or component → UI) and state the assumption at the top of the prototype.
确定要解答的问题——从用户的提示、现有代码中寻找,或是询问用户是否在场:
  • “这个逻辑/状态模型是否合理?”LOGIC.md。构建一个小型交互式终端应用,将状态机应用于那些难以在纸面推理的场景。
  • “这个UI应该是什么样的?”UI.md。为单个路由生成几种截然不同的UI变体,可通过URL搜索参数和浮动底部栏切换。
这两个分支会产出完全不同的成果——选分支错误会浪费整个原型的制作。如果问题确实模糊且无法联系到用户,默认选择与现有代码更匹配的分支(后端模块→逻辑;页面或组件→UI),并在原型顶部说明这一假设。

Rules that apply to both

通用规则

  1. Throwaway from day one, and clearly marked as such. Locate the prototype code close to where it will actually be used (next to the module or page it's prototyping for) so context is obvious — but name it so a casual reader can see it's a prototype, not production. For throwaway UI routes, obey whatever routing convention the project already uses; don't invent a new top-level structure.
  2. One command to run. Whatever the project's existing task runner supports —
    pnpm <name>
    ,
    python <path>
    ,
    bun <path>
    , etc. The user must be able to start it without thinking.
  3. No persistence by default. State lives in memory. Persistence is the thing the prototype is checking, not something it should depend on. If the question explicitly involves a database, hit a scratch DB or a local file with a clear "PROTOTYPE — wipe me" name.
  4. Skip the polish. No tests, no error handling beyond what makes the prototype runnable, no abstractions. The point is to learn something fast and then delete it.
  5. Surface the state. After every action (logic) or on every variant switch (UI), print or render the full relevant state so the user can see what changed.
  6. Delete or absorb when done. When the prototype has answered its question, either delete it or fold the validated decision into the real code — don't leave it rotting in the repo.
  1. 从一开始就明确是一次性原型,并清晰标记。 将原型代码放在实际使用位置附近(紧邻它所原型化的模块或页面),以便上下文清晰——但命名要让普通读者能看出这是原型而非生产代码。对于一次性UI路由,遵循项目已有的路由约定;不要创建新的顶级结构。
  2. 一键运行。 无论项目现有的任务运行器支持哪种方式——
    pnpm <name>
    python <path>
    bun <path>
    等。用户无需思考就能启动它。
  3. 默认不持久化。 状态保存在内存中。持久化是原型要验证的内容,而非它依赖的东西。如果问题明确涉及数据库,使用临时数据库或带有清晰“PROTOTYPE — wipe me”名称的本地文件。
  4. 跳过打磨环节。 不写测试,除了保证原型可运行之外不做错误处理,不做抽象。目的是快速学到东西然后删除它。
  5. 展示状态。 在每次操作(逻辑原型)或切换变体(UI原型)后,打印或渲染完整的相关状态,让用户能看到发生了什么变化。
  6. 完成后删除或整合。 当原型解答了问题后,要么删除它,要么将验证后的决策整合到正式代码中——不要让它在仓库里闲置变质。

When done

完成后

The answer is the only thing worth keeping from a prototype. Capture it somewhere durable (commit message, ADR, issue, or a
NOTES.md
next to the prototype) along with the question it was answering. If the user is around, that capture is a quick conversation; if not, leave the placeholder so they (or you, on the next pass) can fill in the verdict before deleting the prototype.
原型中唯一值得保留的是答案。将答案连同它所解答的问题一起记录在持久化的地方(提交信息、ADR、issue,或是原型旁边的
NOTES.md
)。如果用户在场,可以通过简短对话记录;如果不在,留下占位符,以便他们(或下次迭代的你)在删除原型前填写结论。