形式化符号与自然语言编程:迪杰斯特拉经典观点再审视

发布时间:2026/7/22 8:48:30

形式化符号与自然语言编程:迪杰斯特拉经典观点再审视 注本文为 “形式化符号与自然语言编程” 相关合辑。英文引文机翻未校。中文引文略作重排。如有内容异常请看原文。On the foolishness of “natural language programming”论“自然语言编程”的荒谬性Edsger W.DijkstraSince the early days of automatic computing we have had people that have felt it as a shortcoming that programming required the care and accuracy that is characteristic for the use of any formal symbolism. They blamed the mechanical slave for its strict obedience with which it carried out its given instructions, even if a moment’s thought would have revealed that those instructions contained an obvious mistake. “But a moment is a long time, and thought is a painful process.” (A.E.Housman). They eagerly hoped and waited for more sensible machinery that would refuse to embark on such nonsensical activities as a trivial clerical error evoked at the time.自自动计算诞生初期起便有人认为编程需要使用形式化符号体系所特有的严谨与精确这是一种缺陷。他们指责机器这一“机械奴仆”严格执行给定指令即便稍加思考便能发现这些指令存在明显错误。“但片刻已然漫长思考亦是痛苦的过程。”A.E. 豪斯曼他们热切期盼并等待着更具理性的机器能够拒绝执行因微小笔误在当时所引发的这类无意义操作。Machine code, with its absence of almost any form of redundancy, was soon identified as a needlessly risky interface between man and machine. Partly in response to this recognition so-called “high-level programming languages” were developed, and, as time went by, we learned to a certain extent how to enhance the protection against silly mistakes. It was a significant improvement that now many a silly mistake did result in an error message instead of in an erroneous answer. (And even this improvement wasn’t universally appreciated: some people found error messages they couldn’t ignore more annoying than wrong results, and, when judging the relative merits of programming languages, some still seem to equate “the ease of programming” with the ease of making undetected mistakes.) The (abstract) machine corresponding to a programming language remained, however, a faithful slave, i.e. the nonsensible automaton perfectly capable of carrying out nonsensical instructions. Programming remained the use of a formal symbolism and, as such, continued to require the care and accuracy required before.几乎不具备任何冗余形式的机器代码很快被认定为人机之间一种不必要的高风险接口。部分基于这一认知所谓“高级编程语言”得以开发随着时间推移人们在一定程度上掌握了增强对低级错误防护能力的方法。诸多低级错误如今会触发错误提示而非输出错误结果这是一项重要改进。即便这一改进也未获得普遍认可部分人认为无法忽略的错误提示比错误结果更令人厌烦且在评判编程语言的优劣时部分人仍将“编程便捷性”等同于制造未被察觉错误的便捷性。不过与编程语言对应的抽象机器依旧是忠实的奴仆即无自主判断能力的自动机可完美执行无意义指令。编程依旧依托形式化符号体系因此仍需保持此前所需的严谨与精确。In order to make machines significantly easier to use, it has been proposed (to try) to design machines that we could instruct in our native tongues. this would, admittedly, make the machines much more complicated, but, it was argued, by letting the machine carry a larger share of the burden, life would become easier for us. It sounds sensible provided you blame the obligation to use a formal symbolism as the source of your difficulties. But is the argument valid? I doubt.为大幅提升机器的易用性有观点提出尝试设计可通过自然语言下达指令的机器。不可否认这会使机器复杂度大幅提升但支持者认为让机器承担更多工作负担人类的使用体验会更为轻松。若将使用形式化符号的要求视作困难的来源这一观点看似合理。但该论证是否成立笔者对此存疑。We know in the meantime that the choice of an interface is not just a division of (a fixed amount of) labour, because the work involved in co-operating and communicating across the interface has to be added. We know in the meantime —from sobering experience, I may add— that a change of interface can easily increase at both sides of the fence the amount of work to be done (even drastically so). Hence the increased preference for what are now called “narrow interfaces”. Therefore, although changing to communication between machine and man conducted in the latter’s native tongue would greatly increase the machine’s burden, we have to challenge the assumption that this would simplify man’s life.人们如今已然知晓接口的选择并非仅为固定工作量的分配还需计入接口两侧协作与通信产生的额外工作。笔者补充道从诸多令人警醒的实践经验中可知接口的变更极易使两侧的工作量均有所增加甚至大幅增加。由此当下被称作“窄接口”的设计愈发受到推崇。因此即便改用自然语言实现人机通信会极大增加机器的负担人们仍需质疑这一方式会简化人类工作的预设。A short look at the history of mathematics shows how justified this challenge is. Greek mathematics got stuck because it remained a verbal, pictorial activity, Moslem “algebra”, after a timid attempt at symbolism, died when it returned to the rhetoric style, and the modern civilized world could only emerge —for better or for worse— when Western Europe could free itself from the fetters of medieval scholasticism —a vain attempt at verbal precision!— thanks to the carefully, or at least consciously designed formal symbolisms that we owe to people like Vieta, Descartes, Leibniz, and (later) Boole.简要回顾数学史便能印证这一质疑的合理性。古希腊数学因始终停留在文字与图形表述阶段而陷入停滞伊斯兰代数学在对符号化做出浅尝辄止的尝试后回归修辞学表述模式最终走向消亡而现代文明社会的诞生无论利弊均依托于西欧摆脱中世纪经院哲学的桎梏——经院哲学对文字精确性的追求终归徒劳——这一突破得益于韦达、笛卡尔、莱布尼茨以及后续布尔等人精心或至少是有意识设计的形式化符号体系。The virtue of formal texts is that their manipulations, in order to be legitimate, need to satisfy only a few simple rules; they are, when you come to think of it, an amazingly effective tool for ruling out all sorts of nonsense that, when we use our native tongues, are almost impossible to avoid.形式化文本的价值在于其合法操作仅需遵循少量简单规则细想之下这类文本是排除各类无意义表述的高效工具而这类无意义表述在自然语言使用中几乎无法避免。Instead of regarding the obligation to use formal symbols as a burden, we should regard the convenience of using them as a privilege: thanks to them, school children can learn to do what in earlier days only genius could achieve. (This was evidently not understood by the author that wrote —in 1977— in the preface of a technical report that “even the standard symbols used for logical connectives have been avoided for the sake of clarity”. The occurrence of that sentence suggests that the author’s misunderstanding is not confined to him alone.) When all is said and told, the “naturalness” with which we use our native tongues boils down to the ease with which we can use them for making statements the nonsense of which is not obvious.不应将使用形式化符号的要求视作负担而应将其便捷性视作一种优势依托形式化符号普通学生能够掌握早年唯有天才可完成的工作。1977 年某技术报告序言中作者写道“为保证清晰性甚至规避了逻辑连接词的标准符号”显然该作者并未理解这一道理。此表述的出现也说明这类认知误区并非个例。归根结底人们使用自然语言的“自然性”本质是借助自然语言表述不易察觉其无意义内容的便捷性。It may be illuminating to try to imagine what would have happened if, right from the start our native tongue would have been the only vehicle for the input into and the output from our information processing equipment. My considered guess is that history would, in a sense, have repeated itself, and that computer science would consist mainly of the indeed black art how to bootstrap from there to a sufficiently well-defined formal system. We would need all the intellect in the world to get the interface narrow enough to be usable, and, in view of the history of mankind, it may not be overly pessimistic to guess that to do the job well enough would require again a few thousand years.不妨设想若从一开始自然语言便是信息处理设备唯一的输入输出载体会产生何种结果这一思考颇具启发意义。笔者经深思后推测从某种角度而言历史会重演计算机科学将主要围绕如何从这一基础逐步构建出定义完备的形式化系统这一晦涩技艺展开。人们需要倾尽智慧将接口压缩至可用的窄接口范围结合人类历史进程来看推测完成这一工作仍需数千年时间并不算过度悲观。Remark. As a result of the educational trend away from intellectual discipline, the last decades have shown in the Western world a sharp decline of people’s mastery of their own language: many people that by the standards of a previous generation should know better, are no longer able to use their native tongue effectively, even for purposes for which it is pretty adequate. (You have only to look at the indeed alarming amount of on close reading meaningless verbiage in scientific articles, technical reports, government publications etc.) This phenomenon —known as “The New Illiteracy”— should discourage those believers in natural language programming that lack the technical insight needed to predict its failure. (End of remark.)注受背离理性素养的教育趋势影响近几十年西方社会民众的母语驾驭能力显著下滑按上代人的标准本应具备良好语言能力的人群如今已无法有效运用母语即便在其本可适配的场景中亦是如此。只需审视科研论文、技术报告、政府出版物等文本中经细读便可知其无意义的冗余表述数量便可见问题之严峻。这一被称作“新文盲现象”的状况应当使那些推崇自然语言编程、却缺乏预判其失败所需技术认知的人有所警醒。注毕From one gut feeling I derive much consolation: I suspect that machines to be programmed in our native tongues —be it Dutch, English, American, French, German, or Swahili— are as damned difficult to make as they would be to use.笔者从一种直觉中获得诸多慰藉无论采用荷兰语、英式英语、美式英语、法语、德语还是斯瓦希里语依托自然语言编程的机器其研发难度与使用难度同样极高。Plataanstraat 55671 AL NUENENThe Netherlands荷兰 纽南 5671 AL 普拉坦街 5 号prof.dr.Edsger W.DijkstraBurroughs Research Fellow埃兹格· W. 迪杰斯特拉 教授/博士宝来公司研究员transcribed by Tristram Brelstaffrevised Fri, 19 Nov 2010转录特里斯特拉姆·布雷尔斯塔夫修订时间2010 年 11 月 19 日 星期五Dijkstra 48年前就预言了 Vibe Coding 的问题——自然语言编程的「愚蠢」与「聪明」王勃 发布于 2026-03-25 03:56・北京一个 48 年前的「预言」1978 年计算机科学的祖师爷之一 Edsger Dijkstra 写了一篇短文编号 EWD667标题直白到近乎挑衅《论「自然语言编程」的愚蠢》On the foolishness of “natural language programming”他的论点很简单有人觉得编程太严格了希望有一天能用自然语言跟计算机说话。Dijkstra 认为这个愿望不仅不切实际而且方向就是错的。形式化符号不是程序员的负担而是特权。48 年后的 2026 年大语言模型让自然语言编程真的成了现实。Karpathy 说自己从去年 12 月起几乎没再亲手敲过代码Anthropic Claude Code 产品负责人 Cat Wu 撰文指出 PM 的产出正在从文档变成可运行的原型Stripe 每周有 1300 个无人值守的 Agent PR 被合并。Dijkstra 错了吗我带团队用了一年多 AI 编程工具从最初的阻力到现在全员 Cursor从 Vibe Coding 的兴奋到 Planned 模式的回归。回头看我觉得 Dijkstra 对了一半——而且是更重要的那一半。Dijkstra 到底说了什么EWD667 全文不长但论证链条极其锋利。全文围绕三个观点展开第一形式化符号是文明进步的引擎不是累赘。他用数学史来论证希腊数学因为停留在口头和图形描述而停滞不前穆斯林代数短暂尝试符号化后退回修辞风格而消亡现代科学的崛起恰恰是因为 Vieta、Descartes、Leibniz、Boole 这些人精心设计了形式化符号系统。他写道形式化文本的美德在于其操作只需满足少数简单规则它们是排除各种胡说八道的极其有效的工具——而当我们使用自然语言时胡说八道几乎不可避免。第二自然语言的「自然」本质上是一种危险的舒适。这是全文最犀利的一句所谓自然语言的「自然性」归根结底不过是我们能轻松地用它说出那些荒谬性并不显而易见的话。翻译成大白话自然语言让你很容易说出自己都没意识到的模糊和矛盾而且还觉得自己说清楚了。第三让接口变宽不一定减轻负担可能两边都更累。他指出接口设计不是简单的劳动分配。让机器理解自然语言不只是给机器加活——跨接口的沟通成本也会增加最终可能双方都更累。他因此主张「窄接口」narrow interface约束越明确合作越高效。一年 AI 编程实践的印证去年我要求团队全面使用 Cursor原则是不限量、用好模型。初期有阻力但很快大家就感受到了效率的飞跃。前端岗位开始大量减少我们要求前端转全栈。产品经理也开始用 Cursor 写文档、出交互式原型。很多项目一个人就能搞定需求分析加开发。Vibe Coding 的甜蜜期是真实的用自然语言描述需求AI 几分钟就能生成一个能跑的 demo。Demo 效率大增我们开始接受「不用想很清楚就可以开始」的工作方式产品和研发一起摸石头过河。但甜蜜期过后问题开始浮现——而这些问题恰恰是 Dijkstra 48 年前预言的。AI 总是漏需求。你以为自己说清楚了AI 也表现得好像理解了但交付的东西总是差那么几个关键点。本质上就是 Dijkstra 说的自然语言让你轻松说出荒谬性并不显而易见的话。你的需求描述有模糊地带你自己都没意识到AI 就按它的理解填补了空白。代码没有架构感。AI 生成的代码能跑但结构松散容易被现有代码的风格带偏。因为自然语言描述天然缺乏架构约束——你说「帮我写一个用户管理模块」这句话里没有任何关于分层、依赖关系、接口设计的形式化信息。上下文越长越降智。对话一长AI 的服从性反而变成问题——它会被之前对话中的错误信息污染然后在错误的方向上越走越远最终放弃或者乱试。这就是 Dijkstra 说的「接口变宽两边都更累」的现代版本。写码快不代表深思熟虑。这一点我们团队反复体会到。AI 可以很快写出代码但速度掩盖了思考的缺失。不推荐所有标榜对编码特化的模型除非代码用一次就扔。形式化没有消失只是换了形态踩完坑之后我们的工作流逐渐从 Vibe Coding 回归到了 Planned 模式。一个典型的开发过程变成了描述需求和模型对齐确认它的理解是正确的让模型分析细化排除矛盾可行性预研给出备选方案人来选择提出测试需求系统设计和关键算法设计人来审查设计测试方案自动化 端到端分拆任务确定验收标准执行并验收看到了吗这个流程的每一步都是在把自然语言的模糊描述逐步转化为更形式化的约束——spec、测试用例、验收标准、任务分拆。这不是倒退这是 Dijkstra 说的「窄接口」思想的现代实践。今年行业里出现了一个概念叫 Harness Engineering马具工程/驾驭工程由 Terraform 的作者 Mitchell Hashimoto 提出。他的原则是每次发现 AI 犯错就花时间工程化一个机制让它以后再也不犯这个错。这个概念的演进路线很清晰2023-2024Prompt Engineering— 怎么跟 AI 说话。本质是优化一次性的自然语言输入。2025Context Engineering— 给 AI 看什么信息。不再只盯措辞而是设计整个信息环境。2026Harness Engineering— 构建什么环境让 AI 可靠地工作。验证闭环、架构约束、测试护栏、熵清理。从 Prompt 到 Context 到 Harness这条路线的方向是什么是从自然语言走向形式化约束。CLAUDE.md、AGENTS.md 这些配置文件本质上就是写给 AI 的形式化规范。TDD 测试套件就是用代码表达的验收标准。CI/CD 管道就是自动化的质量闸门。Dijkstra 说「形式化符号是排除胡说八道的工具」。在 AI 时代这句话变成了测试和约束是排除 AI 胡说八道的工具。过去 CI/CD 集成、TDD 这些被认为是昂贵的工程实践很多团队嫌麻烦不做。但在 AI 编程时代它们已经从奢侈品变成了必需品。AI 由于实现机制的原因没有办法保证 100% 稳定不出错在兜底防御方面投入多少力气都不为过。AI 真正改变的是什么说到这里可能有人觉得我在唱衰 AI 编程。恰恰相反。Dijkstra 的洞察在 LLM 时代依然成立但他有一件事没预见到形式化的生产成本可以被 AI 大幅降低。以前写一套完整的测试用例、设计一份严谨的接口规范、维护一份结构化的需求文档——这些形式化工作本身就需要大量人力所以很多团队干脆不做。代码裸奔、需求口头传递、测试靠手点这是大多数团队的现实。现在不一样了。你可以用自然语言描述你想要什么让 AI 帮你生成测试用例、类型定义、接口文档、验收标准。然后你审核和修正这些形式化产物。这个变化的意义在于不是用自然语言替代了形式化而是用 AI 作为自然语言到形式化的桥梁。自然语言是好的输入层——它降低了表达意图的门槛。 形式化是必要的验证层——它保证意图被正确执行。 AI 是两者之间的翻译器——它让形式化变得便宜了。这三层结构才是 AI 编程真正可持续的工作模式。我们团队现在的做法是产品用自然语言写 specAI 帮忙转化成结构化需求开发用自然语言描述功能AI 生成代码同时生成测试测试人员用 AI 增强能力从手工点点点转向编写自动化测试。每个环节自然语言是入口形式化是出口AI 在中间做翻译。烧 token 的速度直接代表了你的 AI 编程能力——这句话听起来有点夸张但实际确实如此。对编程工具的驾驭能力和并行工作的能力直接决定了你烧 token 的速度。别抠省 token浪费的是你的时间和成长速度。Dijkstra 如果活在今天Dijkstra 在 EWD667 的最后写了一句很有意思的话我有一种直觉可以让我感到安慰能用我们的母语编程的机器无论是荷兰语、英语、美语、法语、德语还是斯瓦希里语——它们既该死地难以制造也该死地难以使用。制造这件事LLM 做到了。但「该死地难以使用」这个预言某种意义上也成真了——不是难在操作界面上而是难在如何让自然语言的模糊性不变成系统性的质量问题。如果 Dijkstra 活在今天看到我们先用自然语言让 AI 写代码然后又花大量精力构建测试、约束、验证闭环来确保 AI 不犯错他大概会说「你们终于造出了能听懂自然语言的机器然后发现还是得用形式化来约束它——这不正是我说的吗」写代码变便宜了但思考没有变便宜。驾驭 AI 的能力本质上是构建形式化约束的能力——把模糊的意图变成精确的规则把不可验证的期望变成可执行的测试把「我觉得差不多了」变成「测试全部通过」。这件事48 年前 Dijkstra 就想明白了。只不过他当年是对着编译器说的我们今天是对着大语言模型说的。工具变了道理没变。本文基于 Dijkstra 1978 年手稿EWD667及笔者团队 AI 编程实践经验。原文可在德克萨斯大学 Dijkstra 档案馆在线阅读。ReferenceE.W.Dijkstra Archive: On the foolishness of “natural language programming”. (EWD 667)https://www.cs.utexas.edu/~EWD/transcriptions/EWD06xx/EWD667.htmlDijkstra 48年前就预言了 Vibe Coding 的问题——自然语言编程的「愚蠢」与「聪明」 - 知乎https://zhuanlan.zhihu.com/p/2019985504695768622

相关新闻