將程式設計閱讀視為理論構建
Reading code is often viewed as a linear process of understanding a sequence of instructions. However, a more productive approach is to treat the act of reading programming as "theory building." Instead of simply following the execution flow, 開發者閱讀代碼以構建一個心理模型——一個理論——關於系統如何運作、為什麼存在,以及其組件如何互動。
This shift in perspective transforms the act of reading from a passive activity into an active investigation. 當你在閱讀代碼以建立理論時,你不再只是問「這行代碼做什麼?」,而是問「這個程式的理論是什麼?」。這種方法讓開發者能更有效地導航複雜系統,並為做出具凝聚力的架構決策提供框架,而非支離破碎的決策。
The Danger of Myopic Development
Many developers fall into the trap of focusing exclusively on individual features. 這種近視的觀點會導致軟體缺乏凝聚力,功能被硬塞進去而忽視了整體架構。正如一位社群成員所指出的,「無論對其凝聚力造成什麼影響,只專注於『如何快速實現它們』」往往讓開發者無法參與介面(interfaces)和契約(contracts)等概念,而這些對於長期可維護性至關重要。
When a developer lacks a cohesive theory of the program, the software becomes a collection of disjointed parts. 「理論」是橋接個別功能與整體系統目標之間差距的關鍵,確保用於解決問題的機制在整個代碼庫中是一致的。
Theory Building vs. Design Optimization
While the term "theory building" may not resonate with everyone, the underlying principle is aligned with the core of effective software design. 有些人認為這個過程與其說是「理論」,不如說是因式分解(factorization)與表示法(representation)的優化。
In this view, programming is the act of mentally exploring alternatives to find the ideal factorization—the way to decompose a problem into the simplest possible interfaces and the fewest moving parts. 目標是建立一個實作,讓代碼讀起來就像是需求的描述。在這種情境下,理論構建本質上是精煉問題領域的心理模型以最小化複雜度的過程。
The Impact of LLMs on Mental Models
The rise of Large Language Models (LLMs) has introduced a significant shift in how code is written and maintained. 雖然 AI 可以快速生成功能性代碼,但它通常缺乏對「程式理論」的全面理解。這為人類工程師帶來了一套新的挑戰:
- Loss of Conceptualization: 當開發者採取更放手的做法時,他們面臨著失去對所監督代碼的清晰概念化的風險。從「在每個函數中做出 20 個微架構決策」轉向審查 AI 輸出,可能會導致對系統深層理解的衰退。
- Accumulation of Unknowns: 有一種日益增長的擔憂,我們正在累積大量我們並不完全理解或甚至沒有閱讀過的代碼。當代碼本身是由外部代理人撰寫時,心理模型的的重要性變得更加關鍵。
- The New Role of the Engineer: 隨著 AI 處理編碼的戰術執行,人類工程師的主要價值轉向了上下文(context)的收集與保留——即 AI 無法輕易存取或複製的高層次理論。
Conclusion
Whether you call it "theory building," "factorization optimization," or "mental modeling," the core requirement for sustainable software is a deep, conceptual understanding of the system. 在代碼生成變得商品化的時代,透過閱讀代碼來建立理論的能力,仍然是資深工程師最關鍵的技能。這是確保軟體體系一致、一致性、可維護性與邏輯合理性的唯一途徑。