人物發言

Lauren Tan

我對形式化方法挺看好,但覺得該降溫預期、自己去研究(聲明:我不是這方面專家)。它沒法保證程式沒 Bug,只能保證在某些假設下符合規格;而規格來自人想要什麼,不是數學。只要我們為人做軟體,沒有東西能證明你的規格是對的,只能你自己判斷。

我在 pstack 做/statechart 技能,主要是讓程式裡隱含的狀態機更清楚可讀,縮小審查面,從更高層問:這真的符合意圖嗎?做遊戲時大量使用,下圖是劇情模式狀態圖,靠它找出很多 Bug。

模型檢查(如 TLA+/TLC)適合端到端理解與檢查系統性質;規格不是真碼,有漂移風險,所以她會再疊實證驗證。定理證明與有界模型檢查各有取捨。近中期仍要分層:約束與護欄、實證驗證、真正需要的形式化驗證。

背景:附圖狀態機標出 11 處真實問題(載入凍結、自動選牌、暫停蓋住對白等);技能清單截圖含外部網域,網站未採用該圖。

原文

while i'm quite bullish on formal methods, i think it's worth tempering expectations and doing your own research on it (disclaimer: i am not an expert in it). it cannot guarantee your code is bug free, only that it matches the spec under certain assumptions, and the specs come from what people want, not math. as long as we build software for humans, nothing can prove that your spec is right, only you can judge.

i created the /statechart skill in pstack primarily because it helps make the state machines implicit in your code more obvious and legible to you, so you can shrink the review surface and review the work at a higher level: does it actually match your intent and goal? i used this skill a ton while building my game, below you can see the statechart for story mode where i was able to find many bugs with it.

in that sense, i think model checking (eg TLA+ with TLC) is quite useful for understanding and checking properties of your system e2e, and you don't have to write tons of new verification code for it. the spec isn't your actual code so there's always a risk of drift, but so far i've had good experiences finding actual bugs with it. i tend to pair it with empirical verification (running the code) also to confirm it's real

other types of formal verification like proving theorems (eg Lean, Dafny), bounded model checking (eg CBMC, Kani) etc have their own tradeoffs. proofs cover every possible input, but only for the properties specified, and it takes a lot more code/work. bounded model checking can run on your actual code, which avoids drift, but it only checks up to a certain number of steps, so it's better at finding bugs than proving there aren't any

so i think in the near-medium term you'll still need to layer your codebase: constraints and guardrails (types, lint rules, api design, refactoring), empirical verification (tests, evals, real usage), and formal verification for the parts that really need it. none of these catch everything on their own, but layered together, they catch a lot more and shrink what's left for you to review

but also maybe in the limit, the bitter lesson will prevail and flawless code will just be printed out perfectly every time with no bugs. even in that scenario, /statechart still seems very helpful in confirming that the agent understood your intent correctly. give it a try if you haven't already!

深色狀態圖「AT THE CASE END」:多條角色分支,紅點標出 11 處 Bug 說明。
Lauren 原帖附圖:劇情模式狀態機與 11 項真實 Bug。Lauren Tan 原帖附圖(已清理網域浮水)

重點總結

她看好形式化方法,但提醒只能保證在假設下符合規格;用 statechart 技能在遊戲劇情模式標出 11 處真實 Bug。