每日科技文摘Daily Tech Digest

每日科技文摘Daily Tech Digest

发布于 2026-10-13Published 2026-10-13

今日深读Today's Deep Read

今日深读:「抱歉,你还是得自己思考」——从 DHH 的 AI 重写实验说起Today's Deep Read: "Sorry, But You Still Have to Think" — What DHH's AI Rewrite Experiment Really Shows

2026 年 10 月,Rails 之父 DHH 让 AI 代理把聊天应用 Campfire Once 分别重写成 Rust、Elixir 和 Go,然后像办拍卖会一样发布性能对比;他自己坦白「受不了读和写 Rust」。一份「不用读代码」的产物长什么样?资深工程师 Piotr Sarnacki 把三个重写版逐行看过,写成了这篇《抱歉,但你还是得思考》。他的答案很直白:你不思考,机器就替你思考,只是你不会立刻察觉。In October 2026, DHH — the creator of Rails — had AI agents rewrite his chat app Campfire Once in Rust, Elixir and Go, then published performance comparisons like an auction, while admitting he 'can't stand reading or writing Rust.' So what does a 'never read the code' product actually look like? Senior engineer Piotr Sarnacki read all three rewrites line by line and wrote 'I'm sorry, but you still have to think.' His answer is blunt: if you stop thinking, the machine thinks for you — you just won't notice right away.

第一类坑最隐蔽:提示里没说明白的事情,全靠抛硬币。要不要保持向后兼容?延迟和吞吐谁优先?崩溃时丢通知可不可以接受?三个重写版给出了不同的默认答案——Rust 版为了缓存方便干脆删掉 CSRF token,还把 Redis 换成进程内队列;Elixir 版则贴着原版走。于是「跨语言对比」从第一天起就失真了:这些差异根本不是语言造成的,而是代理在不完整提示下替你做的决定。The first trap is the subtlest: anything your prompt leaves unstated gets decided by coin flip. Backwards compatibility? Latency versus throughput? Losing notifications after a crash, acceptable? The three rewrites answered differently — the Rust version dropped the CSRF token to make caching easier and swapped Redis for in-process queues, while the Elixir version stuck close to the original. So the 'language comparison' was broken from day one: these differences are not language-specific at all. They are decisions the agent made for you under an underspecified prompt.

第二类坑要读代码才看得见:Rust 版里有些查询和锁是同步的,却混在异步任务里跑。Rust 的异步是协作调度——任务不主动让出,同一线程上的其他任务全部停摆。一次 100 毫秒的 SQL,或一把拿住 10 毫秒的普通互斥锁,就能让整条 worker 线程干等。讽刺的是,社区广泛批评的却是 Elixir 版「把所有 SQL 排队串行执行」;同样的毛病,Rust 版藏得更深。The second trap only shows up if you read the code: some database queries and locks in the Rust version are synchronous, yet run inside async tasks. Rust's async scheduling is cooperative — if a task doesn't yield, every other task on the same worker thread stalls. A 100-millisecond query, or a plain mutex held for 10 milliseconds, blocks the whole thread. Ironically, the widely mocked flaw was Elixir's 'one process handling all SQL sequentially'; the same disease hides deeper in the Rust rewrite.

第三类坑在基准测试本身:闭环压测是 N 个客户端「拿到响应才发下一条」,测的是吞吐;而聊天软件的真实负载更像大量用户同时发消息,要用恒定到达率的开环测试。Zach Daniels 重跑发现,Rust 版在高负载下新通知送达率只有 1%;Sarnacki 用恒定 100 POST/s 重测,Elixir 版在不过载时 100% 送达、Rust 版处理着约四倍的请求量——差异是背压策略与负载模型,不是「哪门语言并发更强」。Elixir 的并发确实更省心,但代价是内存和低层控制——rustler 的存在本身就说明问题。The third trap is the benchmark itself. A closed-loop test — N clients each waiting for a response before sending the next — measures throughput; but real chat traffic is many users acting at once, which calls for an open-loop test at a constant arrival rate. Rerun that way, the Rust version delivered only 1% of new notifications under heavy load, while Elixir delivered 100% of a smaller event volume. The difference is backpressure policy and load model, not 'which language does concurrency better.' Elixir's concurrency is genuinely more ergonomic, but it pays in memory and loss of low-level control — rustler exists for a reason.

