2025-06-24 08:01:00
原文: https://blog.nilenso.com/blog/2025/05/29/ai-assisted-coding/
作者: Atharva Raykar
译者: Gemini 2.5 Pro
2025年5月29日
AI should be adopted by serious engineering teams that want to build thoughtful, well-crafted products. This requires skillful usage of these tools. Our obsession with building high-quality software for over a decade has driven us to figure out how this new way of building can result in better products.
那些想要构建深思熟虑、精心打造的产品的严肃工程团队,应该拥抱 AI。但这需要对这些工具有技巧地使用。十多年来,我们对构建高质量软件的执着,驱使我们去探索这种新的构建方式如何能产出更好的产品。
Building with AI is fast. The gains in velocity are important, because when harnessed correctly, it allows teams to tighten feedback loops with users faster and make better products.
用 AI 构建是很快的。速度的提升至关重要,因为如果利用得当,它能让团队更快地缩短与用户的反馈循环,从而做出更好的产品。
Yet, AI tools are tricky to use. Hold it wrong, and you can generate underwhelming results, worse still, slow down your velocity by drowning your project in slop and technical debt.
然而,AI 工具的使用也很有技巧。用错了方法,你可能会得到平庸的结果,更糟的是,你的项目可能会陷入垃圾代码和技术债的泥潭,从而拖慢你的开发速度。
This living playbook is based on our experience working with AI tools in the messy trenches of production software, where no one can afford to get away with vibes. I hope other teams can learn and benefit from our findings.
这份动态更新的实践手册,源于我们在生产软件混乱的战壕中使用 AI 工具的经验——在这里,没人能凭感觉蒙混过关。我希望其他团队能从我们的发现中学习并受益。
To make AI good, get good yourself. AI is a multiplier. If you are a small coefficient, you won’t see much gain. If you are a negative coefficient, expect negative gains.
要想让 AI 发挥好,先要让自己变得优秀。AI 是一个放大器。如果你这个系数本身很小,你不会看到多少增益。如果你是个负系数,那么等着迎接负增长吧。
What I have noticed is that the best and most experienced engineers are able to extract a lot more out of AI tools. There are several reasons for this:
我注意到,最优秀、经验最丰富的工程师能够从 AI 工具中获得多得多的价值。这有几个原因:
Therefore, embody the care of a craftperson. At the end of the day, you should produce artifacts you are proud of, even if the AI assisted in making it. This has translated well into the output I am seeing from these systems.
因此,要体现出工匠般的用心。说到底,你应该产出让自己引以为豪的作品,即使 AI 参与了制作过程。这种态度很好地转化为了我从这些系统中看到的产出质量。
Here’s an example. This prompt is not unreasonable but not particularly thoughtful:
举个例子。下面这个 prompt 不算离谱,但也没有经过深思熟虑:
Write a Python rate limiter that limits users to 10 requests per minute.
写一个 Python 的限流器,限制用户每分钟 10 次请求。
I would expect this prompt to give okay results, but also miss some edge cases, good practices and quality standards. This is how you might see someone at nilenso prompt an AI for the same task:
我预料这个 prompt 会给出还算可以的结果,但也会漏掉一些边界情况、良好实践和质量标准。而在 nilenso,你可能会看到有人这样向 AI 提问同样任务:
Implement a token bucket rate limiter in Python with the following requirements:
- 10 requests per minute per user (identified by `user_id` string)
- Thread-safe for concurrent access
- Automatic cleanup of expired entries
- Return tuple of (allowed: bool, retry_after_seconds: int)
Consider:
- Should tokens refill gradually or all at once?
- What happens when the system clock changes?
- How to prevent memory leaks from inactive users?
Prefer simple, readable implementation over premature optimization. Use stdlib only (no Redis/external deps).
用 Python 实现一个令牌桶限流器,要求如下:
- 每个用户(通过 `user_id` 字符串识别)每分钟 10 次请求
- 线程安全,支持并发访问
- 自动清理过期条目
- 返回一个元组 (allowed: bool, retry_after_seconds: int)
请考虑:
- 令牌是应该逐渐补充还是一次性补满?
- 当系统时钟发生变化时会怎样?
- 如何防止因不活跃用户导致的内存泄漏?
优先选择简单、可读的实现,而不是过早优化。仅使用标准库(不要用 Redis 或其他外部依赖)。
Guess which prompt is going to better achieve the program designer’s intent?
猜猜看,哪个 prompt 能更好地实现程序设计者的意图?
A technique that has worked well for us is metaprompting. I prompt the model with a simple task and ask it to help surface tradeoffs and edge cases. Then I turn it into a tech spec and hand it off to another LLM agent to execute. Even the “better prompt” I shared above is a result of asking the AI to come up with a good prompt. From my experience, models have become good at prompting themselves.
一个对我们很有效技巧是元提示(metaprompting)。我先给模型一个简单的任务,然后让它帮我发现其中的权衡和边界情况。接着,我把这些内容整理成一份技术规格,再交给另一个 LLM 代理去执行。就连我上面分享的那个“更好的 prompt”,也是我让 AI 帮我构思一个好 prompt 的结果。根据我的经验,模型已经变得很擅长提示自己了。
The mechanics of what works for these tools are in flux, but one robust principle is to really work on yourself to be a good engineer. Your habits will quickly pass on to the AI systems you work with. The reason this works is because what helps the human helps the AI.
这些工具的有效机制在不断变化,但有一个稳健的原则是:努力提升自己,成为一名优秀的工程师。你的习惯会迅速传递给你合作的 AI 系统。这之所以有效,是因为对人有益的东西,对 AI 同样有益。
I shall clarify what software engineering is, something I found worth revisiting in the light of disruption from AI advancements.
我想在此阐明一下什么是软件工程,在 AI 进步带来的颠覆之下,我觉得这个问题值得重新审视。
Software engineering is not about writing code. Or at least, that’s not the defining characteristic, much like how writing is not wrist exercises with ink on paper.
软件工程并不仅仅是写代码。至少,这并非它的决定性特征,就像写作不只是在纸上用墨水做手腕运动一样。
To me software engineering is the art and science of maintaining a large body of well-defined mental models that achieve a business or economic need. Much of the work is around crafting and curating these large, complex sociotechnical systems, and code is just one representation of these systems.
对我而言,软件工程是这样一门艺术和科学:维护一个庞大且定义清晰的心智模型集合,以满足商业或经济需求。大部分工作都围绕着构建和维护这些庞大、复杂的社会技术系统,而代码只是这些系统的一种表现形式。
Until AI is good enough to engulf this whole sociotechnical system and expel out all the humans cultivating it, it has to participate and benefit from this very system. In simpler words: AI thrives far, far better in an environment in which a human would also thrive. Which means your team’s software fundamentals should be strong.
在 AI 强大到足以吞噬整个社会技术系统并驱逐所有培育它的人类之前,它必须参与并受益于这个系统本身。简单来说:在一个能让人类茁壮成长的环境中,AI 的成长会好得多得多。这意味着,你团队的软件基础必须扎实。
A system in which AI thrives is one with markers of a high quality team and codebase. These are:
一个能让 AI 蓬勃发展的系统,通常也带有一个高质量团队和代码库的标志。这些标志包括:
Today’s AI can and will make use of all these things to make things “just work”. When I give a coding agent a task, it keeps correcting itself in the agentic loop by running the test cases and static analysis tools. This greatly reduces the hand-holding and intervention needed to get work done.
今天的 AI 能够并且将会利用所有这些东西来让事情“自动搞定”。当我给一个编码代理一项任务时,它会在代理循环中通过运行测试用例和静态分析工具来不断自我修正。这极大地减少了完成工作所需的人工指导和干预。
A rich environment and context helps the AI work better.
一个丰富的环境和上下文有助于 AI 更好地工作。
Here’s an anecdote: when I was working at a project that had two services, one of them had all of the things I described above—good tests, well-documented changes, consistent patterns in the code, lots of checks and guardrails. The other service was messier and had none of the above. Our AI coding assistant struggled to complete a task of equal difficulty on the latter codebase when compared to the former! This is likely because the messier codebase was as confusing for the AI as it would be for a human. There were mixed signals about the right way to do things.
这里有一个轶事:我曾参与一个有两个服务的项目,其中一个服务具备我上面描述的所有优点——良好的测试、文档齐全的变更、一致的代码模式、大量的检查和防护措施。而另一个服务则混乱不堪,上述优点一概没有。我们的 AI 编码助手在后一个代码库上完成一个同等难度的任务时,遇到了极大的困难,远超前一个!这很可能是因为那个混乱的代码库对 AI 来说,就像对人类一样令人困惑。关于做事的正确方式,它收到了太多混杂的信号。
Now that I have outlined the general strategy, here are some tactics that have helped me.
既然我已经概述了通用策略,下面是一些对我有帮助的具体战术。
RULES.md
file. Symlink this file to agent specific rules files such as .cursorrules
, .windsurfrules
, claude.md
, agents.md
etc
RULES.md
文件中。然后将此文件软链接到特定代理的规则文件,如 .cursorrules
、.windsurfrules
、claude.md
、agents.md
等。
There’s a good reason to do this—documentation is now cheap to generate and feeds back into making your LLMs (and humans) on the project a lot more effective.
这样做有一个很好的理由——文档的生成成本现在很低,而它又能反哺项目,让你的 LLM(和人类)工作得更高效。
LLMs greatly reduce the cost of creating lubricants for all the minor friction points that teams run into on a daily basis.
对于团队日常遇到的各种微小摩擦点,LLM 极大地降低了为其创造“润滑剂”的成本。
git log -p <range>
) of each feature to the AI to explain the changes and how to deploy them. Some tools can already do this for you.git log -p <range>
) 提供给 AI,让它解释变更内容以及如何部署。一些工具已经可以为你做这件事了。This is a huge shift in how we write software, and I believe it warrants some changes to ideas that were previously considered common wisdom.
这是我们编写软件方式的一次巨大转变,我相信,这值得我们去修正一些过去被认为是普通常识的观念。
Firstly, It’s less valuable to spend too much time looking for and building sophisticated abstractions. DRY is useful for ensuring patterns in the code don’t go out of sync, but there are costs to implementing and maintaining an abstraction to handle changing requirements. LLMs make some repetition palatable and allow you to wait a bit more and avoid premature abstraction.
首先,花费过多时间去寻找和构建复杂的抽象,其价值已经降低了。DRY 原则对于确保代码模式不失同步很有用,但为了应对需求变化而实现和维护一个抽象是有成本的。LLM 让某些重复变得可以接受,并允许你多等一等,以避免过早的抽象。
Redoing work is now extremely cheap. Code in the small is less important than structural patterns and organisation of the code in the large. You can also build lots of prototypes to test an idea out. For this, vibe-coding is great, as long as the prototype is thrown away and rewritten properly later.
返工的成本现在极其低廉。微观层面的代码,其重要性已不如宏观层面的结构模式和代码组织。你也可以构建大量的原型来测试一个想法。为此,凭感觉编码(vibe-coding)是很棒的,只要这个原型用完即弃,之后再被妥善地重写。
Working with LLMs also lets you take advantage of the generator-verifier gap. Often it’s easier to verify and fix things than it is to produce them from scratch. This reduces activation energy to try new things.
与 LLM 合作,还能让你利用“生成者-验证者差距”。通常情况下,验证和修复问题比从头创造要容易得多。这降低了尝试新事物的启动门槛。
Tests are non-negotiable, and AI removes all excuses to not write them because of how fast they can belt them out. But always review the assertions!
测试是不可协商的,而 AI 消除了所有不写测试的借口,因为它们生成测试的速度飞快。但一定要审查那些断言!
Programming with LLMs - David Crawshaw
Here’s how I use LLMs to help me write code - Simon Willison
How I use “AI” - Nicholas Carlini
2025-06-13 08:00:00
看似挺简单的基础能力,其实很挺复杂的。
2025-06-05 08:00:00
Prompt Caching 是省钱(Token)和提升 AI 响应速度的必须要考虑的一点。 很多人可能会忽略,但是它很重要。