Reducing the cognitive load of AI changes
Reducing the cognitive load of AI changes
降低 AI 变更带来的认知负荷
When reviewing large amounts of AI-generated code, I often find that the LLM chooses terms for abstractions that do not always map to my own choices. 在审查大量 AI 生成的代码时,我经常发现大语言模型(LLM)为抽象概念所选择的术语,并不总是与我自己的习惯相符。
For instance, what it may call a MutationIntent might personally be more natural to me as an EditRequest.
例如,它可能将其称为 MutationIntent(变更意图),而对我个人而言,EditRequest(编辑请求)可能更自然。
Because the LLM’s choice of words is not my ideal choice, I have to do a mental lookup of what it means every time I see it, which adds cognitive load. 由于 LLM 的用词并非我的首选,每次看到这些词时,我都需要在脑海中进行一次“翻译”来理解其含义,这增加了我的认知负荷。
This may seem like a small friction, but the cognitive load accumulates when considering how dozens of new terms interact in unfamiliar code. 这看起来可能只是一个小摩擦,但当考虑到几十个新术语在陌生的代码中如何相互作用时,认知负荷就会不断累积。
I can only hold a finite number of these semantic lookups in my head before I start misinterpreting how things work. 我脑海中能容纳的此类语义转换是有限的,一旦超过这个限度,我就开始误解代码的运行逻辑。
To minimize this, before review, I post-process AI changes with this prompt: 为了尽量减少这种情况,在审查之前,我会使用以下提示词对 AI 的变更进行后处理:
Please review the changes and extract any unconventional or bespoke terms used for abstract objects, processes and concepts. Create a temporary markdown file with each term, its meaning and why it was chosen, and some proposed alternative terms for it. I will then use this markdown file to confirm the term choice or to provide my own custom term. You will then incorporate any changes. The goal here is to map your language choices to my own language choices so that I can understand the concepts more easily. 请审查这些变更,并提取出所有用于抽象对象、流程和概念的非常规或定制术语。创建一个临时的 Markdown 文件,列出每个术语、其含义、选择该术语的原因,以及一些建议的替代术语。随后,我将使用该 Markdown 文件来确认术语选择或提供我自己的自定义术语。你将据此合并所有更改。此举的目标是将你的语言选择映射到我自己的语言习惯上,以便我能更轻松地理解这些概念。
I then go through and confirm term choices. The AI does find-and-replace everywhere, including documentation. 接着,我会逐一确认术语选择。AI 会在全局(包括文档)执行查找和替换。
The resulting code is much easier to review because now it’s written more like it came from my brain. 最终生成的代码审查起来容易多了,因为现在的代码读起来更像是出自我的手笔。