Principia Softwarica
Principia Softwarica
Principia Softwarica is a series of books explaining how things work in a computer by describing with full details all the source code of all the essential programs used by a programmer. All the programs come from Plan 9 from Bell Labs, an operating system designed as the successor to Unix whose code is remarkably elegant and small. Principia Softwarica 是一系列书籍,旨在通过详细描述程序员所使用的所有核心程序的源代码,来解释计算机的工作原理。所有程序均来自贝尔实验室的 Plan 9,这是一个被设计为 Unix 继任者的操作系统,其代码极其优雅且精简。
Among those essential programs are the kernel, the shell, the windowing system, the compiler, the linker, the editor, the web browser, or the debugger. Each program is covered by a separate book (see the full list). The books not only describe the implementations of essential programs — they are the implementations. Each program comes from a literate program, a document containing both source code and documentation where the code is organized and presented to facilitate comprehension. The actual code and the book are both derived automatically from this literate program. 这些核心程序包括内核、Shell、窗口系统、编译器、链接器、编辑器、网页浏览器和调试器。每个程序都由一本独立的书进行讲解(详见完整列表)。这些书不仅描述了核心程序的实现,它们本身就是实现过程。每个程序都源自一个“文学编程”(literate program)文档,该文档同时包含源代码和说明文档,代码经过组织和呈现,旨在方便理解。实际的代码和书籍均由此文学编程文档自动生成。
What’s New
最新动态
- March 2026 — We’re live! The Principia Softwarica website is now online.
- 2026 年 3 月 — 我们上线了!Principia Softwarica 网站现已正式发布。
- 2025 — Resumed: builds and runs again on QEMU and Raspberry Pi; Dockerfile and CI.
- 2025 年 — 项目重启:已可在 QEMU 和树莓派(Raspberry Pi)上构建并运行;增加了 Dockerfile 和持续集成(CI)。
- 2019–2024 — Hiatus (working on Semgrep).
- 2019–2024 年 — 暂停期(期间致力于 Semgrep 项目)。
- 2017 — Kernel ported to Raspberry Pi; Shell and Graphics books underway.
- 2017 年 — 内核移植到树莓派;Shell 和图形系统书籍编写中。
- 2016 — Build System book finished; first Libcore and Compiler literate programs.
- 2016 年 — 构建系统书籍完成;首批 Libcore 和编译器文学编程文档完成。
- 2015 — Assembler and Linker books finished; met Knuth.
- 2015 年 — 汇编器和链接器书籍完成;见到了高德纳(Knuth)。
- 2014 — Project started: forked Plan 9, cross-compiled from macOS, first literate programs.
- 2014 年 — 项目启动:Fork 了 Plan 9,从 macOS 进行交叉编译,完成了首批文学编程文档。
Why Principia?
为什么选择 Principia?
The Education Gap 教育鸿沟
What happens when you type ls in a terminal window? Keith Adams — a colleague at Facebook, later Chief Architect at Slack — used this as his interview question. It is a simple question, but the answer involves the shell, the C library, the kernel, the graphics stack, and the windowing system. Most engineers cannot answer it fully. (See The Journey of ls for the complete trace.)
当你在终端窗口输入 ls 时会发生什么?Keith Adams(Facebook 的前同事,后来担任 Slack 的首席架构师)曾用这个问题作为面试题。这是一个简单的问题,但答案涉及 Shell、C 库、内核、图形栈和窗口系统。大多数工程师无法完整回答。(详见《ls 之旅》以获取完整追踪过程。)
Today, “full stack” usually means React + Node + cloud. But the real full stack is the compiler, the linker, the kernel, and the system calls underneath. There are excellent textbooks that explain the concepts behind these programs, but almost none that show the actual source code. Principia fills that gap. 如今,“全栈”通常指 React + Node + 云服务。但真正的全栈是编译器、链接器、内核以及底层的系统调用。市面上有许多优秀的教科书解释了这些程序背后的概念,但几乎没有哪本展示了实际的源代码。Principia 填补了这一空白。
The AI Era Makes This More Important AI 时代使其愈发重要
AI coding tools use the very programs that Principia explains. They run grep, sed, diff, awk, gcc, ld hundreds of times a day. If writing code is 20% of the job and understanding is 80%, AI is handling the 20%. The 80% — understanding what the code actually does, all the way down to the hardware — becomes everything. Machines recently went through deep learning. It is time for humans to do so too.
AI 编程工具正是使用 Principia 所解释的那些程序。它们每天运行数百次 grep、sed、diff、awk、gcc 和 ld。如果编写代码占工作的 20%,而理解代码占 80%,那么 AI 正在处理那 20%。剩下的 80%——即理解代码到底在做什么,一直到硬件层面——变得至关重要。机器最近经历了深度学习,现在也是人类进行深度学习的时候了。
Plan 9
关于 Plan 9
Plan 9 was chosen because you can realistically understand the entire operating system. The code is written in a clean, consistent C style, and the system design follows a few powerful ideas (everything is a file, per-process namespaces, network transparency) applied uniformly. It is not as fancy as macOS or Windows, but in essence Plan 9 provides the same core services: a kernel managing processes and memory, a windowing system, a shell, a compiler, networking, and graphical applications. 选择 Plan 9 是因为你可以切实地理解整个操作系统。其代码以简洁、一致的 C 语言风格编写,系统设计遵循了几个强大且统一应用的理念(一切皆文件、进程命名空间、网络透明性)。它不像 macOS 或 Windows 那样花哨,但本质上 Plan 9 提供了相同的核心服务:管理进程和内存的内核、窗口系统、Shell、编译器、网络功能以及图形化应用程序。
How small is Plan 9? The treemap below compares the size of GNU/Linux programs (in red) with their Plan 9 equivalents (in green). The entire Plan 9 system — kernel, compiler, shell, windowing system, and all the rest — fits in 183K lines of code, almost 2x smaller than just vim (350K). This is what makes it possible to explain every line in a book series.
Plan 9 有多小?下方的树状图比较了 GNU/Linux 程序(红色)与其 Plan 9 等效程序(绿色)的大小。整个 Plan 9 系统——包括内核、编译器、Shell、窗口系统及其他所有部分——仅有 18.3 万行代码,比单纯一个 vim(35 万行)还要小近两倍。这使得在系列丛书中解释每一行代码成为可能。