Coding Standards

This document describes a list of coding conventions that are required for code submissions to the project. By default, the coding conventions for most Open Source Projects should follow the existing coding conventions in the code that you are working on. For example, if the bracket is on the same line as the if statement, then you should write all your code to have that convention.

本ドキュメントは当プロジェクトにコードを提供する際に従うべきコーディング規約集について述べたものです。概してほとんどのオープンソースプロジェクトで規定されているコーディング規約はそのプロジェクトの実際のコードに含まれている習慣に従っているものです。例えば、if文と同じ行に中カッコがあったら、あなたの書くコードも全てそれに従っている必要があります。

If you commit code that does not follow these conventions, you are responsible for also fixing your own code.

もし、規約に従わないコードをコミットしてしまったら、責任もってその修正をしなければなりません。

Below is a list of coding conventions that are specific to Turbine, everything else not specificially mentioned here should follow the official Sun Java Coding Conventions.

下記にTurbineに特有のコーディング規約を示します。ここで特に挙げられていないものについては、Sun Java コーディング規約に従います。

1. Brackets should begin and end on a new line and should exist even for one line statements. Examples:

1. 中カッコの開始と終了は次の行に記述すること。たとえ中身が1行しかなくてもカッコを省略してはいけません。以下に例を示します:

if ( foo )
{
    // code here
}

try
{
    // code here
}
catch (Exception bar)
{
    // code here
}
finally
{
    // code here
}

while ( true )
{
    // code here
}

2. Though it's considered okay to include spaces inside parens, the preference is to not include them. Both of the following are okay:

2. カッコの中にスペースを入れるのはOKとされていますが、入れない方が好まれます。以下の例はどちらでも構いません:

if (foo)

or

if ( foo )

3. 4 space indent. NO tabs. Period. We understand that many developers like to use tabs, but the fact of the matter is that in a distributed development environment where diffs are sent to the mailing lists by both developers and the version control system (which sends commit log messages), the use tabs makes it impossible to preserve legibility.

3. インデントはタブを使わずに4桁スペースを用いること。 タブを使うことを好む開発者が多数存在することは理解していますが、分散開発環境において開発者やバージョン管理システムによりコードの差分がメーリングリストに流される場合(バージョン管理システムはコミットログメッセージを流します。)、タブを用いることで可読性が維持できなくなる、という問題があります。

In Emacs-speak, this translates to the following command:

Emacsで言うと、この規約は以下のコマンドにあたります。

(setq-default tab-width 4 indent-tabs-mode nil)

4. Unix linefeeds for all .java source code files. Other platform specific files should have the platform specific linefeeds.

4. 全ての.javaソースファイルはUnixのラインフィードを用いなければなりません。他のプラットフォーム特有のファイルについては、そのプラットフォーム向けのラインフィードである必要があります。

5. JavaDoc MUST exist on all methods. If your code modifications use an existing class/method/variable which lacks JavaDoc, it is required that you add it. This will improve the project as a whole.

5. 全てのメソッドに対し、JavaDocが用意されていなければなりません。もしあなたの提供した修正が、JavaDocが用意されていない既存のクラス/メソッド/変数を用いている場合は、それらのJavaDocを追記しなければなりません。こうすることでプロジェクト全体が良くなるのです。

6. The Jakarta/Turbine License MUST be placed at the top of each and every file.

6. Jakarta/Turbineライセンス表記は、全てのファイル各々の先頭に置かなくてはなりません。

7. If you contribute to a file (code or documentation), add yourself to the authors list at the top of the file. For java files the preferred Javadoc format is:

7. コードやドキュメント等ファイルになんらかの寄与を行う場合は、ファイルの先頭にある著者リストに自分で追記を行うこと。JavaDocを用いるJavaファイル用のフォーマットは以下になります。

@author <a href="mailto:user@domain.com">John Doe</a>

8. All .java files should have a @version tag like the one below.

8. 全ての.javaファイルには以下に示すような@versionタグがないといけません。

@version $Id: code-standards.html,v 1.2 2003/05/22 01:41:13 yukimi Exp $

9. Import statements must be fully qualified for clarity.

9. import文は対象が明確になるように完全修飾指定(フルパス指定)でなければなりません。

import java.util.ArrayList;
import java.util.Hashtable;

import org.apache.foo.Bar;
import org.apache.bar.Foo;

And not

以下のようなものは禁止です。

import java.util.*;
import org.apache.foo.*;
import org.apache.bar.*;

X/Emacs users might appreciate this in their .emacs file.

X/Emacsユーザであれば、以下の記述を.emacsファイルに追加するとよいでしょう。

(defun apache-jakarta-mode ()
  "The Java mode specialization for Apache Jakarta projects."
  (if (not (assoc "apache-jakarta" c-style-alist))
      ;; Define the Apache Jakarta cc-mode style.
      (c-add-style "apache-jakarta" '("java" (indent-tabs-mode . nil))))

  (c-set-style "apache-jakarta")
  (c-set-offset 'substatement-open 0 nil)
  (setq mode-name "Apache Jakarta")

  ;; Turn on syntax highlighting when X is running.
  (if (boundp 'window-system)
      (progn (setq font-lock-support-mode 'lazy-lock-mode)
             (font-lock-mode t))))

;; Activate Jakarta mode.
(if (fboundp 'jde-mode)
    (add-hook 'jde-mode-hook 'apache-jakarta-mode)
  (add-hook 'java-mode-hook 'apache-jakarta-mode))

Thanks for your cooperation.

あなたの御協力に感謝します。