你该用 AI 生成哪种类型的代码?
1 分•作者: hopa•3 个月前
我(以及许多人)一直在思考“使用 AI 完成哪些任务是最好的”。
我个人一直在使用的框架是,当你满足以下条件时,就应该使用 AI 生成代码:
1. 代码**易于验证**
2. 人类是否理解代码并不重要
我发现最适合 AI 生成的是纯函数级别的代码(易于验证 + 没必要理解实现细节,只要你理解接口即可)。
我尝试过生成整个服务或应用程序,但这通常违反了规则 1 - 验证整个应用程序是否“正确”是**困难的**,因为“正确”的定义并不明确——例如,是否存在内存泄漏,是否安全,是否能够被监控等等。
我很想知道大家对这个话题的看法。使用 AI 完成的任务越大,节省的时间就越多,但也越有可能在生成的代码中存在灾难性的错误。
遵循这些规则的一个副作用是,生产力提升并不大——最多可能只有 20-30%。
我真的很好奇是否有人找到了一个平衡点——在不损失正确性的前提下实现显著的加速。
查看原文
I (and many people) have been thinking a lot about "what are the best tasks to do using AI."
My personal framework I've been using is, you should use AI to generate code when:
1. The code is <i>easy to validate</i>
2. It is not important that a human understands it<p>I find that the best thing to AI generate is something on the level of a pure function (easy to validate + not necessarily important to understand implementation as long as you understand the interface).
I've tried doing things like generating whole services or applications, but those often violate rule 1 - it's <i>hard</i> to validate an entire application behaves "correctly" when "correctly" isn't really well defined - i.e., are there memory leaks, is it secure, is it able to be monitored, etc.<p>I'm curious of others thoughts on this topic. The larger the task you complete using AI, the more time savings, but also the more likely that a catastrophic error exists in the generated code.
A side effect of following these rules is there is not that much of a productivity gain - maybe 20-30% at most.<p>I'm really interested if anyone has found a way to strike a balance here - significant speedup without losing correctness.