如果人工智能编码正在降低你的代码质量,说明你的质量管理方式不对。
If AI coding is lowering your code quality, you're not managing quality right

原始链接: https://www.i-kh.net/p/if-ai-coding-is-lowering-your-code

尽管有些人担心 AI 编程代理会以牺牲质量为代价换取速度,但采取分层防御的方法实际上可以将开发者的产出提高 2-3 倍,同时减少错误。关键在于将 AI 融入开发生命周期的每一个阶段: * **规范驱动开发:** 在开始编码之前,利用 AI 主动识别边缘情况和需求差距。 * **测试驱动开发 (TDD):** 利用代理在实现功能前编写全面的测试套件,以确保高覆盖率。 * **自动化审查流程:** 利用 AI 进行安全性检查、代码规范检查 (linting) 和重构,以保持代码标准并消除“AI 味”。 * **分层验证:** 在自动化 PR 审查的基础上,辅以针对复杂逻辑的人工抽查。 * **可观测性:** 使用 AI 驱动的日志和错误跟踪工具,自动诊断并修复生产环境中的错误。 通过将 AI 视为质量控制的引擎而不仅仅是代码生成器,团队可以实施比以往更深入、更频繁的检查。这种策略确保了更快的交付不会损害可靠性,使开发者能够在保持高标准的同时显著加快工作流程。

关于“AI 编程是否会降低代码质量”的 Hacker News 讨论引发了开发者之间的激烈辩论。 讨论的核心在于“技能问题”:支持者认为,如果 AI 产出的结果不佳,是因为开发者缺乏适当的管理、防护措施或技术标准来有效地引导这些工具。他们主张,通过实施严格的测试、代码检查(linting)和强类型约束,是可以产出高质量代码的。 相反,许多参与者认为这是一种“责怪用户”的心态。批评者指出: * **固有局限性:** AI 具有随机性,无论用户如何输入,往往都会生成难以维护的“垃圾代码”。 * **边际效应递减:** 要达到高质量,需要进行大量的的人工干预(如编写规范、代码审查和监督),这使得所谓的生产力提升在很大程度上被抵消了。 * **企业压力:** 即便开发者关心质量,管理层往往更看重开发速度而非后期维护,从而助长了“凭感觉编程”而非严谨工程的氛围。 * **技能退化:** 一些人认为 AI 降低了准入门槛,使得经验不足的程序员可以在不理解底层代码的情况下快速交付功能,最终导致项目整体健康状况下降。 总的来说,关于 AI 究竟是强大的效率倍增器还是技术债务的源头,社区内部仍存在分歧。
相关文章

原文

One common take on the coding agents that I see goes something like this: “Sure, AI helps you output more code, but won’t the quality suffer?”

It certainly will if you just blindly merge the PRs and send them off to prod. But if you take a thoughtful, layered approach to managing quality, I find that it’s possible to not just keep the number of bugs stable but actually reduce it—while still increasing the output by 2-2x.

Many of these defensive layers are pretty much the same as before Claude/Copilot/Codex/etc. (though they’re made easier now by AI), while others are new. Here’s a defensive setup that I’ve seen successfully used in practice, both on my team and elsewhere.

One of the biggest surprises after I started using spec-driven development was the drop in bugs in the freshly written code. Before spec-driven development, when building, e.g., a new feature, the teams I was on often spent up to a third of the total effort on the post-development “polishing,” i.e., discovering and fixing various bugs. Many of these bugs occurred either because we didn’t foresee certain interactions and edge cases, or because the developer was tired that day and didn’t put in enough thought, or because the designer or PM didn’t think through certain scenarios. Some of these bugs were missed and ended up in production.

After I started using spec-driven development, the number of these bugs in my code sharply dropped, and I’ve seen the same drop for some (but not all) of my teammates. As far as I can tell, the main cause of this drop is one specific step in the process: having the AI review the requirements or the tech design and find any gaps, edge cases, unexpected interactions with the existing code, or other similar problems.

The AI doesn’t get tired and, when prompted right, is a lot less likely to give up hunting for potential issues. If anything, it can sometimes be overzealous, and I have to carefully review its proposed edits to the requirements to make sure that it doesn’t invent any issues that aren’t there.