这篇文章真正的问题在这里:「AI 能写代码」和「编程被解决了」之间,隔着整个「你还得思考」的距离。读代码、追问根因、选对测量方法,这些过去被当成程序员的苦役,如今被证明恰恰是人不可替代的部分。代理交付的从来不只是代码,还有一批沉默的决定——你不拆开盲盒,账单就寄给你的用户。The real takeaway: between 'AI can write code' and 'coding is solved' sits the whole distance of 'you still have to think.' Reading the code, chasing root causes, choosing the right measurement — duties long treated as drudgery now turn out to be the irreplaceable part. An agent delivers not just code but a pile of silent decisions; if you never open the box, the bill goes to your users.

AI 思考AI Thoughts

数学之美Mathematical Beauty

每日 Lean 谜题 · 周二Daily Lean Puzzle · Tuesday ★★☆☆☆☆☆

每日 Lean 谜题(★2):高斯求和——把数列折回来加Daily Lean Puzzle (★2): Gauss's Sum — Fold the Sequence and Add

证明:对任意自然数 $n$,都有 $2 \cdot \sum_{i \in \mathrm{range}(n+1)} i = n \cdot (n+1)$,即 $2 \cdot (0 + 1 + 2 + \cdots + n) = n(n+1)$。Prove: for every natural number $n$, $2 \cdot \sum_{i \in \mathrm{range}(n+1)} i = n \cdot (n+1)$, i.e. $2 \cdot (0 + 1 + 2 + \cdots + n) = n(n+1)$.

这就是高斯少年故事的原型——传说小学老师让全班算 $1$ 加到 $100$,小高斯秒出 $5050$(故事版本从 $1$ 开始、不乘 $2$;Lean 里从 $0$ 求和并把 $2$ 留在左边,正好避免整除问题。你能用「折回来加」的办法证明它,也可以用归纳法——两种都要)。This is the archetype of the young Gauss story — a teacher supposedly asked the class to sum $1$ through $100$ and Gauss answered instantly with $5050$ (the school-tale starts at $1$ without the factor $2$; Lean sums from $0$ and keeps the $2$ on the left, neatly avoiding division. Prove it by 'folding and adding' — and also by induction; do both.)

Lean 形式化陈述(把 sorry 换成你的证明):The statement in Lean (replace sorry with your proof):

-- level: 2
import Mathlib
/-! Gauss's sum: prove $2(0 + 1 + \cdots + n) = n(n+1)$. -/
theorem gauss_sum (n : ℕ) : 2 * ∑ i ∈ Finset.range (n + 1), i = n * (n + 1) := by
  sorry

在浏览器中挑战 ▶Try it in your browser ▶ 下载题目 .leanDownload puzzle .lean

提示Hint

别急着算和:$n(n+1)$ 这个形状已经暗示了「成对」——试试把 $0, 1, \dots, n$ 和倒写的 $n, \dots, 1, 0$ 上下相加。Lean 路线:对 $n$ 归纳,归纳步先把 $\mathrm{range}(k+2)$ 里最大的那一枚拆出来。Don't rush to compute: the shape $n(n+1)$ already whispers 'pairs' — add the sequence $0, 1, \dots, n$ to the same sequence written backwards. Lean route: induct on $n$, and in the step peel off the largest element of $\mathrm{range}(k+2)$.

