Postgresql 中文操作指南

56.1. Formatting #

源代码格式使用 4 列制表符间距,且制表符被保留(即制表符不会扩展为空格)。每个逻辑缩进级别都是一个额外的制表符停靠点。

Source code formatting uses 4 column tab spacing, with tabs preserved (i.e., tabs are not expanded to spaces). Each logical indentation level is one additional tab stop.

布局规则(大括号放置等)遵循 BSD 约定。特别是,ifwhileswitch 等受控块的花括号在它们自己的行中。

Layout rules (brace positioning, etc.) follow BSD conventions. In particular, curly braces for the controlled blocks of if, while, switch, etc. go on their own lines.

限制行长度,以便可以在 80 列窗口中读取代码。(这并不意味着您绝不能超过 80 列。例如,在任意位置打断长错误消息字符串只是为了将代码保持在 80 列之内可能不会明显提高可读性。)

Limit line lengths so that the code is readable in an 80-column window. (This doesn’t mean that you must never go past 80 columns. For instance, breaking a long error message string in arbitrary places just to keep the code within 80 columns is probably not a net gain in readability.)

为了保持一致的编码风格,不要使用 C++ 样式的注释(// 注释)。pgindent 将用 /* …​ */ 替换它们。

To maintain a consistent coding style, do not use C++ style comments (// comments). pgindent will replace them with /* …​ */.

建议的多行注释块样式为

The preferred style for multi-line comment blocks is

/*
 * comment text begins here
 * and continues here
 */

请注意,从第 1 列开始的注释块将按原样由 pgindent 保留,但它将重新整理缩进注释块,就好像它们是纯文本一样。如果您希望保留缩进块中的换行符,请添加类似这样的破折号:

Note that comment blocks that begin in column 1 will be preserved as-is by pgindent, but it will re-flow indented comment blocks as though they were plain text. If you want to preserve the line breaks in an indented block, add dashes like this:

    /*----------
     * comment text begins here
     * and continues here
     *----------
     */

提交的补丁程序完全不必遵循以下格式规则,但这样做是个好主意。在下次发布之前,你的代码将通过 pgindent 运行,所以没必要在其他格式约定下让它看起来很好。关于补丁程序的一条好经验法则便是“让新代码看起来与周围的现有代码类似”。

While submitted patches do not absolutely have to follow these formatting rules, it’s a good idea to do so. Your code will get run through pgindent before the next release, so there’s no point in making it look nice under some other set of formatting conventions. A good rule of thumb for patches is “make the new code look like the existing code around it”.

src/tools/editors 目录包含示例设置文件,可与 Emacs、xemacs 或 vim 编辑器配合使用,以帮助确保它们根据这些约定格式化代码。

The src/tools/editors directory contains sample settings files that can be used with the Emacs, xemacs or vim editors to help ensure that they format code according to these conventions.

如果你想本地运行 pgindent 来帮助你的代码匹配项目样式,请查看 src/tools/pgindent 目录。

If you’d like to run pgindent locally to help make your code match project style, see the src/tools/pgindent directory.

可以这样调用更多和更少的文本浏览工具:

The text browsing tools more and less can be invoked as:

more -x4
less -x4

以使它们适当显示标签。

to make them show tabs appropriately.