V2EX  ›  英汉词典

Code Smell

释义 / Definition

“代码异味”指代码中可能暗示设计或实现存在问题的迹象(不一定是明确的 bug),例如重复代码、过长函数、过度耦合等。它通常提示需要重构以提升可读性、可维护性与扩展性。(该短语在不同语境下也可泛指“让人觉得不对劲的代码风格/结构”。)

发音 / Pronunciation (IPA)

/ˈkoʊd smɛl/

例句 / Examples

This function is a code smell—it’s doing too many things.
这个函数有“代码异味”——它做了太多事情。

Although the feature works, the scattered conditionals are a code smell that suggests the design will be hard to maintain as requirements change.
尽管功能能跑通,但到处散落的条件判断是一种“代码异味”,暗示随着需求变化,这个设计会很难维护。

词源 / Etymology

“Code smell”把“smell(气味)”借喻为不需要精密证明也能让人警觉的不良迹象:闻到“味道”就知道哪里可能有问题。该术语常被认为由 Kent Beck 提出,并在 Martin Fowler 的重构思想传播中广泛流行(尤其是与“重构(refactoring)”概念一起使用)。

相关词 / Related Words

文学作品 / Literary Works

  • Refactoring: Improving the Design of Existing Code(Martin Fowler 等):系统讨论“code smells(代码异味)”与对应的重构手法。
  • Clean Code(Robert C. Martin):虽不一定总以该术语为主线,但大量内容与“识别坏味道、改进代码质量”高度相关。
  • Working Effectively with Legacy Code(Michael Feathers):在处理遗留系统时,经常以“坏迹象/异味”为切入点谈如何安全改进代码。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   804 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 19:36 · PVG 03:36 · LAX 11:36 · JFK 14:36
♥ Do have faith in what you're doing.