面向提示词的编程:通过对话写出更好的代码
我的理解
面向提示词的编程将 Cursor 从抄写员升级为真正的对话伙伴:开发者通过聊天窗口直接表达修改请求、探索方案,而不是将指令隐藏在注释中,这种转变促使思维进一步抽象化——你描述的是期望结果(更好的性能、更健壮的错误处理),而不是实现步骤,Cursor 能横跨多个文件提出整体性方案。来回的对话反馈循环让开发者从机械师转变为系统设计师视角,专注于架构与设计意图而非语法细节。与注释驱动相比,对话式编程允许更大范围的任务规划,是迈向目标导向编程的关键过渡阶段。
相关链接
- Ch08-L03 注释驱动编程 让 AI 来填补空白 — 上一个范式,从注释到对话的进阶路径
- Ch08-L05 目标导向编程 让智能体动起来 — 对话式进阶到目标式,最终由 Agent 自主执行
- Ch04-L11 技术洞察 像管理者一样思考 — 描述期望结果而非指定步骤,与 AI 管理者思维高度一致
- Ch04-L04 学习要点 1 有选择地把任务委托给 AI — 对话式编程是精准委托 AI 完成任务的实践方式
原文
Lesson 62 of 68 面向提示词的编程:通过对话写出更好的代码 / Prompt-Oriented Programming: Chatting Your Way to Better Code
当你只依赖注释时,整个过程更像是在指挥一位抄写员,而不是在进行对话。相比之下,面向提示词的编程让 Cursor 变成了真正的对话伙伴。你不再把指令深埋在代码里,而是直接通过聊天窗口与它交流——提出修改请求、抛出问题、探索想法。这就像从键盘前退后一步,把你的需求像向一位博学的同事那样讲清楚,而这种转变会促使你进行更抽象、更具战略性的思考。
设想你有一个函数,能跑但并不出色,而你又不太确定该如何改进它。打开聊天界面后,你可以这样输入:“你能重写这个方法,让它高效处理更大的数据集吗?”Cursor 会理解你代码库的上下文,审视当前的逻辑,并给出修改建议。如果哪里看着不对劲,就直接说出来:“这个写法看起来很吃内存,能不能换成流式方案?”你正在与它来回讨论,得到的结果不只是逐行的改进,而是对代码架构更整体的优化。
这种方式同样适用于更大型的任务。比如你需要修改一个横跨多个文件的功能,或者把一个新模块集成到现有代码库中。你不必费力地在项目的每个角落添加注释,只需告诉 Cursor 你想要什么:“添加一个新的日志层,记录所有交易,并将它们存储到独立的 JSON 文件中。”Cursor 可以在多个文件之间跳转,提出相关的代码片段,并展示它们如何组合在一起。聊天形式让你能够在更高的抽象层级上指挥 AI,这会促使你超越眼前的语法细节,把注意力放在设计和意图上。
不妨想象一下当下的场景:你的编辑器已经打开,一侧是你熟悉的代码文件,另一侧是一个等待你下达指令的聊天面板。你输入一段提示词,描述你期望的结果——更好的性能、新增的功能,或更健壮的错误处理——Cursor 便处理你的请求。它返回的建议并不局限于某个函数或某段代码。把它想象成这样一位伙伴:他既懂得如何写代码,又记得整个代码库,并能在其中迅速穿梭。随着时间的推移,这种对话式的协作层会重塑你的开发体验,让你感觉自己不再是一名机械师,而更像一位系统设计师。
你也可以请它做一次回顾:“总结一下你刚才所做的修改,并解释为什么现在的代码更易于维护。”Cursor 会给出概述,帮助你确认自己理解了这些建议背后的逻辑。如果有什么地方让你困惑,就请它进一步说明。当你越来越习惯这种交互方式时,你会发现自己写的明确指令越来越少,花在打磨整体设计上的时间越来越多,而 Cursor 则会基于你们不断深入的对话来补全细节。
English Original
When you relied solely on comments, the process felt more like guiding a scribe than engaging in a dialogue. Prompt-oriented programming, by contrast, turns Cursor into a truly conversational partner. Instead of hiding instructions deep in the code itself, you talk directly through the chat window—requesting changes, posing questions, and exploring ideas. It’s like stepping back from the keyboard and explaining what you need as if to a knowledgeable colleague, and this shift encourages more abstract, strategic thinking.
Imagine you have a function that’s fine but not great, and you’re not entirely sure how to improve it. With the chat interface open, you can type something like, “Can you rewrite this method to handle larger datasets efficiently?” Cursor understands the context of your codebase, reviews the current logic, and suggests changes. If something feels off, say so: “This approach looks memory-intensive. Can we try a streaming solution?” You’re engaging in a back-and-forth, and the result is not just a line-by-line improvement, but a more holistic refinement of your code’s architecture.
This approach scales to more substantial tasks. Perhaps you need to modify a feature that spans multiple files or integrate a new module into an existing codebase. Instead of painstakingly adding comments in every corner of the project, you tell Cursor what you want: “Add a new logging layer that records all transactions and store them in a separate JSON file.” Cursor can hop across files, propose relevant code snippets, and show how they fit together. The chat format lets you guide the AI at a higher level of abstraction, and this encourages you to think beyond immediate syntax and focus on design and intent.
Try visualizing what’s happening: your editor is open, and on one side you see your usual code files. On the other side, a chat panel awaits your instructions. You type a prompt describing the outcome you’d like—improved performance, additional features, or more robust error handling—and Cursor processes your request. It returns suggestions that aren’t limited to a single function or block of code. Think of it as someone who not only knows how to code but also remembers the entire codebase and can swiftly navigate it. Over time, this conversational layer transforms your development experience, making you feel less like a mechanic and more like a systems designer.
You might also ask for a recap: “Summarize the changes you just made and explain why the code is now more maintainable.” Cursor responds with an overview, helping you ensure you understand the rationale behind the suggestions. If something feels confusing, ask for clarification. As you grow more comfortable with this mode of interaction, you’ll find that you’re writing fewer explicit instructions and spending more time refining the big picture, with Cursor filling in the details based on your evolving conversation.