バージョンごとのドキュメント一覧

56.1. 書式 #

<title>Formatting</title>

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. ソースコードの書式では、タブを4カラムとするスペーシングを使用し、現在はタブを保存しています(つまりタブをスペースに展開しません)。 各論理インデントのレベルは、さらに1つのタブストップです。

Layout rules (brace positioning, etc.) follow BSD conventions. In particular, curly braces for the controlled blocks of <literal>if</literal>, <literal>while</literal>, <literal>switch</literal>, etc. go on their own lines. 配置規則(括弧の位置など)はBSDの慣例に従います。 特にifwhileswitchなどの制御ブロックのための中括弧はそれ自身を一行で表します。

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.) コードが80カラムのウィンドウで読み易くなるように1行の長さを制限してください。 (これは80カラムを超えてはならないことを意味していません。 例えば、任意の場所にある長いエラーメッセージ文字列をコードが80カラムに収まるように改行を含めても、おそらく可読性を向上させることはありません。)

To maintain a consistent coding style, do not use C++ style comments (<literal>//</literal> comments). <application>pgindent</application> will replace them with <literal>/* ... */</literal>. 一貫したコーディング形式を保つため、C++形式のコメント(//コメント)は使用しないでください。 pgindentは、それらを/* ... */で置き換えます。

The preferred style for multi-line comment blocks is 複数行に渡るコメントブロックの推奨書式は以下のようになります。 <programlisting> /* * comment text begins here * and continues here */ </programlisting>

/*
 * コメントテキストはここから始まり
 * ここまで続きます
 */

Note that comment blocks that begin in column 1 will be preserved as-is by <application>pgindent</application>, 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: カラム1から始まるコメントブロックはpgindentによりそのまま維持されますが、字下げされたコメントブロックは、あたかも平文テキストのように再整形されることに注意してください。 ある字下げブロックの中で改行を維持したい場合は以下のようにダッシュを追加します。

    /*----------

     * comment text begins here
     * and continues here

     * コメントテキストはここから始まり
     * ここまで続きます
     *----------
     */

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 <application>pgindent</application> 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 <quote>make the new code look like the existing code around it</quote>. 登録されたパッチは完全にはこの書式規則に従う必要はありませんが、そのようにすることを勧めます。 登録されるコードは次のリリースの前にpgindentを通します。 ですので、他の書式規則に従って作成して、見た目を良くすることに意味がありません。 優れたパッチに関する原則は、新しいコードがその前後にある既存のコードのように見えることです。

The <filename>src/tools/editors</filename> directory contains sample settings files that can be used with the <productname>Emacs</productname>, <productname>xemacs</productname> or <productname>vim</productname> editors to help ensure that they format code according to these conventions. src/tools/editorsディレクトリには、確実に上記の規約に従った書式になることを補助する、Emacsxemacsvimエディタで使用できるサンプルの設定ファイルがあります。

If you'd like to run <application>pgindent</application> locally to help make your code match project style, see the <filename>src/tools/pgindent</filename> directory. pgindentをローカルで実行して、コードをプロジェクトスタイルに合わせたい場合は、src/tools/pgindentディレクトリを参照してください。

The text browsing tools <application>more</application> and <application>less</application> can be invoked as: テキスト閲覧ツールmorelessでは以下のようにすれば、

more -x4
less -x4

to make them show tabs appropriately. タブを適切に表示させることができます。