SQLite 文档的学习笔记(1)长期支持计划

2022-08-04

前段时间偶然用了 sqlite,在阅读了文档后,感到 sqlite 背后是一个严谨、负责、专业的团队。通过阅读这些文档能学习到不少专业知识和精神。

可惜这些文档的中文版,看起来是通过机器翻译的。我打算在这里以读书笔记的方式,给出一份自己的中文版。

这篇支持计划可以看做是今天的作者写给未来的参与者的信,讲述了过去和今天的做法,树立了今后 SQLite 的开发活动价值观和方法论。在我们的项目中,有值得学习的地方。

原始材料:Long Term Support,中文版:长期支持

正文

The intent of the developers is to support SQLite through the year 2050.

SQLite 开发者的意愿是,将 SQLite 一直支持到 2050 年。

At this writing, 2050 is still 34 years in the future. Nobody knows what will happen in that time, and we cannot absolutely promise that SQLite will be viable or useful that far out. But we can promise this: we plan as if we will be supporting SQLite until 2050. That long-term outlook affects our decisions in important ways.

在编写本文的时候,距离 2050 年还有 34 年之遥,谁也不知道那时的世界会是什么样子。同时,我们也不能保证,在那么久远的将来,SQLite 仍然可以使用甚至能不能运行。然而,我们保证:我们将按照我们能一直支持到 2050 年的假设去规划我们今天的开发活动,这个远期的目标左右着我们今天做出的决定:

Cross-platform Code: SQLite runs on any platform with an 8-bit byte, two’s complement 32-bit and 64-bit integers, and a C compiler. It is actively tested on all currently popular CPUs and operating systems. The extreme portability of the SQLite code and file format will help it remain viable on future platforms.

跨平台兼容能力:SQLite 要能运行在具备以下条件的所有平台上:8比特长的字节、2补码的二进制、32位或64位、有C编译器。SQLite 针对当前流行的CPU和操作系统积极主动地开展测试。SQLite 自身代码和使用的文件格式具备极高的可移植性,这将保证它在未来仍可以运行。

Stable, Cross-platform Database Files: SQLite database files are bit-for-bit identical on 32-bit, 64-bit, big-endian, and little-endian platforms. You can copy an SQLite database file from one system to another without having to translate or convert the database. Furthermore, the file format is well documented and stable. Database files created today will be readable and writable by future versions of SQLite decades in the future.

稳定的、多个平台一致的数据文件: SQLite 保存数据的文件能在 32-bit、64-bit、大端字节、小端字节等各种平台下,做到逐个 bit 的相同。这意味着你从一种平台拷贝数据文件到另一种平台后,不需要转换数据文件格式就能直接读取和运行。而且,数据文件的格式有着详尽而又稳定的文档。今天新建一个数据文件,直到几十年后的 SQLite 版本仍然可以读写。

Aviation-grade testing: Every machine-code branch instruction is tested in both directions. Multiple times. On multiple platforms and with multiple compilers. This helps make the code robust for future migrations. The intense testing also means that new developers can make experimental enhancements to SQLite and, assuming legacy tests all pass, be reasonably sure that the enhancement does not break legacy.

航空级的软件测试过程:SQLite 程序的每一条机器码的分支指令都从两个方向、反复多次、多种平台、多种编译器的完整测试。(注:这是乘法关系,假设有10万个测试场景、5次、5种平台、5种编译器,完整的测试次数将是:10万×5×5×5=1250万次测试)。这样做的目的是让代码保持健壮,不易出错,以备未来的各类迁移重构。另外,严格充分的测试,还能让后继的开发者(可不,现在写这套代码的人,到2050年还有几个能写?)敢于编写一些具有试验性的新功能,待这些新功能发布后,如果以往的测试集在新代码上都能通过,我们能有理由的认为,至少所有的旧功能仍然正常工作。

(关于 SQLite 的测试,有 另一篇文章 做介绍)

Extensive, detailed documentation: SQLite has candid, developer-friendly, and open-source documentation. Docs are written by and for programmers. (A few examples: [1] [2] [3] [4] [5] [6] [7] [8]) The extensive documentation helps new developers come up to speed on SQLite very quickly.

丰富、详尽的文档:SQLite 的文档内容诚恳、坦率、对开发者友好、源代码开放。这些文档从程序员中来、到程序员中去,能让后继的开发者迅速的融入 SQLite 的开发过程中。

文档的示例:

  1. Architecture of SQLite
  2. Database File Format
  3. Query Planning
  4. The SQLite Bytecode Engine
  5. Compile-time Options
  6. Dynamic Memory Allocation In SQLite
  7. Debugging Hints
  8. How To Corrupt An SQLite Database File

Heavily commented source code: The SQLite source code is over 35% comment. Not boiler-plate comments, but useful comments that explain the meaning of variables and objects and the intent of methods and procedures. The code is designed to be accessible to new programmers and maintainable over a span of decades.

大量的代码注释:SQLite 源代码中,注释占到了 35% 以上。而且这些注释都不是言之无物,反而是大有用处。这些注释的内容包括代码中变量和对象的含义、函数方法的设计意图等。这些代码旨在让新加入的程序员能够无压力的阅读,并且能在数十年的跨度内方便维护,而不至于烂到无从下手。

Disaster planning: Every byte of source-code history for SQLite is cryptographically protected and is automatically replicated to multiple geographically separated servers, in datacenters owned by different companies. Thousands of additional clones exist on private servers around the world. The primary developers of SQLite live in different regions of the world. SQLite can survive a continental catastrophe.

灾难预防:SQLite 源代码的每次更新记录的每个字节都被加密保存,而且被自动地备份在多个数据中心上,这些数据中心不仅在地理空间上分隔(注:防天灾),而且还分属于不同的公司(注:防人祸)。

Old school → Nobody is completely immune to trends and fads, but the SQLite developers work hard to avoid being sucked into the latest programming fashion. Our aim is to produce timeless code that will be readable, understandable, and maintainable by programmers who have not yet been born.

In addition to “supporting” SQLite through the year 2050, the developers also promise to keep the SQLite C-language API and on-disk format fully backwards compatible. This means that application written to use SQLite today should be able to link against and use future versions of SQLite released decades in the future.

Our goal is to make the content you store in SQLite today as easily accessible to your grandchildren as it is to you.

Update on 2018-05-31: Our goal of supporting SQLite long-term have apparently come to the notice of the preservationist at the US Library Of Congress who have identified SQLite as a recommended storage format for the preservation of digital content.

捐助本站

为了保证阅读体验,本站不安放广告。但是,租用服务器和编写文章需要个人资金和时间的投入。

如果您觉得文章对您有用,请考虑捐助小站(金额不限),以期待更多原创文章。捐助记录

本站是个人网站,若无特别说明,文章均为原创,并采用 署名协议 CC-BY-NC 授权。
欢迎转载,惟请保留原文链接,且不得用于商业用途。

相关文章