Difference between revisions of "Style Guide"

From RifidiWiki

Jump to: navigation, search
(Rules for the code)
m (Reverted edits by Amesycyxa (Talk); changed back to last version by Kyle)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
=Look of the code=
 
=Look of the code=
 +
*We follow the naming conventions http://wiki.eclipse.org/Naming_Conventions
 
*All submitted files have to be formated eclipse style (Hit the autoformat Shift-Ctrl-F in eclipse)
 
*All submitted files have to be formated eclipse style (Hit the autoformat Shift-Ctrl-F in eclipse)
 
*Run Check Style on the file (use 'Sun Checks (Eclipse)' as check configuration) and eliminate ALL documentation warnings
 
*Run Check Style on the file (use 'Sun Checks (Eclipse)' as check configuration) and eliminate ALL documentation warnings
Line 5: Line 6:
  
 
=Rules for the code=
 
=Rules for the code=
*No System.out.println should go into SVN if it is not vital to the application (Use commons logging from apache). To use the apache logger, make sure that your project has a dependency on org.rifidi.depenedenciesAt the top of any class that you wish to use a logger for, place a statement like this, where <tt>ClassName</tt> is the name of the class:
+
*No System.out.println should go into SVN if it is not vital to the application.  Use [[Log4J]].
<pre>
+
    private static Log logger = LogFactory.getLog(ClassName.class);
+
</pre>
+
To use the logger to print out something:
+
<pre>
+
    logger.debug("Message Here");
+
</pre>
+
The output will look like this:
+
<pre>
+
    DEBUG [THREAD_NAME] (ClassName.java:139) - Message Here
+
</pre>
+
Notice that this allows us to know the class name and line number that the message was printed on.  This way we can identify where in the code out output is coming from, which helps to prevent "loose" System.out.print calls.
+
 
+
  
 
*All calls to syncExec and asyncExec have to be discussed with the team and should only be used if there is absolutely no way avoiding them
 
*All calls to syncExec and asyncExec have to be discussed with the team and should only be used if there is absolutely no way avoiding them
 
*Synchronizing UI and Model should occur via eclipse databinding and not through direct calls to the viewers
 
*Synchronizing UI and Model should occur via eclipse databinding and not through direct calls to the viewers
 +
 +
=Comments=
 +
*All classes and interfaces should have a description with the author's name and a high level description of what the class or interface does.
 +
*All methods should have method comments above them.
 +
*All files should have a header with the license that follows this template:
 +
<pre>
 +
/*
 +
*  ${file_name}
 +
*
 +
*  Project: Rifidi - A developer tool for RFID
 +
*  http://www.rifidi.org
 +
*  http://rifidi.sourceforge.net
 +
*  Copyright: Pramari LLC and the Rifidi Project
 +
*  License: Lesser GNU Public License (LGPL)
 +
*  http://www.opensource.org/licenses/lgpl-license.html
 +
*/
 +
</pre>
 +
To have this header generated for you automatically when you create a new file, click Windows->Preferences->Java->Code Style->Code Templates.  Then Click on Comments->Files, and add the header template above.  Now when you create a new file, make sure the box next to "Generate Comments" is checked.

Latest revision as of 19:44, 26 November 2010

Look of the code

  • We follow the naming conventions http://wiki.eclipse.org/Naming_Conventions
  • All submitted files have to be formated eclipse style (Hit the autoformat Shift-Ctrl-F in eclipse)
  • Run Check Style on the file (use 'Sun Checks (Eclipse)' as check configuration) and eliminate ALL documentation warnings
  • ALL beanproperties and methods MUST be documented.

Rules for the code

  • No System.out.println should go into SVN if it is not vital to the application. Use Log4J.
  • All calls to syncExec and asyncExec have to be discussed with the team and should only be used if there is absolutely no way avoiding them
  • Synchronizing UI and Model should occur via eclipse databinding and not through direct calls to the viewers

Comments

  • All classes and interfaces should have a description with the author's name and a high level description of what the class or interface does.
  • All methods should have method comments above them.
  • All files should have a header with the license that follows this template:
/*
 *  ${file_name}
 *
 *  Project: Rifidi - A developer tool for RFID
 *  http://www.rifidi.org
 *  http://rifidi.sourceforge.net
 *  Copyright: Pramari LLC and the Rifidi Project
 *  License: Lesser GNU Public License (LGPL)
 *  http://www.opensource.org/licenses/lgpl-license.html
 */

To have this header generated for you automatically when you create a new file, click Windows->Preferences->Java->Code Style->Code Templates. Then Click on Comments->Files, and add the header template above. Now when you create a new file, make sure the box next to "Generate Comments" is checked.

Personal tools