blob: f6d6ffdb04109e3a19124383200c1940bf8a3028 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 2.0.0 from src/site/xdoc/common/code-standards.xml at 17 Jun 2025
| Rendered using Apache Maven Fluido Skin 2.1.0
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 2.0.0" />
<title>Coding Standards – Apache Turbine</title>
<link rel="stylesheet" href="../css/apache-maven-fluido-2.1.0.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script src="../js/apache-maven-fluido-2.1.0.min.js"></script>
<style>.github-fork-ribbon:before { background-color: orange; }</style>
</head>
<body>
<a class="github-fork-ribbon right-top" href="https://github.com/apache/turbine-site" data-ribbon="Fork me on GitHub">Fork me on GitHub</a>
<div class="container-fluid container-fluid-top">
<header>
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h1><a href=".././"><img src="../images/turbine-project.png" alt="Apache Turbine" /></a></h1></div></div>
<div class="pull-right"><div id="bannerRight"><h1><a href=".././"><img src="../images/logo.gif" /></a></h1></div></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 01 Apr 2025<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 7.0</li>
<li class="pull-right"><span class="divider">|</span>
<a href="../fulcrum/">Fulcrum</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href=".././">Turbine</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="https://www.apache.org/">Apache</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="../fulcrum/">Fulcrum</a></li>
<li class="pull-right"><a href="https://www.apache.org">Apache</a></li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">General Information</li>
<li><a href="../index.html">Overview</a></li>
<li><a href="../turbine-concepts.html">Turbine Concepts</a></li>
<li><a href="../fsd.html">Specification</a></li>
<li><a href="../further-reading/index.html">Further Reading</a></li>
<li><a href="../news.html">News and Status</a></li>
<li><a href="../common/powered.html">Sites Using Turbine</a></li>
<li><a href="../common/related.html">Sites Related to Turbine</a></li>
<li><a href="../common/license.html">License</a></li>
<li><a href="../download.html">Download</a></li>
<li><a href="../examples.html">Example Apps</a></li>
<li class="nav-header">Shortcuts to Turbine Documentation</li>
<li><a href="https://blogs.apache.org/turbine/">Turbine Blog</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/TURBINE/">Turbine Wiki Home</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/TURBINE/Turbine2+FAQ">Frequently Asked Questions (FAQ)</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/TURBINE/Turbine2+Tutorial">Tutorial</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/TURBINE/Turbine2+UsersGuide">User&apos;s Guide</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/TURBINE/Turbine5">Development</a></li>
<li class="nav-header">Events</li>
<li><a href="https://www.apache.org/events/current-event.html" target="_blank"><img class="imageLink" src="https://www.apache.org/events/current-event-125x125.png" /> Apache Conferences</a></li>
<li class="nav-header">Turbine Releases</li>
<li><a href="../turbine/index.html">Overview</a></li>
<li><a href="../turbine/turbine-2-3-3/index.html">Turbine 2.3.3</a></li>
<li><a href="../turbine/turbine-4-0/index.html">Turbine 4.0 (M2)</a></li>
<li><a href="../turbine/turbine-5-0/index.html">Turbine 5.0</a></li>
<li><a href="../turbine/turbine-5-1/index.html">Turbine 5.1</a></li>
<li><a href="../turbine/turbine-6-0/index.html">Turbine 6.0</a></li>
<li><a href="../turbine/turbine-7-0/index.html">Turbine 7.0</a></li>
<li class="nav-header">Turbine Development</li>
<li><a href="../turbine/index.html">Current Turbine Development Tree</a></li>
<li class="nav-header">Turbine Sub Projects</li>
<li><a href="../fulcrum/index.html">Fulcrum</a></li>
<li class="nav-header">Turbine + Fulcrum Parent POM</li>
<li><a href="../turbine-parent/index.html">Turbine Parent</a></li>
<li class="nav-header">Closed projects</li>
<li><a href="../stratum/index.html">Stratum</a></li>
<li><a href="../tdk/index.html">TDK</a></li>
<li><a href="../meta/index.html">META</a></li>
<li class="nav-header">Community</li>
<li><a href="../who-we-are.html">Who we are</a></li>
<li><a href="../contact.html">Contact us</a></li>
<li><a href="../how-to-help.html">How to help</a></li>
<li><a href="../how-it-works.html">How it works</a></li>
<li><a href="../board-reports.html">Board reports</a></li>
<li class="nav-header">General Development Information</li>
<li class="active"><a>Coding Specification</a></li>
<li><a href="../common/developer-links.html">Developer Links</a></li>
<li><a href="../common/documentation.html">Improving Documentation</a></li>
<li class="nav-header">ASF</li>
<li><a href="https://apache.org/">Main</a></li>
<li><a href="https://www.apache.org/licenses/">License</a></li>
<li><a href="https://apache.org/foundation/sponsorship">Sponsorship</a></li>
<li><a href="https://www.apache.org/foundation/sponsors">Thanks</a></li>
<li><a href="https://www.apache.org/foundation/policies/conduct">Conduct</a></li>
<li><a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy</a></li>
<li><a href="https://www.apache.org/security/">Security</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="../project-info.html"><span class="icon-chevron-right"></span>Project Information</a></li>
<li><a href="../project-reports.html"><span class="icon-chevron-right"></span>Project Reports</a></li>
<li class="nav-header">Apache</li>
<li><a href="https://www.apache.org/">Apache Website</a></li>
<li><a href="https://www.apache.org/licenses/">License</a></li>
<li><a href="https://www.apache.org/foundation/how-it-works.html">How the ASF works</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li><a href="https://www.apache.org/security/">Security</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<form id="search-form" action="https://www.google.com/search" method="get" >
<input value="https://turbine.apache.org/" name="sitesearch" type="hidden" />
<input class="search-query" name="q" id="query" type="text" placeholder="Search with Google..." />
</form>
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<a href="https://maven.apache.org/" class="builtBy" target="_blank"><img class="builtBy" alt="Built by Maven" src="../images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10">
<section><a id="Coding_Standards"></a>
<h1>Coding Standards</h1>
<p>
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.
</p>
<p>
<strong>If you commit code that does not follow these conventions, you
are responsible for also fixing your own code.</strong>
</p>
<p>
Below is a list of coding conventions that are specific to Turbine,
everything else not specificially mentioned here should follow the official
<a href="http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html" class="externalLink">Sun
Java Coding Conventions</a>.
</p>
<p>
1. Brackets should begin and end on a new line and should exist even
for one line statements. Examples:
</p>
<pre class="prettyprint"><code>
if (foo)
{
// code here
}
try
{
// code here
}
catch (Exception bar)
{
// code here
}
finally
{
// code here
}
while (someCondition)
{
// code here
}
</code></pre>
<p>
2. Though it's considered okay to include spaces inside parens, the
preference is to not include them. Both of the following are okay:
</p>
<pre class="prettyprint"><code>
if (foo)
or
if ( foo )
</code></pre>
<p>
3. 4 space indent. <strong>NO tabs</strong>. 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.
</p>
<p>
In Emacs-speak, this translates to the following command:
</p>
<pre class="prettyprint"><code>
(setq-default tab-width 4 indent-tabs-mode nil)
</code></pre>
<p>
4. Unix linefeeds for all .java source code files. Other platform specific
files should have the platform specific linefeeds.
</p>
<p>
5. JavaDoc <strong>MUST</strong> 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. For guidelines on how to write proper
JavaDocs, see
<a href="http://java.sun.com/j2se/javadoc/writingdoccomments/index.html" class="externalLink">
Sun's guidelines</a>
</p>
<p>
6. When writing javadocs for variables, try to keep the comment on just
one line.
</p>
<pre class="prettyprint"><code>
/** Documentation of this variable */
private int myVariable;
/**
* If the documentation of the variable is enough to occupy multiple
* lines, then this form of comment is also perfectly acceptable.
*/
private int myVariable;
</code></pre>
<p>
7. The ASL 2.0 License <strong>MUST</strong> be placed at the top
of each and every file.
</p>
<p>
8. If you contribute to a file (code or documentation), add yourself to the
authors list at the top of the file. You should add yourself to the end of
the list of authors. For java files the preferred Javadoc format is:
</p>
<pre class="prettyprint"><code>
@author &lt;a href=&quot;mailto:user@domain.com&quot;&gt;John Doe&lt;/a&gt;
</code></pre>
<p>
9. All .java files should have a @version tag like the one below.
</p>
<pre class="prettyprint"><code>
@version $Id$
</code></pre>
<p>
10. Import statements must be fully qualified for clarity.
</p>
<pre class="prettyprint"><code>
import java.util.ArrayList;
import java.util.Hashtable;
import org.apache.foo.Bar;
import org.apache.bar.Foo;
</code></pre>
<p>
And not
</p>
<pre class="prettyprint"><code>
import java.util.*;
import org.apache.foo.*;
import org.apache.bar.*;
</code></pre>
<p>
11. Import statements should be listed in alphabetical order. Use blank lines
to separate products. In cases where there is a large number of imports from a
single product (like java.x) consider separating at the second level. For example,
you could group all of the java.util, java.swing, etc...
</p>
<p>
12. The conditional part of if and while statements should not use
the equality operator for testing true or false values.
</p>
<pre class="prettyprint"><code>
if (foo)
and not
if (foo==true)
</code></pre>
<p>
13. Always use the short form of the classname in code. Certain exception
do apply where the fully qualified classname is required such as when
java.sql.Date and java.util.Date are used in the same class. Otherwise, you
should always import the class and use the short name.
</p>
<pre class="prettyprint"><code>
try
{
}
catch (IOException e)
{
}
and not
try
{
}
catch (java.io.IOException e)
{
}
</code></pre>
<p>
14. Avoid using Iterators that are initialized outside of the loop.
</p>
<pre class="prettyprint"><code>
for (Iterator iter=getIterator(); iter.hasNext; )
{
}
and not
Iterator iter=getIterator();
for (;iter.hasNext; )
{
}
</code></pre>
<hr />
<p>
X/Emacs users might appreciate this in their .emacs file.
</p>
<pre class="prettyprint"><code>
(defun apache-turbine-mode ()
&quot;The Java mode specialization for Apache Turbine projects.&quot;
(if (not (assoc &quot;apache-turbine&quot; c-style-alist))
;; Define the Apache Turbine cc-mode style.
(c-add-style &quot;apache-turbine&quot; '(&quot;java&quot; (indent-tabs-mode . nil))))
(c-set-style &quot;apache-turbine&quot;)
(c-set-offset 'substatement-open 0 nil)
(setq mode-name &quot;Apache Turbine&quot;)
;; 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 Turbine mode.
(if (fboundp 'jde-mode)
(add-hook 'jde-mode-hook 'apache-turbine-mode)
(add-hook 'java-mode-hook 'apache-turbine-mode))
</code></pre>
<p>
Thanks for your cooperation.
</p>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2000–2025
<a href="https://turbine.apache.org/">Apache Software Foundation</a>
</p>
</div>
</div>
</footer>
</body>
</html>