答案与讲解Solution & walkthrough
  1. 第一步(人类的招——折回来加):故事版 $1+\cdots+100$:倒写一遍再上下相加,每列都是 $101$,共 $100$ 列,总和的两倍是 $100 \times 101$。一般化:$0,1,\dots,n$ 与倒序逐位相加每对得 $n$,共 $n+1$ 对,得 $2S = n(n+1)$。谜题 statement 里那个「$2$」,正是这个方法自然留下的指纹。Step 1 (the human move — fold and add): in the story version $1+\cdots+100$, write the sum backwards underneath and add column by column: every column is $101$, there are $100$ columns, so twice the sum is $100 \times 101$. Generalize: $0,1,\dots,n$ plus the reversed copy pairs every position to $n$ across $n+1$ positions, giving $2S = n(n+1)$. That '2' in the puzzle's statement is the fingerprint of exactly this method.
  2. 第二步(机器要的另一条路——归纳):计算机代数不擅长「再抄一遍数列」这种全局戏法,它擅长递推:基例 $n=0$ 时左边 $2 \cdot 0$、右边 $0 \cdot 1$,都等于 $0$。Step 2 (the other road a machine prefers — induction): algebra systems are bad at global tricks like 'copy the sequence and flip it,' but great at recursion: base case $n=0$ — left side $2 \cdot 0$, right side $0 \cdot 1$, both zero.
  3. 第三步(Lean 怎么写基例):`induction n with` 起手,`| zero => simp`——目标 $2 \cdot \sum_{i \in \mathrm{range}(1)} i = 0$ 里 range 拆完只剩空和,`simp` 顺手化简掉了。Step 3 (base case in Lean): open with `induction n with`, then `| zero => simp` — the goal $2 \cdot \sum_{i \in \mathrm{range}(1)} i = 0$ collapses because the range sum empties out, and `simp` finishes it.
  4. 第四步(Lean 归纳步,一行一个数学动作):目标从 $k$ 走到 $k+1$,先把和的最后一项拆出来:`rw [Finset.sum_range_succ]` 对应数学上「$\sum_{i \le k+1} = \sum_{i \le k} + (k+1)$」;`mul_add` 把 $2$ 乘进两项,对应分配律;再用归纳假设 `ih`(即 $2\sum_{i \le k} i = k(k+1)$)替换掉第一项;剩下 $k(k+1) + 2(k+1) = (k+1)(k+2)$,这是环上的多项式恒等式,`ring` 一键收工。Step 4 (the induction step, one math move per tactic): going from $k$ to $k+1$, peel the last term: `rw [Finset.sum_range_succ]` is exactly 'sum through $k+1$ = sum through $k$ plus $(k+1)$'; `mul_add` distributes the $2$; rewriting with `ih` replaces $2\sum_{i \le k} i$ by $k(k+1)$; what remains, $k(k+1) + 2(k+1) = (k+1)(k+2)$, is a ring identity and `ring` closes it.
  5. 第五步(验证与 takeaway):完整答案四行——`induction n with | zero => simp | succ k ih => rw [Finset.sum_range_succ, mul_add, ih]; ring`。通过 `#print axioms` 检查只有 Lean 标准公理。两种证法一个想法:高斯靠「对称配对」把和看成一整块,Lean 靠「递推」把它拆成一步——数学证明常常是同一路风景的两个登山口。Step 5 (check and takeaway): the full proof is four lines — `induction n with | zero => simp | succ k ih => rw [Finset.sum_range_succ, mul_add, ih]; ring` — verified with `#print axioms` showing only Lean's standard axioms. Two proofs, one idea: Gauss saw the sum as one symmetric block; Lean peels it recursively — often the same mountain scenery, two trailheads.
-- level: 2
import Mathlib
/-! Gauss's sum: prove $2(0 + 1 + \cdots + n) = n(n+1)$. -/
theorem gauss_sum (n : ℕ) : 2 * ∑ i ∈ Finset.range (n + 1), i = n * (n + 1) := by
  induction n with
  | zero => simp
  | succ k ih =>
    rw [Finset.sum_range_succ, mul_add, ih]
    ring

运行答案 ▶Run the solution ▶ 下载答案 .leanDownload solution .lean

人的思考A human's take

Arithmetic progression — Wikipedia(History 一节专门讲了高斯故事的真伪) — Wikipedia 英文版编辑(历史综述段落,已通读)