Coding agents now make test-driven development (TDD) trivial to the point where there’s no reason not to do it. However, it needs to be done right: you don’t want the agent to blindly write passing tests for any bugs it just added to the code. So the best planning and implementation skills I’ve seen usually follow this pattern:

  • Instruct the agent to think through the test scenarios and test cases based on the requirements,

  • Write the test cases,

  • Write the implementation,

  • Test the implementation against the test cases and fix any issues that come up,

  • Maybe backfill any remaining coverage gaps—but again, keeping the requirements in mind.

Also, with the agents writing the tests, there’s no excuse not to shoot for near-universal coverage or to wait on backfilling any missing unit tests.

There’s still no substitute for a human (you, QA, PM, or someone else) actually trying out the feature, going through all the edge cases, and seeing whether everything works as expected or whether you need to make changes.

These manual tests can take a while, especially if the test scenarios take some effort to set up. This is one of the steps that so far has seen only modest gains in productivity, and it’s the main reason that my output has increased only 2-3x instead of something like 10x. Though now that I think about it, there may be a few opportunities for automation here that I’ve missed.

End-to-end (E2E) tests are arguably the most important tests in the codebase because they verify that new changes haven’t broken any existing functionality as experienced by the end user. Ideally, they’d run on the PRs, in the test/stage environments, and in production after every deployment. Ideally, they’d also be maintained by the same developers who write regular code, but I understand that some organizations aren’t really set up for that.

AI does make it easier to write E2E tests, but to do that effectively, it needs access to the tools or MCP servers that let it debug test failures—e.g., a browser tool or MCP access to the logs. However, it’s important to keep in mind that E2E tests aren’t a substitute for manual testing because they’re just a rough, incomplete check that nothing important broke.

I find that coding agents aren’t great at following complex instructions in AGENTS.md or CLAUDE.md. But they do pretty well if you add a separate pass to find and fix specific issues. These can be:

  • Security issues,

  • Finding overcomplicated or duplicated code,

  • Compliance with naming, file organization, or formatting rules,

  • A general code review pass to find any issues with the logic,

  • Overly long comments written in AI-ese instead of regular English,

  • Any other specific things that you’d like to find and fix.

If added to the planning or implementation skills, these can be pretty much “free” additions, adding maybe 5-15 min to the implementation time with no additional attention required.

They can be also added to the PR reviews if you prefer to take a look at the comments before applying any fixes.

I think I’m becoming convinced that for minor tweaks and simple bug fixes, human reviews can become optional. Provided that other defensive layers are still in place.

But for complex changes, I find that it’s still necessary to review AI-written code. I still regularly find big-picture mistakes, missed adverse interactions with other features, overcomplicated or suboptimal implementations, and other problems. Not to mention weird word choices like “mint” instead of “generate” or “stamp” instead of “set.”

AI code reviews have also been a really great addition. On my current team, we run both Claude and Cursor reviews on the PRs, and surprisingly, each of them finds different problems. You can also add other custom reviews from various angles, like security, efficiency, interactions with other repos, and so on, though be aware that AI can be overly nitpicky in its reviews, so it’s important to also have a pass where another agent prunes the proposed AI-generated PR comments that aren’t actually meaningful.

Once the code is in production, at a minimum, it’s good to have someone periodically scroll through the logs or watch any user recordings in something like Fullstory, or review various dashboards that track error rates, latencies, and other issues.

Even better would be an error tracking service like Sentry or GCP’s Error Reporting that detects and deduplicates errors.

The best approach, however, would be to then have Claude/Cursor/whatever auto-diagnose these errors, figure out the root cause, and make PRs with the proposed fix.

I’m sure I’ve missed other important components of maintaining high quality, but the main idea is that with the right set of defensive layers, the increased output doesn’t have to come at the cost of reliability. If anything, coding agents now make it cheaper to add more and deeper checks than before: more tests, more review passes, faster diagnosis of production issues.

So if you’re sufficiently focused on quality, I think it’s entirely possible to double the delivery speed while keeping the bugs under control. Or maybe even reducing them.

联系我们 contact @ memedata.com