Differences between revisions 14 and 15
Revision 14 as of 2011-10-11 23:05:00
Size: 3945
Editor: cpc13-uddi19-2-0-cust312
Comment:
Revision 15 as of 2011-10-11 23:12:09
Size: 3869
Editor: c-76-115-137-211
Comment: despam
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
Below is a list of coding conventions that are specific to [[http://www.rapid-guaranteed-payday-loans.co.uk/|guaranteed payday loans]] Velocity, Below is a list of coding conventions that are specific to Velocity,

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 you commit code that does not follow these conventions and you are caught, you are responsible for also fixing your own code.

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

If your contribution will be making use of any of the logging facilities, please follow the projects LoggingLevel conventions as well.

1. Brackets should begin and end on a new line. Examples:

if ( foo )
{
    // code here
}

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

while ( true )
{
    // code here
}

2. It is OK to have spaces between the parens or not. The preference is to not include the extra spaces. For example, both of these are ok:

{{{if (foo)

or

if ( foo ) }}}

3. 4 spaces. NO 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 environment, when the svn commit messages get sent to a mailing list, they are almost impossible to read if you use tabs.

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

(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.

5. Javadoc MUST 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.

6. The Apache Software License MUST be placed at the top of each and every file.

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:

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

Thanks for your cooperation.

More Fun For Emacs

To make coding easier, the following bit of Emacs LISP does the 'right thing' with bracing, if you want.

(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))

Note that this will apply to all java in emacs. To control it :

  • Turn off :

M-: (remove-hook 'java-mode 'apache-jakarta-mode)
  • Turn on :

M-: (add-hook 'java-mode 'apache-jakarta-mode)

'M-:' is <meta> followed by ':', of course. It will be on by default at startup.

This was stolen lock, stock and barrel from the contribution to the Turbine project by Daniel L. Rall. Thanks Daniel!

CodeStandards (last edited 2011-10-11 23:12:09 by c-76-115-137-211)