这一页没有停留在「高斯秒算 1+⋯+100」的爽文版本:History 一节开门见山写「这则轶事可靠性存疑」,并立刻把功劳还给更早的人——公式在古典时代已由阿基米德、许普西克勒斯、丢番图知晓,中国见于张邱宗《算经》,印度见于 Aryabhata、Brahmagupta、Bhaskara II,中世纪欧洲则有 Alcuin、Dicuil、斐波那契、Sacrobosco 与《塔木德》的 tosafist 注家——有人甚至猜源头是公元前 5 世纪的毕达哥拉斯学派。The page refuses the motivational-poster version of 'young Gauss sums 1 to 100 instantly': its History section states outright that the anecdote's reliability is doubtful, then returns credit where it came due — the formula was known in antiquity to Archimedes, Hypsicles and Diophantus, in China to Zhang Qiujian, in India to Aryabhata, Brahmagupta and Bhaskara II, and in medieval Europe to Alcuin, Dicuil, Fibonacci and Sacrobosco, plus anonymous Talmud commentators (the Tosafists); some even trace it to the 5th-century BC Pythagoreans.

作者真正教的是那招「折回来加」:以 $2+5+8+11+14=40$ 为例,把数列倒写一遍上下相加,每列都等于首末之和 $16$,$16 \times 5 = 80$ 恰好是目标的两倍——「乘 $n$、乘首末和、除 $2$」的公式由此一次成形。这正是谜题 Lean 陈述里坚持写 $2 \cdot \sum$(而不写除法)的同款理由:乘法版的配对恒等式最干净。What the authors actually teach is the fold-and-add trick itself: with $2+5+8+11+14=40$, write the sequence backwards underneath and add column by column — every column equals first-plus-last, $16$; $16 \times 5 = 80$ is exactly twice the desired sum. The one-line formula (count of terms, times first-plus-last, divided by two) emerges in a single stroke. That is precisely why the puzzle's Lean statement insists on $2 \cdot \sum$ with no division: the multiply-by-two pairing identity is the cleanest form.

AI 随想An AI's reflection

以下由 AI 撰写。Written by AI.

这道 ★2 谜题有意思的地方不在结果——$0+\cdots+n$ 的公式谁都会背——而在同一件事有两条来路完全不同、却同样严丝合缝的证明。高斯式的「折回来加」是几何的眼光:把和看成一整块,寻找它的对称性,让两半拼成规整的矩形;归纳法则是机器的眼光:不看整体,只问「从 $k$ 到 $k+1$ 多出来的那一项是什么」,让递推自己滚起来。Lean 的陈述里那个 $2$,其实是几何眼光留下的化石——配对法天然产生两倍的总和,形式化时与其引入除法去抵消,不如干脆留着它。我们日常的工作里也是这样:两种眼光对应两种调试法——全局对称(「这段代码和那段是不是同一个模式的两半?」)和局部递推(「第 $k+1$ 步多做了什么?」)。会背公式的人很多,同时拥有两条来路的人,才能在一道题卡住时换登山口。今天的答案四行就写完了,但「四行写完」和「只有一种写法」是两回事——后者才是周二 ★2 想教的东西。What makes this ★2 puzzle lovely isn't the result — everyone has memorized the sum of $0$ through $n$ — but that the same fact admits two completely different roads that fit just as tightly. Gauss's fold-and-add is the geometric eye: see the sum as one block, find its symmetry, let the two halves tile a neat rectangle. Induction is the mechanical eye: ignore the whole, ask only 'what does step $k+1$ add?' and let recursion roll. The factor $2$ in the Lean statement is a fossil left by the geometric eye — pairing naturally produces a doubled total, and formalization keeps it rather than introducing division to cancel it. Working life mirrors this: the two eyes are the two debugging modes — global symmetry ('is this code half of a pattern mirrored elsewhere?') and local recursion ('what did step $k+1$ add?'). Plenty of people can recite the formula; only people who own both roads can switch trailheads when one gets stuck. The verified answer is four lines long, but 'four lines' and 'only one way to write it' are different things — the latter is what a Tuesday ★2 is for.

✓ 已通过 Lean 编译验证(无 sorry,无额外公理)✓ Verified by Lean (no sorry, no extra axioms) · 题目来自本站题库Problem from this site's puzzle bank · Lean v4.35.0-rc4 · Mathlib feefa32

程序员随想Programmer's Musings

哲学与生活Philosophy and Life

工具角Tools Corner