AI 编程 4.0 · 优秀 2026-10-07 · 文章

How to read code

Sean Goedecke 把读代码讲成可训练的方法:代码与书不同,顺序由机器决定且多以 diff 形式被读,所以不能按行顺序通读他借 dyadic scanning 给出多 pass 读法先抓整体结构,再沿调用关系追子结构,最后端到端通读抓之前漏掉的怪味道文中还回应能否让 LLM 替我读:他今年读 AI 生成代码反复遇到的是 alignment 问题agent 为一个无害的 race condition 写出 3000 行 machinery 去修,AI 让 review 反而更重要

打开原文回到归档

How to read code

  • ID: 5c1dd850
  • 原文链接: https://seangoedecke.com/how-to-read-code/
  • 作者: Sean Goedecke
  • 日期: 2026-10-07
  • 分类: coding
  • 来源类型: article
  • 标签: code-reading, code-review, llm-generated-code, engineering-practice
  • 质量评分: 4/5
  • 抓取时间: 2026-10-08T15:41:20Z

中文导读

Sean Goedecke 把读代码讲成可训练的方法:代码与书不同,顺序由机器决定、且多以 diff 形式被读,所以不能按行顺序通读。他借 dyadic scanning 给出多 pass 读法——先抓整体结构,再沿调用关系追子结构,最后端到端通读抓之前漏掉的怪味道。文中还回应『能否让 LLM 替我读』:他今年读 AI 生成代码反复遇到的是 alignment 问题——agent 为一个无害的 race condition 写出 3000 行 machinery 去『修』,AI 让 review 反而更重要。

为什么值得关注

把『AI 让代码 review 反而更重要』讲成了具体反例,比一般性劝告有用得多。

关键信息

  • 代码与英语文本的差异:顺序由机器决定、通常以 diff 形式被读
  • 方法:dyadic scanning——整体结构 → 调用子结构 → 端到端通读,多 pass 各追一条线
  • LLM 部分:alignment 失败案例——三行改动引出 3000 行『修复』machinery
  • 发布:Sean Goedecke 博客,2026-10-07

English Summary

Sean Goedecke turns code reading into a trainable method: unlike books, code is ordered by the machine and usually read as a diff, so do not read it line by line. Borrowing 'dyadic scanning', he suggests multiple passes - grasp overall structure first, then trace call substructures along one path, then read end-to-end for missed code smells. On 'can't the LLM read it for me': from a year of reading AI-generated code he keeps hitting alignment failures - given a three-line change, an agent spots a harmless race condition and writes 3000 lines of machinery to 'fix' it - so review matters more, not less.

原文节选

Everyone knows how to read a book. Beginning at the first page, you read each word in order1, stopping periodically to think, until you arrive at the last word on the last page. That’s how you read a newspaper article, or a poem, or an email. Why would reading code be any different?

Why code is different

English text is designed to be read in order. In fact, there are almost no constraints on the order of a text aside from how you want the reader to consume it. In writing this post, I could put the ideas I want to convey in any order I like. Code, on the other hand, is designed to be _run_ by a computer. The order is thus primarily determined by non-human factors. I cannot simply move2 a line of code to the beginning of a file or function because I think it provides a better introduction to the program for human readers.

The other big difference is that English text is always read as a final product, while code is usually read as a _diff_. We software engineers spend most of our time reading subtle changes to existing code, not brand-new programs. Imagine if reading this post was like that. You would read each successive draft in the order I wrote them, consuming the post as a changed sentence here and a new sentence there. It would be easy to lose track of the overall flow.

The third reason — and I say this as a lover of literature and poetry — is that code is much more structurally complex than English texts. Even famously difficult books are _syntactically_ simpler than most computer programs (for instance, grammatical dependencies are largely bounded by a single paragraph, while code dependencies can stretch across the entire codebase). Their primary difficulty lies in understanding the nuances of human nature being discussed, not in understanding what each word’s grammatical function is3. Large codebases are also just longer: _War and Peace_ contains around 600,000 words, while most large modern codebases have that many _lines_.

People are bad at reading code

As I’ve said many times, large computer programs are simply too complex for a single person to fully understand. Reading code in a large program is thus a process of _compromise_: of deciding which parts to thoroughly grasp and which parts to gloss over; or of portioning out your finite mental capacity across the codebase.

Because of all this, most people read code very badly. They struggle through it front-to-back, like a book, and lose track of the execution flow. Or they just read through the diff and miss the significance of un-edited parts of the code4. Or they simply are defeated by the complexity, give up and just guess what it means. How can you do better?

How I read code

The best article I’ve read about reading code is this piece about reading mathematics papers, which have a similar structure. The author describes a technique called “dyadic scanning”. Instead of reading slowly and sequentially, you make several passes: first to figure out the overall structure, then the sub-structure, and then finally the details.

For code5, this means reading out-of-order. I like to pick an important path (say, the happy path for the feature introduced in the dif

Obsidian Notes

  • 内容由 seangoedecke.com(opencli web read 抓取全文) 生成(opencli-first 成功)。
  • 中文导读与价值判断锚定在原文全文与当日 AK-RSS 摘要上;节选仅保留正文文字。