[Avida-cvs] [avida-svn] r915 - development/documentation
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Aug 31 18:29:10 PDT 2006
Author: brysonda
Date: 2006-08-31 21:29:09 -0400 (Thu, 31 Aug 2006)
New Revision: 915
Modified:
development/documentation/code_standards.html
Log:
Finish writing coding standards documentation.
Modified: development/documentation/code_standards.html
===================================================================
--- development/documentation/code_standards.html 2006-08-31 02:53:41 UTC (rev 914)
+++ development/documentation/code_standards.html 2006-09-01 01:29:09 UTC (rev 915)
@@ -5,7 +5,7 @@
<body>
<div style="float: right">
-Revised 2006-08-30 DMB
+Revised 2006-08-31 DMB
</div>
<p><a href="index.html">Return to the Index</a></p>
@@ -35,6 +35,9 @@
</li>
</ul>
+
+
+<p> </p>
<h3>Braces</h3>
<div style="margin-left: 10px">
@@ -46,7 +49,7 @@
exception to this rule is single line class methods, in which both braces
are allowed to be on the same line as the code (but only in pairs). Examples:
</p>
- <h5>Right:</h5>
+ <h5 style="color: #008800">Right:</h5>
<pre>
void cFoo::Method()
{
@@ -59,7 +62,7 @@
inline void Method()
{ // longer code in here }
</pre>
- <h5>Wrong:</h5>
+ <h5 style="color: #880000">Wrong:</h5>
<pre>
void cFoo::Method() {
// code goes here
@@ -73,21 +76,208 @@
</div>
<h4>For, While, Do Loops and Switch Statements</h4>
+ <div style="margin-left: 10px">
+ <p>
+ The open brace should go on the same line as the control structure,
+ the close brace on its own line. Examples:
+ </p>
+ <h5 style="color: #008800">Right:</h5>
+<pre>
+while (foo) {
+ // code goes here
+}
+</pre>
+ <h5 style="color: #880000">Wrong:</h5>
+<pre>
+while (foo)
+{
+}
+</pre>
+ </div>
+
<h4>If/Else Statements</h4>
+ <div style="margin-left: 10px">
+ <p>
+ The same formatting rules as for/while/etc., but if there is an else clause
+ the close brace should go on the same line as the else statement. Single
+ line if else statements should not get braces, unless they accompany a
+ multi-line statement. Examples:
+ </p>
+ <h5 style="color: #008800">Right:</h5>
+<pre>
+if (foo) {
+ DoSomething();
+ DoAnotherSomething();
+} else {
+ DoADifferentSomthing();
+}
+
+if (!foo) CallAFunction();
+else CallBFunction();
+</pre>
+ <h5 style="color: #880000">Wrong:</h5>
+<pre>
+if (foo)
+{
+ DoSomething();
+ DoAnotherSomething();
+} else
+ DoADifferentSomthing();
+
+if (!foo) {
+ CallAFunction();
+}
+else CallBFunction();
+</pre>
+ </div>
</div>
+
+<p> </p>
<h3>Parentheses</h3>
+<div style="margin-left: 10px">
+ <h4>Function Declarations and Calls</h4>
+ <div style="margin-left: 10px">
+ <p>
+ Do not use any space between the name and the open parenthesis, inside the
+ parentheses, or before commas that separate arguments. A single space
+ should follow commas that separate arguments. Examples:
+ </p>
+ <h5 style="color: #008800">Right:</h5>
+<pre>
+void cFoo::Method(int arg1, double arg2);
+int aFunction();
+</pre>
+ <h5 style="color: #880000">Wrong:</h5>
+<pre>
+void cFoo::Method( int arg1 , double arg2 );
+void cFoo::Method (int arg1, double arg2);
+int Function ( );
+</pre>
-<h3>NULL, false, and 0</h3>
+ </div>
+ <h4>Control Structures</h4>
+ <div style="margin-left: 10px">
+ <p>
+ Control structures such as if, for, while, do, and switch statements use a
+ single space before the open parenthesis, but spaces inside them.
+ </p>
+ </div>
+</div>
+
+
+<p> </p>
<h3>Other Punctation</h3>
+<ul>
+<li>
+ Pointer and reference types should be written with <strong>NO</strong> space
+ between the type name and the * or &.
+</li>
+</ul>
+
+<p> </p>
<h3>Include Guards and Statements</h3>
+<ul>
+<li>
+ All header files must use include guards, where the name of the guard is
+ exactly the filename with the period replaced with an underscore. For
+ example, <kbd>cPopulation.h</kbd> is guarded by:
+<pre>
+#ifndef cPopulation_h
+#define cPopulation_h
+// Code goes here
+#endif
+</pre>
+</li>
+<li>
+ Include statements in header files (<kbd>.h</kbd>) <em>must</em> check for
+ previously defined include guards. Example:
+<pre>
+#ifndef cPopulation_h
+#include cPopulation_h
+#endif
+</pre>
+</li>
+<li>
+ Include statements in implementation files (<kbd>.cc</kbd>) must
+ <strong>not</strong> check include guards.
+</li>
+</ul>
+
+
<p> </p>
<h2>Naming Conventions</h2>
+<ul>
+<li>
+ Variable names should be all lowercase. Multi-word variables should have the
+ words separated by underscores ('_'). Examples:
+<pre>
+i
+position
+this_is_my_var
+</pre>
+</li>
+<li>
+ Class instance member variables should have the same format as regular
+ variables, but must be prefixed with 'm_'. Examples:
+<pre>
+m_type
+m_lexeme
+m_my_component
+</pre>
+</li>
+<li>
+ All functions should begin with a capital letter followed by lowercase.
+ Additional words should be signified by capital letters. Underscores
+ should only be used to indicate a category of functions. Examples:
+<pre>
+Sort()
+ThisIsMyFunction()
+Inst_Divide()
+</pre>
+</li>
+<li>
+ All class names should begin with a lowercase 'c', followed by capital
+ letters leading each word (similar to functions). Templates have the same
+ pattern, but beginning with a 't', and enumeration types begin with an
+ 'e'. Lastly, structs should begin with a 's'. Examples:
+<pre>
+cGenome
+tArray
+eHeadTypes
+sSomeData
+</pre>
+</li>
+<li>
+ All constant values (even as listed in enumerations) should be in all
+ capital letters, with words separated by underscores. Examples:
+<pre>
+NUM_REGISTERS
+MAX_STRING_LENGTH
+</pre>
+</li>
+<li>
+ All filenames should be the same as the class defined within that file.
+ Header files should use <kbd>.h</kbd>; implementation files should use
+ <kbd>.cc</kbd>.
+ Examples:
+<pre>
+cGenome.h
+tArray.h
+cPopulation.cc
+</pre>
+</li>
+<li>
+ Generally, there should only be one class defined in each header/source
+ file pair. Implementation helper classes should be defined as internal
+ class members.
+</li>
+</ul>
<hr />
More information about the Avida-cvs
mailing list