refactor — 重构;重整代码结构;改写
Pronunciation /riːˈfæktə(r)/ (BrE) · /riːˈfæktɚ/ (AmE) · 音标依 factor /ˈfæktə(r)/ 推得(核验边界见文末)
v. [T] 重构;在不改变外部行为的前提下调整内部结构 · n. 重构(活动)· 复数 refactors · 名词 refactoring · 形容词 refactorable
义项 Senses
1. v. (computing) to restructure existing source code so that it is easier to understand, reuse or modify, without changing its observable behaviour
zh.(计算机)重构——不改外部行为地重组代码结构
"We should refactor this module before we add the new payment path." "加新支付链路前,先把这个模块重构一下。"
2. n. the process of doing this; a restructuring carried out as a series of small behaviour-preserving steps
zh. 重构(过程);以「小步、行为不变」的变换完成调整
"A refactor is not a rewrite: the system keeps working after every step." "重构不是重写:每一步之后系统都还是可用的。"
3. v. (general, informal) to reorganise any existing thing — a document, a process, an organisation — into a cleaner shape
zh.(泛用/口语)重整;把(文档、流程、组织)梳理更清晰
"We refactored the onboarding checklist and new hires now ship in week one." "我们重整了入职清单,新人现在第一周就能交付。"
习语与复合词 Idioms & Compounds
- a big / major refactor n. 一次大规模重构(暗示工期长、风险高)
"We don't have time for a major refactor; we're shipping in two weeks." "没时间做大重构,两周后就上线。"
- refactor under pressure phr. 在压力下边改边重构(讽刺 deadline 前的大改)
"Never refactor under pressure — ship the fix and schedule the cleanup." "别在压力下重构——先上线修复,再排清理。"
- preparatory refactoring n. 铺垫式重构——先改结构,让下一个改动变简单
"Fowler calls this a preparatory refactoring: make the change easy, then make the easy change." "福勒称之为铺垫式重构:先让改动变容易,再做容易的。"
派生词 Derivatives
- refactoring n. 重构(还技术债的手段)
"Refactoring is how you pay down technical debt before it compounds." "重构就是在技术债滚雪球前还掉。"
- refactorable adj. 可重构的
"This module isn't refactorable until the tests cover it." "测试补齐前,这模块没法重构。"
- refactorer n. 重构者;自动重构工具
"The refactorer moved the import to the top of the file." "重构工具把 import 移到顶。"
- refactorability n. 可重构性
"We scored refactorability as part of the technical due diligence." "可重构性被列进尽调评分项。"
词源 Etymology
en. A software-engineering coinage on factor: Latin factor "doer, maker" (from faciō "make, do", plus the agent suffix -tor) → Anglo-Norman factour → Middle English factour → English factor, which by the 17th century had also drifted into the mathematical sense "an expression treated as a product of factors". Refactor = re- + factor, on the analogy of mathematical re-factorisation: factor x² + 5x + 6 into (x+2)(x+3) and the arithmetic gets easier — just as a program broken into logical chunks is easier to work with. The engineering sense crystallised in two independent communities at once. Bill Wake dug out the first known printed use of "refactoring" in Thinking Forth (Leo Brodie, 1984), page 181 — in the Forth community, where the factoring metaphor was already at home. Separately, Bill Opdyke and Ralph Johnson were circling the term in the Smalltalk world; Opdyke recalled proposing "Software Refactory" (a pun on "Software Factory") to Ralph Johnson, and it became the name of their consulting company. Their 1990 paper and Opdyke's 1992 thesis carried the word into the object-oriented literature.
zh. 软件工程界自造的词,底子是 factor:拉丁语 factor「做的人」(来自 faciō「做」,加施事后缀 -tor)→ 盎格鲁-诺曼法语 factour → 中古英语 factour → 英语 factor;17 世纪起它又漂出数学义「因子」。Refactor = re- + factor,与数学「再分解」平行:把 x² + 5x + 6 分解成 (x+2)(x+3),运算就变简单;程序切成逻辑清晰的块,人跟代码打交道也变简单。工程义在两个独立社区同时成形:Bill Wake 挖出「refactoring」最早见诸印刷,在 Forth 社区——Leo Brodie 1984 年的 Thinking Forth 第 181 页;另一边 Smalltalk 社区的 Bill Opdyke 与 Ralph Johnson 也在围着这词转,Opdyke 回忆自己曾提议叫「Software Refactory」(拿 "Software Factory" 做的双关)。这词后来随其论文进入面向对象世界。
引语 Quotations
"Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior." — Martin Fowler, Refactoring: Improving the Design of Existing Code "重构是一种有纪律的技术:重组既有代码,不改外部行为地调整内部结构。"(福勒《重构:改善既有代码的设计》)
"Refactoring isn't another word for cleaning up code — it specifically defines one technique for improving the health of a code-base." — Martin Fowler, refactoring.com "重构不是『清理代码』的另一种说法——它特指改善代码库健康度的具体技术。"(福勒,refactoring.com)
"And right there, on page 181, is what is, to the best of my knowledge, the first published appearance of The Word itself." — Bill Wake, Catfish in the Memepool, 2011 "就在那本书第 181 页——据我所知,那是这词最早见诸印刷处。"(Wake,2011)
词族 Word Family
- factor n. 因素;因数;制作者(词根)
- factorial n./adj. 阶乘(的)
- factorize / factorise v. 分解为因数
- refactor v./n. 重构
- refactoring n. 重构(活动)
- refactorable adj. 可重构的
- refactorer n. 重构者/重构工具
- refactorability n. 可重构性
- unrefactored adj. 未重构
- 复合:preparatory refactoring(铺垫式重构)、major refactor(大改)
- 词根链:PIE *dʰeh₁-「做」 → 拉丁语 *faciō → *factor → 英语 *factor → refactor
近义词辨析 Synonyms & Nuance
- refactor — 唯一带**「外部行为不变」硬约束**的那个:改内部结构,不改对外表现。小步、可验证、可回滚。语域:软件工程、架构评审、Git 提交信息。
- rewrite — 推倒重来。a rewrite from scratch。没有行为不变的承诺,通常伴随一段「新旧行为不一致」的窗口期。把 rewrite 说成 refactor 是误用。
- restructure — 最宽泛的「重新组织」,可涵盖技术债、组织架构、部门。Fowler 说 restructuring 是更一般的说法,refactoring 是其中一种技术。refactor ⊂ restructure。
- clean up — 口语,强调「收拾干净」,无方法论。clean up the code 像打扫卫生,refactor the code 像有纪律的动作。
- rearchitect / modernize / optimize — 目标各自明确:改架构层级、换技术栈、改性能指标。refactor 只承诺「结构更清楚、改动更省」。
- 中文陷阱:中文「重构」同时盖住 refactor 和 rewrite,还常被用来指「推倒重写」。英文里这两件事风险等级完全不同:refactor 小步可回滚,rewrite 意味着危险窗口期。说 refactor 时务必带上「行为不变」,否则对方会按 rewrite 的风险理解。
一句话记法:refactor 不改行为;restructure 泛指重组;rewrite 推倒重来。中文一个「重构」盖住前两个,最易出事。
用法提示 Usage Note
- 拼写:动词 refactor(不带 -ing),名词 refactoring,单数 a refactor、复数 refactors。
- 介词:refactor for X(为 X 而重构)、refactor away X(重构掉 X)。别混数学的 re-factorisation(再分解),虽同源但另一回事。
- 通用词典收录:牛津学习型词典与剑桥词典均无此词条(详见「最早用例」)——它是行业术语而非通用词汇。跟不懂技术的听众沟通,第一次出现最好解释。
- 语气:工程圈之外,refactoring 偶尔带点「故弄玄虚」的味道。用在中层沟通最稳。
工作场景例句 At Work
-
技术评审
"I'd refactor the settlement module first — adding the new fee rule on top of this makes it twice as hard to change later." "我会先重构结算模块——在这基础上加新费率规则,以后只会更难改。"
-
商务邮件(向非技术方解释)
"This is a refactor, not a rebuild: the service behaves exactly the same afterwards, we just make the code easier for the team to change safely." "这是重构,不是重写:上线后服务表现完全一样,只是代码更好维护,团队改动更安全。"
-
面试表达
"At Payful I set a rule that every behaviour change and every refactor lands as a separate commit, so the audit trail stays readable." "在宝付期间我定了个规矩:行为变更和重构各自独立提交,审计链路始终清晰。"
-
财经评论
"Investors read a restructuring as a cost; engineers read a refactor as an investment in the next three years of change." "投资人把重组读作成本,工程师把重构读作未来三年改动的投资。"
交叉参考 Cross-References
- deprecate — 重构常伴随旧接口下线 →
learning/word-of-day/2026-11/deprecate - redundant — 重构常见目标:消除重复 →
learning/word-of-day/2026-10/redundant - granularity — 重构要决定拆到哪层 →
learning/word-of-day/2026-11/granularity - explicit — 重构前先写清「行为不变」范围 →
learning/word-of-day/2026-10/explicit - trade-off — 重构是拿今天时间换未来改动成本 →
learning/word-of-day/2026-10/trade-off - robust — 重构产出要扛得住改动 →
learning/word-of-day/2026-11/robust
最早用例 First Known Use
- 最早印刷用例:1984 年,Leo Brodie 的 Thinking Forth 第 181 页——由 Bill Wake 挖出并公开考证,Fowler 词源页亦引此说。
- 进入 OOP 圈:1990 年,Opdyke 与 Johnson 发表 Refactoring: An Aid in Designing Application Frameworks...(OOPSLA);Opdyke 的 1992 年学位论文更完整。1997–1999 年 Fowler 出版 Refactoring 第一版,第二版(2018 年)时他写道当年这还是「鲜为人知的技术」,十八年后已是熟练程序员的常规工具。
- 中文小结:印刷史起于 1984 年(Forth 社区),1990 年进入 OOP 学术圈,1997–1999 年经 Fowler 的书进入大众工程视野;词形路径为「PIE *dʰeh₁- → *faciō → *factor → refactor」。
- 核验边界(透明):词源主线(Fowler 的 EtymologyOfRefactoring 页、refactoring.com 定义段)、Bill Wake 的考证(Thinking Forth 1984、第 181 页)、Wiktionary 词源树「From re- + factor」、「OALD 查无此词」四处均已直连原页逐字核对(OALD 检索页原话 "Word not found in the dictionary")。Merriam-Webster / Etymonline / Collins / Cambridge 的 refactor 词条页被 Cloudflare 403 或本身无该词条拦截,故音标依
factor通行读法推得并标注为推得值;First Known Use 年份暂缺。