跳转到内容

Snippet

“Snippet” 在 IDE 中常指 snippet 快捷键展开的模板;在文档中指短代码示例。强调短小、可复制,而非完整项目。VS Code、JetBrains 均支持自定义 code snippets。

  1. “She saved a React hook snippet for faster prototyping.” (她保存了一个 React Hook 片段以便快速原型。)
  2. “The docs include a snippet showing how to authenticate.” (文档包含展示如何认证的代码片段。)
  3. “Paste the SQL snippet into your migration file.” (把 SQL 片段贴进迁移文件。)

可能源自 snip(剪)的指小词,比喻“剪下来的一小块”。

“-et” 为指小后缀,表“小片、少量”。

Stack Overflow 回答常以 snippet 形式出现;snippet 管理是提升开发者效率的常见做法。

  • 固定搭配: “code snippet” (代码片段), “snippet library” (片段库), “insert snippet” (插入片段)
  • 动词: 少用,多作名词

从长代码里 snip 出一小 bit——snippet。

“A five-line snippet fixed the date formatting bug that had puzzled the team all day.” (五行代码片段修好了困扰团队一整天的日期格式 bug。)