1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<?xml version="1.0"?>
<document>
<properties>
<title>Coding Standards</title>
<author email="jvanzyl@zenplex.com">Velocity Documentation Team</author>
</properties>
<body>
<section name="Coding Standards">
<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 and you
are caught, you are responsible for also fixing your own code.</strong>
</p>
<p>
Below is a list of coding conventions that are specific to Velocity,
everything else not specificially mentioned here should follow the official
<a href="http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html">Sun
Java Coding Conventions</a>.
</p>
<p>
1. Brackets should begin and end on a new line. Examples:
</p>
<source test=""><![CDATA[
if ( foo )
{
// code here
}
try
{
// code here
}
catch (Exception bar)
{
// code here
}
finally
{
// code here
}
while ( true )
{
// code here
}
]]></source>
<p>
2. It is <strong>OK</strong> to have spaces between the parens or not. The
preference is to not include the extra spaces. For example, both of these are
ok:
</p>
<source test=""><![CDATA[
if (foo)
or
if ( foo )
]]></source>
<p>
3. 4 spaces. <strong>NO</strong> tabs. Period. We understand that a lot of you
like to use tabs, but the fact of the matter is that in a distributed
development enviroment, when the cvs commit messages get sent to a mailing list,
they are almost impossible to read if you use tabs.
</p>
<p>
In Emacs-speak, this translates to the following command:
(setq-default tab-width 4 indent-tabs-mode nil)
</p>
<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 your methods. Also, if you are
working on existing code and there currently isn't a javadoc for that
method/class/variable or whatever, then you should contribute and add it.
This will improve the project as a whole.
</p>
<p>
6. The <a href="license.html">Apache Software License</a> <strong>MUST</strong> be placed at the top
of each and every file.
</p>
<p>
7. If you contribute to a file (code or documentation), add yourself to the
top of the file. For java files the preferred Javadoc format is:
</p>
<source><![CDATA[
@author <a href="mailto:user@domain.com">John Doe</a>
]]></source>
<p>
Thanks for your cooperation.
</p>
</section>
<section name="More Fun For Emacs">
<p>
To make coding easier, following bit of Emacs LISP does
the 'right thing' with bracing, if you want.
</p>
<source><![CDATA[
(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))
]]></source>
<p>
Note that this will apply to all java in emacs.
To control it :
<ul>
<li>
Turn off : <code>M-: (remove-hook 'java-mode 'apache-jakarta-mode)</code>
</li>
<li>
Turn on : <code>M-: (add-hook 'java-mode 'apache-jakarta-mode)</code>
</li>
</ul>
'M-:' is <meta> followed by ':', of course.
It will be on by default at startup.
</p>
<p>
This was stolen lock, stock and barrel from the contribution
to the Turbine project by Daniel L. Rall. Thanks Daniel!
</p>
</section>
</body>
</document>
|