技术写作的 10 条规则、主动语态、短句、代码>文字、避免 jargon——让文档不说人话的根源在这里
"The function returns a promise."
"Click the Submit button."
"The server sends a response."
"A promise is returned by the function."
"The Submit button should be clicked."
"A response is sent by the server."
每句不超过 25 个词。如果一个句子需要逗号+从句+修饰语才能说完,拆成两句。技术文档不是文学——清晰比优雅重要。
"Create a new project. Run npm init. Then install the SDK."
"After you have created a new project by running the npm init command in your terminal, you should then proceed to install the SDK by running the npm install command."
能用代码说清楚的,不要用文字。代码是精确的,文字是模糊的。一段 3 行代码示例胜过 3 段文字描述。
// 获取用户列表
const users = await client.users.list({
limit: 10,
sort: 'created_at:desc'
});"To retrieve the list of users, you need to call the users endpoint with the list method, passing in a configuration object that specifies the limit parameter to control the number of results and the sort parameter to order by creation date in descending order."
除非你的读者 100% 理解术语,否则用大白话。如果必须用 jargon,第一次出现时给出定义。
| Jargon | 大白话 |
|---|---|
| idempotent | 重复调用结果相同 |
| serialization | 把对象转成字符串 |
| memoization | 缓存函数结果 |
| hydration | 给静态页面加交互 |
| reconciliation | 对比新旧差异 |
用"你"而不是"我们"或"用户"。文档是在和读者对话,不是在写报告。
"你需要安装 Node.js 18+."
"你的 API Key 在 Settings 页面。"
"用户需要安装 Node.js 18+."
"我们建议安装 Node.js 18+."
描述功能和行为时用现在时。不要用将来时——代码现在就能做,不是"将能做"。
"This function validates the input."
"The API returns a JSON response."
"This function will validate the input."
"The API will return a JSON response."
用标题、列表、表格组织内容。不要写大段落——没人读。每个段落一个主题,每个列表项一个要点。
同一个概念用同一个词。不要交替使用"API Key"和"Access Token"指同一件事。建立术语表。
数字要精确,不要用"很多""很快""大概"。"支持 10,000 并发"比"支持高并发"好 10 倍。
每个断言都应该是可验证的。如果你说"性能提升 3x",就要有 benchmark 代码让读者自己跑。
中文技术文档有一些独特的挑战,是英文文档不需要面对的:
| 问题 | 说明 | 建议 |
|---|---|---|
| 中英混排 | 中英文之间不加空格很丑 | 使用 pangu.js 自动加空格 |
| 术语翻译 | 翻译还是不翻译? | 常见词翻译(函数、变量),新词不翻译(Agent、Token) |
| 标点符号 | 中文用全角,英文用半角 | 中文环境用中文标点,代码/英文用半角 |
| 代码注释 | 中文注释 vs 英文注释? | 开源项目英文,内部项目中文,混合最差 |
| 排版 | 每个段落首行缩进? | 技术文档不缩进,段间距分隔 |
| "的"字过多 | "用户的请求的处理的函数" | 删掉多余"的",或改用"之" |
Google 提供免费的 Technical Writing Courses,这是目前最好的技术写作入门课程。两个模块各约 2 小时,涵盖:清晰句子的写作、段落组织、文档结构、标点和格式。强烈推荐每位开发者完成。