<HTML>
<HEAD>
   <TITLE>Community Programming Style Guide (CPSG)</TITLE>
   <META NAME="GENERATOR" CONTENT="Generated from XML"/>
<!--

<rdf:RDF xmlns="http://web.resource.org/cc/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<Work rdf:about="">
   <license rdf:resource="http://creativecommons.org/licenses/by-sa/2.0/" />
</Work>

<License rdf:about="http://creativecommons.org/licenses/by-sa/2.0/">
   <permits rdf:resource="http://web.resource.org/cc/Reproduction" />
   <permits rdf:resource="http://web.resource.org/cc/Distribution" />
   <requires rdf:resource="http://web.resource.org/cc/Notice" />
   <requires rdf:resource="http://web.resource.org/cc/Attribution" />
   <permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
   <requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
</License>

</rdf:RDF>

-->
</HEAD>

<BODY BGCOLOR="white">

<H1 ALIGN=CENTER>Community&nbsp;Programming&nbsp;Style&nbsp;Guide</H1>

<P ALIGN=CENTER>
  <TT>http://vinci.org/style</TT>
  <BR/>
  Release Date: 2005-08-19
  <BR/>
  <BR/>
  Editor: <A HREF="http://vinci.org/rlv">Ralph L. Vinciguerra</A>, 
  <A HREF="http://vinci.org/trinity">Trinity Research and Development
  Corporation</A>.
  <BR/>
  Contributors: ALPHATECH, <A HREF="http://baesystems.com">BAE Systems</A>
</P>

<P>
The goal of the CPSG (this document) is to create a flexible and
evolving programming style guide that is freely available.
</P>

<p>
<!-- Creative Commons License -->
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/2.0/">Creative Commons License</a> called "Attribution".
<!-- /Creative Commons License -->
See <a href="#AppendixC">Appendix C</a> for details.
<br/>
<a rel="license" href="http://creativecommons.org/licenses/by/2.0/">
<img alt="[Creative Commons License]" border="0"
src="somerights20-88x32.png"/></a>
<img alt="[By:]" border="0" src="by-32x32.png"/>
</p>

<P>
This document is maintained in
<A HREF="http://www.w3.org/XML/">XML format</A>,
from which an HTML version is generated (and should never be edited).
See <A HREF="#AppendixA">Appendix A</A> for details.
Note: <B>before trying to rewrite this document</B> for another project,
consider instead maintaining a <A HREF="#delta">"delta document"</A>
as described in the introduction.
</P>

<H1>Contents</H1>

<UL>
  <LI>
    Documentation Section
    <UL>
      <LI><A HREF="#Introduction">Introduction</A> </LI>
      <LI><A HREF="#VersionHistory">Version History</A></LI>
      <LI><A HREF="#Remaining">Remaining Work</A> </LI>
      <LI><A HREF="#References">References</A> </LI>
      <LI><A HREF="#AppendixA">Appendix A - Style Document Generation</A> </LI>
      <LI><A HREF="#AppendixB">Appendix B - Example Files</A> </LI>
      <LI><A HREF="#AppendixC">Appendix C - Document Licensing</A> </LI>
    </UL>
  </LI>
  <LI>
    Rule Section
    <UL>
      <LI><A HREF="#Naming">Naming Conventions</A> </LI>
      <LI><A HREF="#Scoping">Scoping</A> </LI>
      <LI><A HREF="#Classes">Classes</A> </LI>
      <LI><A HREF="#Comments">Comments</A> </LI>
      <LI><A HREF="#Files">Files</A> </LI>
      <LI><A HREF="#HeaderFiles">Header Files</A> </LI>
      <LI><A HREF="#ImplementationFiles">Implementation Files</A> </LI>
      <LI><A HREF="#Indentation">Indentation</A> </LI>
      <LI><A HREF="#Declarations">Declarations</A> </LI>
      <LI><A HREF="#ObjectOwnership">Object Ownership and Safety</A> </LI>
      <LI><A HREF="#Allocation">Allocation</A> </LI>
      <LI><A HREF="#Design">Design</A> </LI>
      <LI><A HREF="#Overloading">Overloading</A> </LI>
      <LI><A HREF="#Preprocessor">Preprocessor</A> </LI>
      <LI><A HREF="#Exceptions">Errors and Exceptions</A> </LI>
      <LI><A HREF="#Multithreading">Multithreading</A> </LI>
      <LI><A HREF="#DateRepresentation">Date Representation</A> </LI>
    </UL>
  </LI>
</UL>

<HR>

<A NAME="Introduction"><H1>Introduction</H1></A>

<P>This document defines the programming style that is used in a
community of developers. It is a reference document combining the best
programming styles in common use. The goal is to make source code more
readable and transportable among teams of programmers. By adhering to
these guidelines, it will be easier for programmers new to a project
to locate and recognize sections of the program and to be able to
discern the program semantics, structure, and control flow.</P>

<P>
Please note that this document is broken into two parts,
a prose documentation section, and a reference-like rules section.
</P>

<H2>Multiple Language Support</H2>

<P>To support the use of multiple languages, this style guide is maintained
as a database of rules. Each rule identifies one style element, and also
indicates the following additional attributes: </P>

<UL>
  <LI>Unique ID number, 4 digits, leading zero padded. </LI>
  <LI>Usage (Mandatory, Recommended, Suggested, Excepted) </LI>
  <LI>Languages covered (C, C++, Java), or
      conceptual rules (OO [Object Oriented Issues], Design)</LI>
  <LI>Topic and SubTopic (if needed)</LI>
  <LI>Description (one line summary)</LI>
  <LI>Detail (Fully detailed information, HTML formatted)</LI>
</UL>

<H2>Usage Categories</H2>

<P>Programming styles can be a source of controversy among programmers
on a team, and the best strategy is to label the severity of any particular
style component and allow each team to fine tune the style guide. However,
the best results are obtained when all teams ascribe to precisely the same
style guide. To facilitate consensus, each guideline includes a justification
when possible. </P>

<P>The usage categories are:
<UL>
  <LI><B>Mandatory</B> - Not an option, a mandate. </LI>
  <LI><B>Recommended</B>- Please use this, we are confident of it's value.</LI>
  <LI><B>Suggested</B> - A good idea. May be open for interpretation. </LI>
  <LI><B>Excepted</B> - Noted, but not followed. Used primarily for
      rules that are marginal and may not apply to all users, but would
      be included by a specific team in their "delta document".</LI>
</UL>
The names were selected to be meaningful, and to also have unique first
letters in case abbreviations are needed (M,R,S,E).
</P>

<A NAME="delta">
<H2>Delta Documents and Unique Rule IDs</H2>
</A>

<P>
Before you create "yet another style guide", consider using this document
as a baseline, and instead maintain a "delta document" that describes
the differences from this document. Your delta document must refer to the
exact version of this document it is based on. The version history here
will always identify those rules that have changed so that your delta document
can be updated to new versions easily.
</P>

<P>Each single recommendation will have a unique 4 digit number to support
cross referencing. The numbers are not necessarily in sequence, but serve
simply as unique IDs.</P>

<P>By having a unique tag for each rule, a project may elect to follow
this guide, and only note the differences as necessary.
New rules should be numbers prefixed with an X (for eXtension).
<B>These can be submitted to the CPSG Editor for future versions
of the style guide.</B></P>

<P>An example:
<BLOCKQUOTE>
  <P>PROGRAM_NAME specific Style Guide</P>
  <P>Based on the Community Programming Style Guide release 1.2</P>
  <PRE>
Change rule 0027:
  Usage: Mandatory-&gt;Suggested
  Languages: C++ -&gt; C++, Java
Change rule 0030:
  ...
Add rule X0001:
  Usage: ...
  Languages: ...
  </PRE>
</BLOCKQUOTE>
</P>

<H2>C++ Rationale</H2>

<P>C++ is a very flexible language that aims to keep the
programmer unrestricted; free to explore any object-oriented techniques.
The downside is that there is essentially no enforcement of what are commonly
considered to be good idioms for object oriented programming.
Also, certain dangerous techniques should be avoided. This guide includes
numerous rules to address these topics. </P>

<P>Tom Mueller stated the situation well in an issue of
<A HREF="http://www.sigs.com/">C++ Report</A>: </P>

<BLOCKQUOTE>
<P>Using C++ on a project of this size did not come without problems. Some
of the problems were related to the technology being new to the development
team. With so many people on the project, at so many different times, and
with such a wide variance in experience level, the flexibility of C++ led
to inconsistent code quality and design drift. Sometimes language features
would be used without knowing the true intent of the feature. For example,
while passing a constant reference parameter for efficient pass-by-value
is reasonable language use, declaring a pass-by-value parameter as a constant
really does not add significant semantic value to a program. This minor
aberration in language [use] would be inconsequential for a one-person
project or for a small team. But for a larger project, where an individual
may read code written by dozens of people in a short period of time, all
of it having different types of these aberrations, a nontrivial amount
of effort is spent trying to figure out if the developer who originally
wrote the code was doing something <B>tricky, unfamiliar, or just wrong.</B>
</P>
</BLOCKQUOTE>

<H2>Java Rationale</H2>

<P>
Java is designed to be a safer language. Many of the flexible, yet
confusing, aspects of C++ are removed. This guide also covers Java, and
it's interesting to note how many of the rules are not needed for
Java. However, the old adage "Give someone enough rope, and they'll
hang themselves" applies here, and Java deserves numerous rules as
well.
</P>

<!---------------------------------------------------------------------->

<A NAME="VersionHistory"></A>
<H1>Version History</H1>

<TABLE ALIGN="center" BORDER="1">
  <TR>
    <TH>Date</TH>
    <TH>Changes</TH>
  </TR>
  <TR>
    <TD>2005-08-19</TD>
    <TD>
      Rule 0109 reworded, since method inheritance is an override and not an
      overload. Also, issues with static overrides are addressed.
      <BR>
      Rule 0012 reworded to be clearer.
      <BR>
      Rule 0002 added to address the use of namespaces in header files.
      <BR>
      Rule 0065 relaxed from Manditory to Recommended.
    </TD>
  </TR>
  <TR>
    <TD>2005-05-17</TD>
    <TD>
      Cleanup of licensing text. Since we downgraded from
      Attribution-ShareAlike to only Atttribution,
      the introductory text needed to be adjusted.
      Also, several icons that were referring directly to the
      CreativeCommons site have been cached locally for speed.
    </TD>
  </TR>
  <TR>
    <TD>2005-05-11</TD>
    <TD>
      Changed to Creative Commons Licensing. Specifically the
      Attribution license.
    </TD>
  </TR>
  <TR>
    <TD>2004-01-23</TD>
    <TD>
      Some trouble with the XML mapping to HTML left some sections
      missing on the published version. This should correct that
      as we continue to transition to proper XML generation techniques.
    </TD>
  </TR>
  <TR>
    <TD>2003-08-14</TD>
    <TD>
      Typographic corrections to rules 0041, 0112, 0115.
    </TD>
  </TR>
  <TR>
    <TD>2003-08-12</TD>
    <TD>
      The licensing is relocated to a companion file,
      and this release is ready for a new review cycle.
    </TD>
  </TR>
  <TR>
    <TD>2003-08-11</TD>
    <TD>
       Extensive input from the ALPHATECH staff lead to the following
       changes.<BR><BR>
       New rules 0149, 0150, 0152, 0153.<BR>
       Deleted rules: 0124, 0125.<BR>
       Edited rules: 0012, 0022, 0026, 0043, 0044, 0045, 0065, 0071, 0072,
         0079, 0098, 0105, 0109, 0110, 0143.<BR>
       Rule 0112 reworked and rule 0113 pulled in.<BR>
       Rule 0036 reworked, and rule 0037 pulled in.<BR>
       Rule 0042 reworked, and rule 0043 pulled in.<BR>
       Renumbered the second duplicate rule ID 0082 to new rule 0151.<BR>
       Many rules were edited for gramatical reasons and are not
       listed here since the intent of the rule has not changed.<BR>
    </TD>
  </TR>
  <TR>
    <TD>2003-07-31</TD>
    <TD>
       Moved examples to separate files in an example subdirectory.<BR>
       Merged rules 0003, 0005, 0011, and 0014 into a restored rule 0001,
       with a new table.<BR>
    </TD>
  </TR>
  <TR>
    <TD>2003-07-15</TD>
    <TD>
      Reworked title to CPSG, and completed licensing under the GFDL.
    </TD>
  </TR>
  <TR>
    <TD>2002-03-14</TD>
    <TD>
      Renamed the "Exceptions" section to "Errors and Exceptions".
      <BR>
      Rule 0142 altered: updated text and relocated to the
      Errors and Exceptions section.
      <BR>
      Changed usage tags so that "Required" is replaced by "Mandatory"
      (same meaning).
      <BR>
      Ran spell checker on entire document.
    </TD>
  </TR>
  <TR>
    <TD>2002-01-28</TD>
    <TD>
      Established a new style guide for TRDC.
    </TD>
  </TR>
</TABLE>

<!---------------------------------------------------------------------->

<A NAME="Remaining"><H1>Remaining Work</H1></A>

<P>Here are items which still need attention. Remove them from this area
once they are completed. </P>

<UL>
  <LI>Rules for scripts</LI>
  <LI>Rules for structures and unions</LI>
  <LI>Rules for function overloading</LI>
  <LI>Rules for exceptions and errors</LI>
  <LI>Add IDL example.</LI> 
  <LI>Add appendix for lists of tools (javadoc, Doxygen, etc)</LI>
</UL>

<!---------------------------------------------------------------------->

<A NAME="References"><H1>References</H1></A>

<DL>
  <DT><A NAME="cxxcs"></A>[cxxcs] </DT>
  <DD>Herb Sutter, Andrei Alexandrescu,
  <I>C++ Coding Standards - 101 Rules, Guidelines, and Best Practices</I>,
  Addison Wesley C++ In-depth Series 2005.</DD>

  <DT><A NAME="ECxx"></A>[EC++] </DT>
  <DD>Scott Myers, <I>Effective C++ - 50 Ways to Improve Your Programs and
  Designs</I>, Addison Wesley Professional Computing Series, 1992. </DD>

  <DT><A NAME="CxxST"></A>[C++ST] </DT>
  <DD>Robert B. Murray, <I>C++ Strategies and Tactics</I>, Addison Wesley
  Professional Computing Series, 1993. </DD>

  <DT><A NAME="Sun"></A>[Sun]</DT>
  <DD>
    Sun's Software Code Conventions for Java
    {<A HREF="http://java.sun.com/docs/codeconv/">
    online</A>, <A HREF="other/sun/CodeConvTOC.doc.html">local copy</A>}
  </DD>

  <DT><A NAME="Netscape"></A>[Netscape]</DT>
  <DD>
    Netscape's Software Coding Standards Guide for Java
    {<A HREF="http://developer.netscape.com/docs/technote/java/codestyle.html">
    online</A>, <A HREF="other/netscape-1999-04.html">local copy</A>}
  </DD>

  <DT><A NAME="Poss"></A>[Poss]</DT>
  <DD>
    {<A HREF="http://www.possibility.com/Cpp/CppCodingStandard.html">
    online</A>, <A HREF="other/poss.html">local copy</A>}
  </DD>

  <DT><A NAME="X1"></A>[X1]</DT>
  <DD>
    <A HREF="other/sdp.txt">Software C &amp; C++ Coding Standards</A>
    - of unknown origin
  </DD>

  <DT><A NAME="Doxy"></A>[Doxy]</DT>
  <DD>
    <A HREF="http://www.doxygen.org">Doxygen</A> - main web site
  </DD>
</DL>

<!---------------------------------------------------------------------->
<A NAME="AppendixA"><H1>Appendix A - Style Document Generation</H1></A>

<P>
The original <A HREF="style.xml">source document</A> is maintained in
<A HREF="http://www.w3.org/XML/">XML format</A>,
from which other formats can be generated. The most common generated
format is HTML.
</P>

<P>
A small Java application named rlv.resub.RESub is used temporarily
to generate an HTML version by using simple substitution rules.
The next version will be generated with a proper XML parser from
the package "org.apache.xalan".
</P>

<!---------------------------------------------------------------------->
<A NAME="AppendixB"><H1>Appendix B - Example Files</H1></A>

<P>
Example files for several languages are provided
in a <A HREF="examples/">example subdirectory</A>.
Note that the file headers use <A HREF="http://cvshome.org">CVS</A>
automatic keywords. If you do not use CVS, substitute the literal
file name for the "Id" keywords, and removed the "Source" keywords.
</P>

<!---------------------------------------------------------------------->
<A NAME="AppendixC"><H1>Appendix C - License Summary</H1></A>

<p>
<!-- Creative Commons License -->
<a rel="license" href="http://creativecommons.org/licenses/by/2.0/">
<img alt="Creative Commons License" border="0" src="somerights20-88x32.png"/>
</a>
<img alt="[By:]" border="0" src="by-32x32.png"/>
<br/>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/2.0/">Creative Commons License</a> called "Attribution".
<!-- /Creative Commons License -->
</p>

<table align="center" border="2"><tbody><tr><td>
<p><b>Attribution 2.0 </b></p>

<p><strong>You are free:</strong></p>
<ul>
  <li>to copy, distribute, display, and perform the work</li>
  <li>to make derivative works</li>
  <li>to make commercial use of the work</li>
</ul>

<p><strong>Under the following conditions:</strong></p>
<ul>
  <li>[By:] - You must give the original author credit.</li>
  <li>For any reuse or distribution, you must make clear to others the license terms of this work.</li>
  <li>Any of these conditions can be waived if you get permission from the copyright holder.</li>
 </ul>

<p align="center" style="margin-top:40px"><strong>Your fair use and other rights are in no way affected by the above.</strong></p>
</td></tr></tbody></table>

<!---------------------------------------------------------------------->

<HR>
<H1>The Rules</H1>

<!-- ------------------------------------------------------------>

<RULESECT>
  <KEY>Naming</KEY>
  <NAME>Naming Conventions</NAME>
</RULESECT>

<RULE>
  <ID>0001</ID>
  <TOPIC>Naming</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>OO, C++, C, Java</LANG>
  <DESC>Use of case in program symbols</DESC>
  <DETAIL>
    <P>
    This table details the proper form for symbols representing
    classes, methods (functions), and fields (variables).
    We avoid the used of "_", this takes more
    characters, is harder to type, and is not typical of most developers.
    Also, leading underbars can be confused with some automatically
    generated internall compiler symbols.
    </P>
    <TABLE BORDER="1" CELLPADDING="2" CELLSPACING="0">
      <TBODY>
        <TR>
          <TH>Type</TH><TH>Rule</TH><TH>Example</TH>
        </TR>
        <TR>
          <TD>Classes</TD>
          <TD>Capitalize class names</TD>
          <TD>Indicator, CalculatorNumberRegister</TD>
        </TR>
        <TR>
          <TD>Fields (Variables)</TD>
          <TD>Do not capitalize fields, used embedded capitalizations
              for word concatenation.</TD>
          <TD>altitude,lastBufferEntry,imageHeader</TD>
        </TR>
        <TR>
          <TD>Methods (Functions)</TD>
          <TD>Do not capitalize methods, used embedded capitalizations.</TD>
          <TD>update, setRegisterCounter</TD>
        </TR>
      </TBODY>
    </TABLE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0004</ID>
  <TOPIC>Naming</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO, C++, C, Java</LANG>
  <DESC>Capitalize acronyms in names</DESC>
  <DETAIL>
    <P>Acronyms should stay completely capitalized if they are embedded in
    a name. Underbars may be used to divide pairs of acronyms when they occur
    adjacent to each other. It is better to pick a different name though,
    instead of using underbars and acronyms. </P>
    <P>Examples:
      <UL>
        <LI>CIAAgent</LI>
        <LI>CIA_FBILiason</LI>
      </UL>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0008</ID>
  <TOPIC>Naming</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>OO, C++, C, Java</LANG>
  <DESC>Use meaningful names</DESC>
  <DETAIL>
    <P>All names should be understandable English, and meaningful.
    The name should serve as documentation for a reader rather than a mnemonic
    shorthand for the writer. For example: <TT>loopCounter</TT> is preferable
    to <TT>lpCtr</TT>.</P>
    <P>
    An exception would be to user shorter names for heavily used
    iteration or access variables. For example a loop performing
    extensive indexing might use a variable named "i", instead
    of "loopIndex".
  </DETAIL>
</RULE>

<RULE>
  <ID>0013</ID>
  <TOPIC>Naming,Classes</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>OO, Java C++</LANG>
  <DESC>Use specific names for classes, avoid generic words</DESC>
  <DETAIL>
    <P> Avoid class names which use common words like <TT>Object</TT>
    that have a high probability of clashing with other libraries. Also, make
    the names as specific to the context as possible (Coordinate is more
    specific than Number). </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0015</ID>
  <TOPIC>Naming,Methods</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Methods names should contain the object of the verb</DESC>
  <DETAIL>
    <P> Names of methods (C++ functions) containing verbs should also
        contain the object of the verb (&quot;object&quot; in a grammatical
        sense) and should be in the form &quot;verbObject,&quot; for example
        <TT>getSignature</TT> instead of <TT>signatureGet</TT>. </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0016</ID>
  <TOPIC>Naming,Methods</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Use a restricted set of verbs for method names when appropriate</DESC>
  <DETAIL>
    <P> Verbs from the following list should be used to form function
        names when applicable:
      <UL>
        <LI>get<I>Object</I></LI>
        <LI>set<I>Object</I></LI>
        <LI>compare<I>Object</I></LI>
        <LI>compute<I>Object</I></LI>
        <LI>perform<I>Object</I></LI>
        <LI>process<I>Object</I></LI>
        <LI>test<I>Object</I></LI>
      </UL>
    </P>        
  </DETAIL>
</RULE>

<RULE>
  <ID>0017</ID>
  <TOPIC>Naming,Classses</TOPIC>
  <USAGE>Excepted</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>
    Sometimes, set and get prefixes may be eliminated from method names.
   </DESC>
  <DETAIL>
    <P>
      In some cases, a class is composed of small, heavily accessed
      components. The accessor functions for these components may
      eliminate the &quot;set&quot; and &quot;get&quot; prefixes if
      appropriate. For example,
      a class representing a 2-dimensional point might see these accessors in
      use:
      <PRE>
point.x(3);              // Set the X coordinate to 3.
point.x(4 + point.x());  // Shift in the X direction by 4.
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0138</ID>
  <TOPIC>Naming,Methods</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Methods returning new objects are prefixed with 'create'</DESC>
  <DETAIL>
    <P> Methods (C++ functions) that create new instances of a class
        should be prefixed with 'create'. </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0019</ID>
  <TOPIC>Naming,Files</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>File names should match class names</DESC>
  <DETAIL>
    <P>
      Files are named to match their associated classes exactly,
      with the same capitalization. If more than one implementation file is
      needed, they are distinguished by suffixes. If the operating
      system imposes a file name length limit, select a meaningful
      abbreviation.
      More arcane operating systems may not be able to comply.
      We hope the last of these systems pass into history rapidly. </P>
  </DETAIL>
</RULE>

<!-- ------------------------------------------------------------>

<RULESECT>
  <KEY>Scoping</KEY>
  <NAME>Scoping</NAME>
</RULESECT>

<RULE>
  <ID>0078</ID>
  <TOPIC>Scoping</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Avoid extern statements</DESC>
  <DETAIL>
    <P>
      To obtain declarations for external variables, files must include
      the relevant information rather than having literal <TT>extern</TT>
      statements.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0112</ID>
  <TOPIC>Scoping</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Limit the use of friend to specific well justified cases.</DESC>
  <DETAIL>
    <P>
      Friend functions should be used only for non-member binary
      operator functions and in special efficiency cases. The whole
      friend concept violates encapsulation and information hiding.
      Only classes which are very tightly coupled should be friends.
      One example of such tight coupling is a collection class and
      its iterator.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0010</ID>
  <TOPIC>Scoping,Naming,Variables</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>OO, C++</LANG>
  <DESC>Avoid global variables</DESC>
  <DETAIL>
    <P>
      Global variables should be avoided at all costs. Use class scoped
      static data members instead. If you are forced to use one,
      a <TT>g</TT> prefix is suggested to make the variable standout
      like a sore thumb.
      For example:
      <PRE>
        int gProcessNumber;
        char gFileName;
      </PRE>
    </P>
    <P>
      Be sure to comment all global variables and give them an initial value
      as well.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0149</ID>
  <TOPIC>Scoping,Naming,Variables</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO, C++, Java</LANG>
  <DESC>Use prefixes for easily identifying the scope of variables.</DESC>
  <DETAIL>
    <P>
      Many coding standards suggest a set of naming prefixes the help
      determine the scope or purpose of variables. This is not generally
      used and it may be hard to enforce across a large code base.
      However in certain well controlled bodies of code, it is possible
      to use this technique effectively. The following table demonstrates
      a set of prefixes:
    </P>
    <TABLE BORDER="1" CELLPADDING="2" CELLSPACING="0">
      <TBODY>
        <TR>
          <TH>Prefix</TH><TH>Example</TH><TH>Purpose</TH>
        </TR>
        <TR>
          <TD>m</TD>
          <TD>mCounter</TD>
          <TD>Identifies class member variables.</TD>
        </TR>
        <TR>
          <TD>p</TD>
          <TD>pArray</TD>
          <TD>Identifies pointer variables (not applicable to Java).</TD>
        </TR>
        <TR>
          <TD>g</TD>
          <TD>gProcessNumber</TD>
          <TD>Identifies global scope variables.</TD>
        </TR>
      </TBODY>
    </TABLE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0002</ID>
  <TOPIC>Scoping, Naming</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Avoid the forced use of namespaces in widely included header
        files.</DESC>
  <DETAIL>
    <P>
      If a header file is widely included, for example in as a library,
      it should not contain "using namespace" statements since these
      namespaces would then be forced on dependent
      classes. However, in the body files, the namespace statements can
      be used as needed for clarity and convenience. 
      <A HREF="#cxxcs">[cxxcs, rule 59]</A>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0110</ID>
  <TOPIC>Scoping, Naming</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++, Java</LANG>
  <DESC>Avoid package/namespace clutter.</DESC>
  <DETAIL>
    <P>
      Keep the packages/namespaces from being cluttered by restricting
      names to class scope where possible. If a class X is only used
      by a single other class A, nest the class X inside A. Enums
      can be similarly scoped.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0012</ID>
  <TOPIC>Scoping,Naming,Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Use Packages/Namespaces for class naming.</DESC>
  <DETAIL>
    <P>Define packages (Java) or namespaces (C++) to prevent class name
    collisions. If packages or namespaces are not available, then
    use a one or more letter prefix for class names,
    starting the prefix with an upper
    case letter to observe the convention for class naming.
    For example, a project named IMAX could use <TT>Ix</TT> for all it's
    classes. A subsystem named AIMS might use <TT>Am</TT>. Some examples:
    </P>
    <BLOCKQUOTE>
      IxImage<BR>
      AmFile<BR>
    </BLOCKQUOTE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0036</ID>
  <TOPIC>Scoping,Access</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Make all class members private, with limited exceptions.</DESC>
  <DETAIL>
    <P>
      Make all class members <B>private</B> to maintain
      the object-oriented design technique data hiding,
      and to keep users of classes independent
      of their implementation.
    </P>
    <P>
      Exception: Use <B>protected</B> keyword to provide direct
      member access for derived subclasses, whether the subclasses
      are created at the same time or in the future. This is
      more complex class design issues that requires attention
      to the future evolution of the inheritance hierachy.
    </P>
    <P>
      Exception: Use <B>public</B> in very restricted circumstances
      where a class is expected to <U>never</U> change it's
      implementation, and the access is so heavily used
      that the method call overhead is a problem.
      For example, a Coordinate class might have public members
      for it's x,y, and z values. Use this with caution!
    </P>
  </DETAIL>
</RULE>

<!-- -------------------------------------------------------------------->

<RULESECT>
  <KEY>Classes</KEY>
  <NAME>Classes</NAME>
</RULESECT>

<RULE>
  <ID>0028</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Define default method arguments in the header file.</DESC>
  <DETAIL>
    <P>
      Default function arguments values should be specified with
      the function declarations in the header files and not with
      the implementations in the body files.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0101</ID>
  <TOPIC>Classes,Protection</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Accessor should not modify the object, and should be const.</DESC>
  <DETAIL>
    <P>
      Accessor functions should not modify the object and are declared
      as <TT>const</TT> as well as returning an object (copied on the stack),
      a reference to a const object, or a pointer to a const object.
      This prevents unexpected side effects from occuring later in the
      the control flow.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0122</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Avoid the ellipses argument to methods.</DESC>
  <DETAIL>
    <P>
      Functions with the ellipses argument should be avoided except
      in rare cases. If required, use the <TT>&lt;stdargs.h&gt;</TT>
      implementation instead of the older <TT>&lt;varargs.h&gt;</TT> one.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0096</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Match order between init list and declaration inside class.</DESC>
  <DETAIL>
    <P>
      Members in an initialization list should be in the same order
      as their declaration inside the class.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0032</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use constructor initializer list instead of assignment.</DESC>
  <DETAIL>
    <P>
      Avoid using assignments to initialize class members; use the
      constructor initializer list instead. The use of these
      initialization techniques is expected by C++ programmers, and is
      also the only way to initialize reference and const members. Place
      the initializer list under the class name. For example:
      <PRE>
void
Thing::func(int i, long l) : member1(i), member2(l)
{
  ...
}
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0030</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>All destructors should be defined as virtual.</DESC>
  <DETAIL>
    <P>
      All destructors should be defined as virtual. This handles
      the situation where a pointer to a base class is used by <TT>delete</TT>
      to deallocate an object, and it is vital for the virtual behavior
      to allow the most derived class to free its data members through
      its own destructor first.
    </P>
    <P>
      Exceptions would be real-time or embedded applications where the
      virtual table traversal may not be justified in space or time impact.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0093</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Assignment operator should set all attributes.</DESC>
  <DETAIL>
    <P>
      In the assignment operator all data members and base classes
      should be assigned values to bring the object a known state.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0094</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Assignment operator should test for self assignment.</DESC>
  <DETAIL>
    <P>
      The assignment operator must test for assignment to itself
      as its first act. If this case is executed, the left hand object may be
      destroyed (as many assignment operators do) before it can be
      assigned values from the right hand object.
     </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0095</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Assignment operator return type should be const reference to class.
  </DESC>
  <DETAIL>
    <P>
      The return type of the assignment operator should be a <TT>const</TT>
      reference to the class and should return <TT>*this</TT>: </LI>
      <PRE>
const Thing&amp;
operator=(const Thing&amp; thing)
{
  if(thing == this) return(*this);
  else
  {
    ...
    return(*this);
  }
}
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0059</ID>
  <TOPIC>Class</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use constructor format for variable initialization.</DESC>
  <DETAIL>
    <P>
      Member variable initialization when performed in the declaration
      statement is performed in constructor format. For example:
      <PRE>
typedef UINT4 Time;
Time t(0);          // Correct.
Time t = 0;         // Incorrect.
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0060</ID>
  <TOPIC>Methods</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Divide up lengthy argument lists across lines.</DESC>
  <DETAIL>
    <P>
      Lengthy function argument lists should be divided across several
      lines, giving the opportunity to comment each argument on each line.
      Also, the first argument begins on a new line so that the length
      of the function name does not affect the indentation of the arguments
      making them easier to spot. Also note the aligned indents for
      the one line comments. An example:
      <PRE>
int
manyArgumentMethod(
  char c,     // A single character.
  Time time,  // The time in seconds.
  Date date); // The Gregorian date.
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0098</ID>
  <TOPIC>Class,Methods</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Unmodified arguments to methods should be passed as a const
        reference.</DESC>
  <DETAIL>
    <P>
      Reference or pointer parameters which are not modified by a
      member function should be declared as <TT>const</TT>, allowing
      the compiler to enforce the designer's intentions.
      Passing parameters as a <TT>const</TT> reference can be
      more efficient than passing them by value, since only
      a pointer is placed on the call stack, instead of a copy
      of the value. So, for example, if a pointer (4 bytes) is shorter
      than a copy of an entire class (many bytes) the call stack loading
      and unloading will be faster.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0099</ID>
  <TOPIC>Class</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Non mutating methods should be declared const.</DESC>
  <DETAIL>
    <P>
      Member functions which do not change an object's logical state
      should be declared const while the implementation casts away the const
      internally. This protects the caller from performing a dangerous cast
      that only the class implementer should address.
      This also allows the compiler to enforce the designer's intentions.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0141</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Implement all canonical methods</DESC>
  <DETAIL>
    <P> Regarding canonical methods (constructors, copy constructors,
        destructors) please do at least one of the following:
      <UL>
        <LI>Implement and test each method</LI>
        <LI>Make the method private so a compile time check will be made</LI>
        <LI>Put a special error handler into the method so at execution
            time, anyone calling it will be notified.</LI>
      </UL>
    </P>
    <P>We do not want each compiler making arbitrary decisions about where
       each method is implemented.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0150</ID>
  <TOPIC>Classes</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Order the class implementation.</DESC>
  <DETAIL>
    <P>
      To aid readability, order the class implementation into
      these sections:
    </P>
    <UL>
      <LI>public section including:
        <UL>
          <LI>constructors</LI>
          <LI>destructors</LI>
          <LI>methods</LI>
          <LI>members</LI>
        </UL>
      </LI>
      <LI>protected section including:
        <UL>
          <LI>methods</LI>
          <LI>members</LI>
        </UL>
      </LI>
      <LI>private section including:
        <UL>
          <LI>methods</LI>
          <LI>members</LI>
        </UL>
      </LI>
    </UL>
  </DETAIL>
</RULE>

<RULE>
  <ID>0038</ID>
  <TOPIC>Method Declarations</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Define methods as virtual to allow sub classes to express virtual
        behavior.
  </DESC>
  <DETAIL>
    <P>
      In general, member functions (except the constructors and assignment
      operators) should be declared virtual to allow derived classes to
      express virtual behavior. If a member function must explicitly avoid
      virtual behavior, then leave out the virtual keyword.
    </P>
  </DETAIL>
</RULE>

<P><!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Comments</KEY>
  <NAME>Comments</NAME>
</RULESECT>

<RULE>
  <ID>0082</ID>
  <TOPIC>Comments</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Use English language comments.</DESC>
  <DETAIL>
    <P> All comment text is in the English language. This is meant
        to match the largest common base of programmer fluency. Translations
        to other languages can be included if needed.
        </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0151</ID>
  <TOPIC>Comments</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Do not disable code with commenting</DESC>
  <DETAIL>
    <P>
      Do not use C-style comments to 'comment-out' sections of
      code. If other C comments are encountered some compilers may not nest the
      comments properly. In C++, use the preprocessor directives like
      <TT>#ifdef ENABLE_THIS / #endif</TT> instead. In Java,
      us a simple <TT>if(false) { ... }</TT> instead.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0021</ID>
  <TOPIC>Comments</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Comments for statements have matching indent depth.</DESC>
  <DETAIL>
    <P> When comment lines are associated with statements, the
        indent depth is matched (Java code is shown):</P>
    <PRE>
// The main loop.
//
int fact = 1;
int fib = 0;
for(int i=1; i&lt;=4; i++)
{
  // Perform the calculations.
  fact *= i;
  fib += i;

  // Display our progress.
  Susyem.out.println("Factorial so far is "+fact);
  System.out.println("Fibonacci so far is "+fib);
}
    </PRE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0022</ID>
  <TOPIC>Comments</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Single line comments are placed at the end of the statement.</DESC>
  <DETAIL>
    <P>If a short single line comment applies to one or more statements,
       it can be placed after the statement on the same line
       preceded by the usual "<TT>// </TT>" introduction.</P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0023</ID>
  <TOPIC>Comments</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Align trailing comments</DESC>
  <DETAIL>
    <P>
      If multiple statements are near each other with trailing comments,
      try to align the comments vertically. If a few statements are
      exceptionally long, don't let them force all the other comments out.
      For example:
      <PRE>
int   i;          // Iteration variable.
Image inputData;  // The input image.
char  string;     // A temporary buffer.
Image imageWithManyPixels;  // The big image.
int   depth;      // The water depth.
      </PRE>
    </P>
  </DETAIL>
</RULE>


<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Files</KEY>
  <NAME>Files</NAME>
</RULESECT>

<RULE>
  <ID>0018</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Use specific files to implement classes</DESC>
  <DETAIL>
    <P> In Java, each public class is implemented in a single file
        This is enforced by the compiler.
        Inner and private classes can be placed into the same file. </P>

    <P> In C++, Each class has two files: one header file and one or more
        implementation files. The header file should define one class only,
        or a small group of very tightly coupled classes. It should also be
        named to match the class name exactly. </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0145</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java</LANG>
  <DESC>Use proper file name suffixes</DESC>
  <DETAIL>
    <P>
      For Java the source files are suffixed with ".java". This is the
      only choice, and is enforced by the compiler.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0072</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++,sh,csh,ksh,perl,python,matlab</LANG>
  <DESC>Use common file name suffixes</DESC>
  <DETAIL>
    <P>
      For Java, long ago Sun established the suffix <TT>java</TT>
      and it is now written in stone. The shorter <TT>j</TT> would
      have been welcome but probably conflicted with some other preexisting
      system.
    </P>
    <P>
      For C++, the file name suffixes are <TT>.hh</TT> for header files and
      <TT>.cc</TT> for implementation files. The lower case doubled letters
      distinguish these file from C source files, and are the easiest to type
      (no shifting, and a repeated single character us very fast to type).
      These are less desirable, but often seen alternatives:
    </P>
    <TABLE BORDER="1" ALIGN="center">
      <TBODY>
        <TR>
          <TD><TT>.hpp .cpp</TT></TD>
	  <TD>Extra characters.</TD>
        </TR>
        <TR>
          <TD><TT>.hxx .cxx</TT></TD>
          <TD>More characters to type, and cryptic rotate "+" concept.</TD>
        </TR>
        <TR>
          <TD><TT>.h .C</TT></TD>
          <TD>Header file not distinguished between C/C++. 
              Needs Shift key. Dangerous on case-insensitive systems.</TD>
        </TR>
        <TR>
          <TD><TT>.H .C</TT></TD>
          <TD>Needs shift key.
              Dangerous on case-insensitive systems.</TD>
        </TR>
      </TBODY>     
    </TABLE>
    <P>
      For scripts, an official script suffix is best.
      The inconvenience of the extra suffix when executing scripts can
      be addressed by creating a symbolic link (on UNIX),
      or a "shortcut" (on Windows) with the shortened name if desired.
      The suffixes have proven to be useful for development tools as
      well as certain operating system file classification systems
      which need this extra information when processing or analyzing files.
      <UL>
        <LI><TT>sh</TT> - bourne shell</LI>
        <LI><TT>csh</TT> - cshell</LI>
        <LI><TT>ksh</TT> - kshell</LI>
        <LI><TT>pl</TT> - perl</LI>
        <LI><TT>m</TT> - matlab</LI>
        <LI><TT>py</TT> - python</LI>
      </UL>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0024</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Keep lines shorter than 78 characters.</DESC>
  <DETAIL>
    <P> Each line in the file should be less than or equal to 78 characters
    long to avoid problems with printing and various screen editors. </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0025</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Break long lines just before operators</DESC>
  <DETAIL>
    <P> If a language statement must be broken across a line, break the
    statement just before an operator, and start the next line indented,
    with the operator at the front. This reinforces the fact that the
    start of the second line is a continuation of the previous line. </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0026</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Recomended</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Supply header comment blocks for every file.</DESC>
  <DETAIL>
    <P>
      Each file also has specific requirements for commenting content.
      All files need to have the starting comments similar to these:
    </P>
    <PRE>
// Example.java
// Copyright 2001-2003 YoyoDyne, all rights reserved.
    </PRE>
    <P>
      If you are using the CVS or related version control systems
      you can use the special tags that are automatically substituted
      instead. Refer to the <A HREF="examples/">example subdirectory</A>.
    </P>
    <P>
      Any extra header information beyond the copyright is less
      important now that Javadoc and <A HREF="#doxy">Doxygen</A>
      solutions are available. See the other rules for class and
      method documentation for details.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0143</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java</LANG>
  <DESC>Make import statements as literal as possible.</DESC>
  <DETAIL>
    <P>
      It is not a good practice in import statements to use the "*"
      wildcard character to allow access to an entire level of the package
      hierarchy. Instead, it's more useful to call out individual classes
      with separate import statements. This makes it easier to determine
      the dependencies between java source files.
    </P>
    <P>
      The exception to this rule is the use of standard Java packages
      in which a large number of the classes are in use, and the number
      of import statements would be prohibitive.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0027</ID>
  <TOPIC>Files</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Mark spots in the code that need further attention.</DESC>
  <DETAIL>
    <P>
      Mark spots in the code which require future attention in comments
      with the special sequence <TT>XXX:</TT>. This can be used as a search
      field to locate problem areas. This is in keeping with common
      practice for open source development (Linux, FreeBSD, etc).
    </P>
    <P>
      It is also an advantage to append include your own initials
      if resolution of the issue should be referred to you.
    </P>
    <P>
      Examples:
      <UL>
        <LI>
          <TT>
            /*&nbsp;XXX:RLV:&nbsp;The&nbsp;next&nbsp;version&nbsp;should&nbsp;use&nbsp;a&nbsp;bubble&nbsp;sort&nbsp;here.&nbsp;*/
          </TT>
        </LI>
        <LI>
          <TT>
            /*&nbsp;XXX:&nbsp;This&nbsp;method&nbsp;needs&nbsp;to&nbsp;switch&nbsp;from&nbsp;HashTable&nbsp;to&nbsp;HashMap.&nbsp;*/
          </TT>
        </LI>
      </UL>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0039</ID>
  <TOPIC>Files,Inclusion</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++, C</LANG>
  <DESC>Never include an implementation file.</DESC>
  <DETAIL>
    <P>
      Implementation files must <B>never</B> include other implementation
      files. Although the compilers will support this, it is unexpected and
      can confuse developers working on the program.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0076</ID>
  <TOPIC>File Inclusion</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use forward declaration where possible.</DESC>
  <DETAIL>
    <P>
      Header files only include header files for classes used in
      that classes declaration, otherwise, forward declarations are used
      instead. This speeds compilations. Forward declarations merely identify
      the particular name as a class:
      <PRE>
class Foo;

class Bar
{
   Bar(Foo* x);
}
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0006</ID>
  <TOPIC>Variable/Scoping</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Declare variables in the smallest enclosing scope possible.</DESC>
  <DETAIL>
    <P>
      Variables should be declared in the smallest enclosing scope possible.
      This makes it easier to locate their declarations.
    </P>      
  </DETAIL>
</RULE>

<RULE>
  <ID>0007</ID>
  <TOPIC>Variable/Declaration</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Declare only one variable per line.</DESC>
  <DETAIL>
    <P>
      All variables should be separately declared, one variable per
      line. This promotes proper commenting of each variable. In some cases a
      group of variables are tightly coupled and can exist on one line: (e.g.
      <TT>x,y,z</TT>).
    </P>
  </DETAIL>
</RULE>


<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>HeaderFiles</KEY>
  <NAME>Header Files and General Documentation</NAME>
</RULESECT>

<RULE>
  <ID>0152</ID>
  <TOPIC>Documentation</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>When using Doxygen, stay compatible with Javadoc</DESC>
  <DETAIL>
    <P>
      <A HREF="#doxy">Doxygen</A> supports both an
      "at" sign prefix and a backslash prefix. Use only the
      "at"sign prefix to maintain compatibility with Javadoc.
      The backslash form can only be used if you can guarantee
      your source code won't be reused by another project that might want
      to use a more common tool like Javadoc.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0040</ID>
  <TOPIC>Files/Classes</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++,Java</LANG>
  <DESC>One class per file</DESC>
  <DETAIL>
    <P>
      Each file (header file in C++) should declare only one class.
      Mixing multiple classes into single header files makes it difficult
      to locate the code for any given class.
      In Java, nested classes are allowed for this purpose, but should be
      used carefully.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0077</ID>
  <TOPIC>Files/Header</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++,C</LANG>
  <DESC>Header file contents.</DESC>
  <DETAIL>
    <P>
      Each header file has the following basic order of contents:
      <UL>
        <LI>Preprocessor tests for inclusion. </LI>
        <LI>File Comment block </LI>
        <LI>Preprocessor protected include statements </LI>
        <LI>Forward declarations </LI>
        <LI>File local typedefs </LI>
        <LI>Extern and constant declarations </LI>
        <LI>Struct, union, and class definition blocks </LI>
        <LI>Inline function definitions </LI>
      </UL>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0041</ID>
  <TOPIC>Preprocessor</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++, C</LANG>
  <DESC>Use the preprocessor to prevent multiple processing of includes.</DESC>
  <DETAIL>
    <P>
      The very first and the last lines of each header file contain
      special preprocessor lines to prevent multiple processing of the
      same header file during compilation. A unique symbol is defined which
      can be tested by the compiler. At the top of each header file:
    </P>
    <PRE>
#ifndef <I>EXAMPLE</I>_HH
#define <I>EXAMPLE</I>_HH
    </PRE>
    <P>
      At the very end of each header file there's a companion line:
    </P>
    <PRE>
#endif
    </PRE>
    <P>
      Then in each effort to include the designated include file,
      Any <TT>#include</TT> statements are each individually wrapped
      as follows to improve compiler efficiency. This allows the compiler to
      avoid even opening any additional files unless the files have not yet
      been seen. See a later rule which shows how the tested symbol is
      defined. In code control systems like ClearCASE (tm), the speed
      improvements can be dramatic. An example follows:
      <PRE>
#ifndef <I>EXAMPLE</I>_HH
#include &quot;<I>Example</I>.hh&quot;
#endif
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0043</ID>
  <TOPIC>Comments/Class</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java,C++</LANG>
  <DESC>Precede each class definition by a comment header.</DESC>
  <DETAIL>
    <P>
      Each class definition will be preceded by a comment block
      to describe the class.
      See the <A HREF="examples/">example subdirectory</A>.
    </P>
    <P>
      The specialized tags shown work in several documentation generating
      systems including Javadoc, and Doxygen.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0044</ID>
  <TOPIC>Comments/Method</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Precede each method with a comment block</DESC>
  <DETAIL>
    <P>
      Within the class declaration, each member function or attribute
      is preceded by a comment block which has a very specific format.
      This is the prime location for general information used by people
      calling the class methods. In C++ the header file should be
      preferred over the body file as the body file is not
      always distributed.
      See the <A HREF="examples/">example subdirectory</A>.
      This format is compatible across javadoc and <A HREF="#doxy">Doxygen</A>.
    </P>
    <P>
      Optional: Also note that the example's the method name is placed
      on it's own line, left justified to make it easier to scan
      visually down through a class for a particular method by name.
      If the usual technique of putting the keywords and method name
      on one lines are used, the method name ends up at an
      unpredictable depth making it difficult to spot.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0045</ID>
  <TOPIC>Comments/Methods</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Break methods into related groups</DESC>
  <DETAIL>
    <P>
      Methods can be broken into groups by using a horizontal
      lines in comments and a title. For example:
    </P>
    <PRE>
  //
  //---- Method Group 1 ---------------------------------
  //

  ...

  //
  //---- Method Group 2  ---------------------------
  //
    </PRE>
    <P>
      Unfortunately Javadoc does not support this formally,
      as it alphabetizes all the methods instead. This is an interesting
      tradeoff, but the organization of the source code this way can
      still be valuable. Doxygen does support this through specialized
      tags, but unfortunately, this would be lost in Javadoc processing.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0046</ID>
  <TOPIC>Method/Arguments</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use const on method arguments when possible.</DESC>
  <DETAIL>
    <P>
      Const should be used as the default designation for function
      arguments, unless the function needs to return information through the
      arguments in question. Many believe that const should be the the language
      default and a new keyword like <TT>volatile</TT> would be available for
      non-const needs. The following C++ example function shows a const
      in every possible location:
      <BLOCKQUOTE>
        <PRE>
  const Point&amp; convert(const Point&amp; point) const;
        </PRE>
      </BLOCKQUOTE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0047</ID>
  <TOPIC>Comments/Method</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Put a comment block before each inline method.</DESC>
  <DETAIL>
    <P>
      In-line member functions have special needs. For each function,
      put a conventional declaration inside the class declaration block with
      it's associated preceding comment block describing it's use. After all,
      inline functions are used in exactly the same manner as regular
      functions. After the end of the class declaration block place the
      complete implementations for all the in-line member functions.
      For example:
      <PRE>
  /**
   * An inline function of note.
   */
  inline void
  Example::func()
  {
    ...
  }

  /**
   * Yet another inline function of note.
   */
  inline void
  Example::func2()
  {
    ...
  }
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0074</ID>
  <TOPIC>Methods/Inline</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Contructors, destructors, and virtual methods are not inline.</DESC>
  <DETAIL>
    <P>
      Constructors, destructors, and virtual methods must not be
      declared inline. The address of these methods may be preserved,
      possibly implicitly, and would result in multiple copies of the code
      being created.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0102</ID>
  <TOPIC>Methods/Inline</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Only very small functions should be inlined.</DESC>
  <DETAIL>
    <P>
      Only accessor, mutator, and very short functions can be declared
      <TT>inline</TT>. Code bloat can be severe otherwise.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0103</ID>
  <TOPIC>Methods/Inline</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Avoid I/O in inline methods.</DESC>
  <DETAIL>
    <P>
      I/O (via iostream.h) should not be performed within inline
      functions, otherwise code bloat via the include of iostream.h can occur.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0048</ID>
  <TOPIC>typedefs</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Gather typedefs in a single file</DESC>
  <DETAIL>
    <P>
      All system-wide typedefs are collected in a shared header file.
      If the system is divided into reusable subsystems, then each sub-system
      has it's own shared header file with typedefs. </LI>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0049</ID>
  <TOPIC>Enumerations</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Declare enumerations in a relevant class.</DESC>
  <DETAIL>
    <P>
      Enumerations should be declared within a relevant class to
      obtain qualified name scoping. The enum itself should be named with the
      same conventions as a class (capitalized). The enum members are similar
      to symbolic constants and should be each all upper case. Also, its very
      useful to define an explicit illegal value for error checking. Enums
      values can order themselves automatically, so the illegal value is
      forced to -1 at the end of the list, allowing automatic numbering
      for the regular values. Here is an example:
      <PRE>
class Display
{
  enum Color { RED, GREEN, BLUE, ILLEGAL=-1};
};
      </PRE>
      Accessing one of these enums would be as follows:
      <PRE>
color = Display::RED;
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0050</ID>
  <TOPIC>Inheritance</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java</LANG>
  <DESC>Divide lengthy extension lists (derivation in C++) across lines</DESC>
  <DETAIL>
    <P>
      Lengthy derivation lists should be divided across lines. In Java:
      <PRE>
class SubClass extends
  SuperClass1, SuperClass2, SuperClass3, ...
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0051</ID>
  <TOPIC>Access</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Order the access identifiers</DESC>
  <DETAIL>
    <P>
      Member access identifiers in class declarations should be ordered
      public, protected, then private, with the private identifier explicitly
      specified; it is the default if no designator is present can
      be confusing if absent.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0075</ID>
  <TOPIC>Class/Layout</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>In a class, methods first, then attributes</DESC>
  <DETAIL>
    <P>
      In the class declaration, member functions are declared first,
      followed by data members.
    </P>
  </DETAIL>
</RULE>

<!---------------------------------------------------------------------->
<RULESECT>
  <KEY>ImplementationFiles</KEY>
  <NAME>Implementation Files</NAME>
</RULESECT>

<RULE>
  <ID>0079</ID>
  <TOPIC>Files/Layout</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Implementation file layout</DESC>
  <DETAIL>
    <P>
      Each implementation file has the following components:
      <UL>
        <LI>File header comments including the file
            name and copyright information.</LI>
        <LI>
          Include directives, with at least the header file for the
          current class
        </LI>
        <LI>Global data initialization </LI>
        <LI>Static data initialization </LI>
        <LI>Static data function declarations </LI>
        <LI>Friend function and binary operator declarations </LI>
        <LI>Member function definitions </LI>
        <LI>Static function definitions </LI>
      </UL>
      See the <A HREF="examples/">example subdirectory</A>.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0052</ID>
  <TOPIC>Files/Layout</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Precede method implementations by comment blocks</DESC>
  <DETAIL>
    <P>
      Each function is preceded by a comment block with a description
      of its detailed implementation as needed. This information is an
      extension to the short information provided in the header file for
      each function. The user of this class should only need to read the
      header file comments and declarations to effectively use this
      function and only consult the implementation file when studying
      the implementation is warranted.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0054</ID>
  <TOPIC>Methods</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Keep method implementations under 100 lines of code.</DESC>
  <DETAIL>
    <P>
      Try to keep method implementations less than 100 lines in
      length. Methods that are shorter are easier to comprehend and
      maintain. Shorter methods also support a modular approach where
      complex operations are subdivided into simpler operations.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0080</ID>
  <TOPIC>Classes,Scoping</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Do not use the "this" prefix to access members.</DESC>
  <DETAIL>
    <P>
      In the definition of methods, references to class
      data members should not use the historical <TT>this</TT> pointer, since
      the language supplies it implicitly. Since the most common activity in
      methods is the manipulation of member data, this assumption is
      justified. Some style guides recommend the use of a special prefix for
      all data members; although this is better than using the <TT>this</TT>
      pointer, it still is not justified as above. However, many projects and
      libraries have started using special prefixes like &quot;my&quot; for
      class data members so if it can be consistently applied across a
      related set of classes, then this is reasonable.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0055</ID>
  <TOPIC>Syntax</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Make operator priority explicit with parentheses.</DESC>
  <DETAIL>
    <P>
      Parenthesize complex expressions if operator priority is in
      doubt. For example:
      <PRE>
result = (one + two) * three;
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0056</ID>
  <TOPIC>Conversion</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Use function-style type conversion.</DESC>
  <DETAIL>
    <P>
      Instead of &quot;casts&quot; for explicit type conversion,
      apply a function style conversion with the name of the required data type
      to the variable or value:
      <PRE>
int i(4);
float x = float(i);
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0057</ID>
  <TOPIC>Syntax</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Use compound assignment operators</DESC>
  <DETAIL>
    <P>
      Use compound assignment operators whenever possible, as they
      are natural to Java, C++, and C. They aid rapid comprehension of the
      operation. For example, use:
      <PRE>
result += 2;
      </PRE>
      instead of:
      <PRE>
result = result + 2;
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0058</ID>
  <TOPIC>Syntax</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Use monadic operators over compound operators if possible.</DESC>
  <DETAIL>
    <P>
      If a compound assignment operator <TT>+=</TT> or <TT>-=</TT>only
      requires changing the value by one, use the monadic increment or
      decrement operators:
      <PRE>
result++;
++result;
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0061</ID>
  <TOPIC>Variables</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Initialize pointers.</DESC>
  <DETAIL>
    <P>
      Initialize pointers when they are defined. If no value is ready,
      initialize them to 0. For example:
      <PRE>
int two(2);
int* twoPtr(&amp;two);     // twoPtr is a pointer to an int
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0062</ID>
  <TOPIC>Pointers</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++,C</LANG>
  <DESC>Test for null pointers wherever practical</DESC>
  <DETAIL>
    <P>
      Test for 0 pointers explicitly when possible:
      <PRE>
if(pointerVar == 0) cout &lt;&lt; &quot;Economic Module: Oops!&quot; &lt;&lt; endl;
else pointerVar-&gt;computeGrossNationalProduct();
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0127</ID>
  <TOPIC>Class,Variables,Assignment</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Use initialization instead of assignment for efficiency.</DESC>
  <DETAIL>
    <P>
      Use initialization instead of assignment for efficiency. Thus
      a declaration followed by an assignment requires calls to the constructor
      and the assignment operator, whereas initialization will simply call the
      constructor.
    </P>
  </DETAIL>
</RULE>

<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Indentation</KEY>
  <NAME>Indentation</NAME>
</RULESECT>

<P>
  Indentation of the code supports readability, and it needs to be consistent
  across all the software so that the developers can learn to recognize the
  spatial patterns in the source code. Each section below deals with a single
  code layout issue.
</P>

<RULE>
  <ID>0063</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Do not uses tab characters for indentation.</DESC>
  <DETAIL>
    <P>
      All indentation is performed with space characters instead
      of tabs. Tabs can confuse printers and editors. Many
      text editors can be adjusted to map the tab key to the correct
      number of spaces automatically.</LI>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0064</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Use 2 spaces for indentation when possible.</DESC>
  <DETAIL>
    <P>
      All indentation is done with two spaces per indent level. Two
      spaces is optimal for supporting deeply nested code and is more
      convenient than typing three or more spaces to achieve each indent
      level. If small changes are in progress on a file with a different
      indentation scheme, conform to the existing scheme.
      Each file should exhibit only one scheme.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0065</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Line up the curly brace code blocks vertically.</DESC>
  <DETAIL>
    <P>
      The curly braces mark code blocks and are lined up with
      the statement with which they are associated. The statements within
      the block are indented within those braces. This provides a reasonable
      visual form for the block. One can quickly scan for the block starts and
      ends and it easier to perceive nested cases. The old Kernigan&amp;Ritchie
      technique of "hiding" an open brace at the end of a line
      tends to obscure this visual form, and makes the visualization of
      the code structure more difficult.
      An example with one level of code block nesting, notice how your
      eye can pick out the nesting immediately:
    </P>
    <PRE>
if(value == true)
{
  System.out.println("The value is true");
  if(value2 == true)
  {
    System.out.println("The other value is true too.");
  }
}
    </PRE>
  </DETAIL>
</RULE>


<RULE>
  <ID>0066</ID>
  <TOPIC>Code Structure</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Put special ending comments on long code blocks.</DESC>
  <DETAIL>
    <P>
      If a code block (<TT>{}</TT>) is exceptionally long, put an
      in-line comment after the closing brace to correlate with the conditional
      that may be present at the start of the block, otherwise select a unique
      phrase.
      <PRE>
if(value == true)
{
  ...many, many lines....
}  // if(value == true)
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0067</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Single statement code blocks on a single line can extend a
        conditional.</DESC>
  <DETAIL>
    <P>
      If a conditional statement has a short executable result,
      then it may be placed after the test without
      the braces as follows:
      <PRE>
if(value == YABBA) Yabba();
if(value == DABBA) Dabba();
if(value == DOO) Doo();
      </PRE>
      This is best used for a set of short test and dispatch cases,
      and makes it easier to read. However, this can cause trouble
      during debugging in the setting of breakpoints to note whether
      the case has executed. See rule 0068 for an alternative.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0068</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>No conditional statements on their own line without braces.</DESC>
  <DETAIL>
    <P>
      A single statement which is the result of a conditional test
      should not be placed on it's own line without braces
      to surround it. Without the braces the statement relies on
      indentation as the sole means to define the code structure which is
      risky, and can lead to errors and difficult to find bugs.
    </P>
    <P>
      Correct:
    </P>
    <PRE>
if(value == true)
{
  System.out.println("The value is true.");
}
if(otherValue == true)
{
  System.out.println("The otherValue is true.");
}
    </PRE>
    <P>
      Incorrect:
    </P>
    <PRE>
if(value == true)
  System.out.println("The value is true.");
if(otherValue == true)
  System.out.println("The otherValue is true.");
    </PRE>
    <P>
      The down side, for blocks with only one statement, is that
      the code uses extra vertical space (2 extra lines). With caution,
      one can break this recommended rule, realizing the danger to the
      proper perception of program structure, that is then only clearly
      indicated by indentation. The tradeoff between conciseness and
      easily perceived structure is at issue here. We recommend structural
      clarity over conciseness.
    </P>
  </DETAIL>
</RULE>


<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Declarations</KEY>
  <NAME>Declarations</NAME>
</RULESECT>

<RULE>
  <ID>0153</ID>
  <TOPIC>Variables/Declaration</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Declare variables in the narrowest appropriate scope.</DESC>
  <DETAIL>
    If a variable is only needed within a code block,
    declare that variable in the narrowed scope of that
    code block rather than at class or method scope.
    This also makes it easier to locate the relevant declarations.
  </DETAIL>
</RULE>

<RULE>
  <ID>0084</ID>
  <TOPIC>Variables/Declaration</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>
    Do not use the for loop initializer to declare extended
    scope variables.
  </DESC>
  <DETAIL>
    <P>
      Declarations of variables should not be used in the initializer
      section of <TT>for</TT> statements if the variables value will
      be used after the for loop exits. The newer language specifications
      are changing the scope of initializer section variables limiting them to
      the <TT>for</TT> statement and the enclosed block <B>only</B>. Instead,
      it is best to place them just before the <TT>for</TT> statement.
      <PRE>
int i;
for(i=0; i&lt;10; i++) { ... }
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0085</ID>
  <TOPIC>Variables/Declarations</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Do not use unamed structures or classes</DESC>
  <DETAIL>
    <P>
      All Class and structure declarations should have a name and
      should not also be used to declare instances. Below shows the proper
      separation of a structure and its instances.
    <PRE>
struct Coord
{
  int x,  // X Coordinate.
  int y   // Y coordinate.
};
struct Coord c1,c2;
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0086</ID>
  <TOPIC>Methods</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>All methods must have return types specified.</DESC>
  <DETAIL>
    <P>
      A functions should have explicitly stated return types. This
      includes the function <TT>main()</TT> that should now return
      <TT>int</TT> as the old <TT>exit()</TT> function can now be replaced
      by a <TT>return()</TT>.
      In older C compilers, functions which had no defined return types
      defaulted to <TT>int</TT> and supported a bad habit of underspecified
      function declarations.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0087</ID>
  <TOPIC>Indentation</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Left justify the method name in declarations.</DESC>
  <DETAIL>
    <P>
      The return type of all method declarations and definitions
      should be placed on a separate line before the method name allowing the
      method name to be left justified and easier to spot in the code.
      Example of a method declaration:
      <PRE>
/**
 * The locate method
 */
int
locate(int i);
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0088</ID>
  <TOPIC>Method Arguments</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>Java,C++,C</LANG>
  <DESC>Provide argument dummy names, and keep them consistent.</DESC>
  <DETAIL>
    <P>
      The names used for the arguments to functions should be provided
      in all cases. In C++ that dummy argument name should be the same
      for the declaration and definition. The name
      should be selected to help indicate the use of that particular argument:
    </P>
    <PRE>
long
power(long base, long exp);
    </PRE>
  </DETAIL>
</RULE>


<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>ObjectOwnership</KEY>
  <NAME>Object Ownership and Safety</NAME>
</RULESECT>

<RULE>
  <ID>0092</ID>
  <TOPIC>Object Ownership</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>OO, C++, Java</LANG>
  <DESC>Sharing access to instances</DESC>
  <DETAIL>
    <P>Avoid writing functions which return non-const pointers or references
    to their member data. This undermines encapsulation and information hiding,
    making the caller dependent on the internal operations of the classes.</P>

    <P>Under no circumstances should you ever cast away a const on a
    return value. The const expresses a contract that the caller is
    being given access to a potentially private component which must
    not be modified. This is used on rare occasions for efficiency
    reasons to prevent an extra copy operation. However one should
    generally return copies of the data element if the size is not
    prohibitive.</P>

    <P>C++ Example:</P>

    <PRE>
class Foo
{
  private:
    int x;
  public:
    const int&amp; getX() { return x; }
}
    </PRE>

    <PRE>
main()
{
  ...
  Foo* f = new Foo();
  int&amp; myX = (int*)f-&gt;getX();  // Error:&nbsp;cast away the const!
  myX++;                       // Consequence: Modified private data member of Foo!
}
    </PRE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0091</ID>
  <TOPIC>Ownership</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Non const returned pointers assume the passage of object ownership
  </DESC>
  <DETAIL>
    <P>
      If a function returns a non-const pointer to an object, the
      ownership is passed to the caller who becomes responsible for deletion
      and management of the object. In all other cases, the caller is not the
      owner of the returned object.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0034</ID>
  <TOPIC>Object Lifespan</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++, C</LANG>
  <DESC>Set unused pointers to 0.</DESC>
  <DETAIL>
    <P>
      Pointers must be set to 0 unless they point to additional constructed
      objects. The older NULL practice should be replaced with a typeless 0,
      to prevent newer compilers from choking on NULL being set to
      <TT>(void*)0</TT>.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0035</ID>
  <TOPIC>Object Lifespan</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Destructors can be used on null pointers in some compilers.</DESC>
  <DETAIL>
    <P>
      Destructors can be invoked on pointers which are either valid
      or 0. For most compilers the <TT>delete</TT> call will properly handle
      a 0 argument. If your compiler does not, or you need to support
      multiple compilers, consider using a macro named DELETE_SAFE
      as shown below:
    </P>
    <PRE>
#define DELETE_SAFE (p) { if(p) delete (p); }
    </PRE>
  </DETAIL>
</RULE>

<RULE>
  <ID>0089</ID>
  <TOPIC>Ownership</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use reference arguments when possible</DESC>
  <DETAIL>
    <P>
      The arguments to function should be a reference to an object
      instead of the object itself when appropriate. Passing without the
      reference designation will cause a copy of the object to be created
      on the stack which can waste time and space of the object is large.
      There are special cases when the argument needs to be copied in case
      it might be changes by complex control flows.
    </P>
    <P>
      When passing arguments for input only also consider the use
      of the const keyword for those arguments.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0137</ID>
  <TOPIC>Ownership</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Functions should not store pointers to reference arguments.</DESC>
  <DETAIL>
    <P>
      Functions must not store pointers to arguments passed by reference.
      This is called the Linton Convention.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0090</ID>
  <TOPIC>Ownership</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Non const pointer arguments should be assumed to pass object ownership
    unless otherwise documented.
  </DESC>
  <DETAIL>
    <P>
      Unless otherwise documented,
      if a function argument is passed by non-const pointer the ownership
      should be assumed to be passed to the function, which then becomes
      responsible for the deletion and management of the object if so documented.
      All other cases leave the function's caller as the object owner.
      If the documentation does
      not indicate the assumption of ownership, the Linton Convention applies,
      and the caller must exercise care since the function might
      maintain an internal copy of the pointer which can become invalid after
      the call.
    </P>
    <P>
      Exceptions: this rule does not apply to cases where the caller is expecting
      a function to have the side effect of modifying the object passed by pointer.
      Another case is where the caller allocates a fresh object and then passes
      it in to be filled. In these kinds of cases, the documentation must clearly
      indicate these specialized behaviors.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0031</ID>
  <TOPIC>Ownership</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Code blocks that allocate objects must deallocate or pass ownership.</DESC>
  <DETAIL>
    <P>
      Each block of code which allocates new objects must delete
      them or pass ownership during their control flow. A memory leak will
      occur otherwise.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0100</ID>
  <TOPIC>Scope</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java,C++</LANG>
  <DESC>Avoid the use of public or protected data members.</DESC>
  <DETAIL>
    <P>
      Data members should not be marked as public or protected. This
      exposes the class implementation and violates encapsulation and
      information hiding. Inline functions should provide ways to modify
      or access an object's state instead; this also maintains efficiency.
    </P>
  </DETAIL>
</RULE>


<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Allocation</KEY>
  <NAME>Allocation</NAME>
</RULESECT>

<RULE>
  <ID>0029</ID>
  <TOPIC>Allocation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Classes that allocate on the heap or use external resources
    should clean up properly.</DESC>
  <DETAIL>
    <P>
      All classes which allocate their own additional objects on
      the heap (not the stack) or consume other shared resources must
      have definitions which support, as a minimum, the following member
      functions, making up a <I>canonical</I> class: </LI>
      <PRE>
class Thing
{
public:
  Thing();                  // Default constructor
  Thing(const Thing&amp;);  // Copy constructor
  virtual ~Thing();         // Destructor
  Thing&amp;
  operator=(const Thing&amp;);  // Assignment operator
protected:
private:
}
      </PRE>
      The compiler generated copy constructor and assignment operator will
      not attend to the complex internal data properly. Generally, these can
      be expected to act as simplistic shallow copies. If you desire deep copy
      semantics, you should define an explicit member function named
      <B>deepCopy</B>. If, for some reason you need the regular copy
      constructor syntax to have this behavior, comment the reasons well,
      and make the copy constructor simply call through to the deepCopy
      function. This is not recommended, since the compiler behavior has
      already set the assumption that copy constructors
      are shallow. By being explicit, the code will be easier to understand.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0033</ID>
  <TOPIC>Allocation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Constructors should initialize all class data.</DESC>
  <DETAIL>
    <P>
      All constructors must initialize all their data members. Unknown
      and unpredictable value can creep around can hide serious bugs.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0104</ID>
  <TOPIC>Allocation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Use <TT>new</TT> and <TT>delete</TT> instead of
       <TT>malloc</TT> and <TT>free</TT></DESC>
  <DETAIL>
    <P>
      Use <TT>new</TT> and <TT>delete</TT> instead of <TT>malloc()</TT>
      and <TT>free()</TT>, and never mix both in a program.
      The newer constructs are easier to understand, and easier to
      overload.
    </P>
    <P>
      Exception: if you are calling an older function (like something in libC)
      that may return "malloc"'d memory, they you should use free for that
      memory.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0105</ID>
  <TOPIC>Allocation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Use the array delete form on array deletions.</DESC>
  <DETAIL>
    <P>
      When an array is allocated with <TT>new</TT> directly, use
      the array form of <TT>delete</TT>. Some older compilers require this,
      but it also improves understanding.
      <PRE>
int array[] = new int[20];
...
delete[] array;
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0148</ID>
  <TOPIC>Allocation</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java</LANG>
  <DESC>Use finalize method only for class local resources.</DESC>
  <DETAIL>
    <P>
      The delayed nature of garbage collection makes the finalize
      method only appropriate for the release of resources local
      to the instance of the class. External resources, and methods on
      other classes that might block can cause JVM lockups.
      Manage these resources explicitly instead, outside of the finalize
      method.
    </P>
    <P><I>Rewritten from original material in JOOP, v11 n 1, Mar/Apr 1998.
    </I></P>
  </DETAIL>
</RULE>

<!---------------------------------------------------------------------->

<RULESECT>
  <KEY>Design</KEY>
  <NAME>Design</NAME>
</RULESECT>

<RULE>
  <ID>0126</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++</LANG>
  <DESC>Avoid static initialization problems.</DESC>
  <DETAIL>
    <P>
      Static objects from other files should not be used in functions
      called at static constructor time. The order of inter-file static
      construction is undefined by the C++ standards.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0132</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>OO, C++, Java</LANG>
  <DESC>Law of Demeter</DESC>
  <DETAIL>
    <P>A class should not depend on the internal structure of another class.
    This is often called the &quot;Law of Demeter&quot;. </P>

    <P>Stated more formally: In each method M of class C, only call methods
    of the following classes:</P>

    <UL>
      <LI>Classes of C's members</LI>
      <LI>Classes of the arguments of M</LI>
    </UL>
  </DETAIL>
</RULE>

<RULE>
  <ID>0111</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java,C++</LANG>
  <DESC>Reuse existing packages (libraries for C++).</DESC>
  <DETAIL>
    <P>
      Where possible use existing class packages (libraries)
      rather than implementing them. This can save time spent
      debugging classes which may never be as robust as public
      or commercial class libraries.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0073</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Inheritance declarations should specify the protection</DESC>
  <DETAIL>
    <P>
      Class inheritance declarations must specifically indicate the
      protection, since private is the default and is counter-intuitive.
      If private is desired, the following example shows the correct
      form:
      <PRE>
class Derived : private Base { ... };
      </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0109</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>A non-static method defined in a super class as non-virtual should not
        be overridden.</DESC>
  <DETAIL>
    <P>
      A non-static method defined in a super class as non-virtual should not be
      overridden, as the super classes' function will be hidden. If the method
      must be static, it cannot be virtual and special care must be given to
      call up to the super class to preserve the inherited behavior if that
      is appropriate to the method's intent.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0108</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Never redefine an inherited default parameter value.</DESC>
  <DETAIL>
    Never redefine an inherited default parameter value. Virtual
    functions are dynamically bound, default parameters are statically bound.
    This can produce unpredictable results <A HREF="#ECxx">[EC++, item 38]</A>.
  </DETAIL>
</RULE>


<RULE>
  <ID>0117</ID>
  <TOPIC>Design,Conversions</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use implicit conversions sparingly.</DESC>
  <DETAIL>
    <P>
      Provide and use implicit conversions sparingly. For example
      the following conversion from a C string to a String class instance is
      reasonable to provide and use:
      <PRE>
class String
{
public:
  String(const char* = &quot;&quot;);
};
...
void printOut(const String&amp;);
...
printOut(&quot;Testing&quot;);  // Uses implicit conversion.
      </PRE>
      Remember that single argument constructors are conversion functions
      which can be called explicitly or implicitly.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0123</ID>
  <TOPIC>Design,Conversion</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Avoid type casts</DESC>
  <DETAIL>
    <P>
      Avoid type casts unless absolutely necessary. They undermine
      the type safety offered by C++.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0128</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Avoid deep inheritance hierarchies</DESC>
  <DETAIL>
    <P>
      Inheritance hierarchies more than 3 levels deep should be watched,
      as the complexity may be too high.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0129</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Wide inheritance hierarchies may signal a design problem.</DESC>
  <DETAIL>
    <P>
      Wide class hierarchies with more than 3 children from a base
      class should be watched, and more commonality may be captured
      with inheritance or templates.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0130</ID>
  <TOPIC>Design,Classes</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Classes with fewer than 3 methods may need merging.</DESC>
  <DETAIL>
    <P>
      Classes with less than 3 methods are usually candidates
      for elimination by merging with other classes. Classes are expensive
      to maintain and should justify their presence.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0131</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Classes with too many methods may need to be split</DESC>
  <DETAIL>
    <P>
      Classes with too many member functions are candidates for splitting
      into separate classes.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0133</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Minimize class coupling</DESC>
  <DETAIL>
    <P>
      Minimize class coupling to make classes resistant to changes
      in the system at large. This aids reusability.
    </P>
    <P>
      ToDo: an example is needed.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0134</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++</LANG>
  <DESC>Use templates instead of inheritance for families of classes.</DESC>
  <DETAIL>
    <P>
      Use templates instead of inheritance when a family of classes
      only differ through member function argument and data member types.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0135</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>OO,Java,C++</LANG>
  <DESC>Use inheritance to represent the "is a" relationship.</DESC>
  <DETAIL>
    <P>
      Only use inheritance to express an "is a" relationship.
      Not for "has a".
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0136</ID>
  <TOPIC>Design,Inheritance</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>OO,C++</LANG>
  <DESC>Use multiple inheritance sparingly</DESC>
  <DETAIL>
    <P>
      Use multiple inheritance sparingly. It can often introduce
      potential ambiguities and complexity into programs, and these
      issues should be well understood before proceeding.
      Often the capability of multiple inheritance can be implemented
      with single inheritance and enlightened containment
      (inheritance by delegation).
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0144</ID>
  <TOPIC>Design</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>Java</LANG>
  <DESC>Use abstract super classes only when appropriate</DESC>
  <DETAIL>
    <P>
      Using an abstract class to embody pure design, i.e. nothing but
      abstract methods, is better accomplished in Java by using an
      interface.  Whenever, a design calls for an abstraction that
      includes instance/state and/or a partial implementation, however,
      an abstract class is the correct choice.
    </P>

    <P><I>
      From Teach Yourself Java in 21 Days by Laura Lemay and
      Charles Perkins.
    </I></P>
  </DETAIL>
</RULE>

<!-- ---------------------------------------------------------------------->

<RULESECT>
  <KEY>Operator Overloading</KEY>
  <NAME>Operator Overloading</NAME>
</RULESECT>

<P>
Operator overloading only applies to C++ and it must be used with
caution as it can suprise people reading the code who expect
the usual behavior associated with operators. For example,
redefining "+" to do something drastically different than
an addition-related operation is risky.
</P>

<P>A common goal in the implementation of overloaded operators is to suppress
the implicit conversions of arguments since implicit operations are harder
to recognize and to understand.</P>

<P>
In C++, the operators that can be overloaded are:
<PRE>
+    -    *    /    =    &lt;    &gt;    +=   -=   *=   /=   &lt;&lt;   &gt;&gt;
&lt;&lt;=  &gt;&gt;=  ==   !=   &lt;=   &gt;=   ++   --   %    &amp;    ^    !    |      
~    &amp;=   ^=   |=   &amp;&amp;   ||   %=   []   ()   -&gt;   -&gt;   new  delete
</PRE>

<RULE>
  <ID>0118</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Excluded</USAGE>
  <LANG>C++</LANG>
  <DESC>Unary operators should be defined as member functions</DESC>
  <DETAIL>
    <P>
      All unary operators should be defined as member functions.
      This will suppress implicit conversions of the argument. </LI>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0119</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Excluded</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Certain operators must be member functions per the language
    specification
  </DESC>
  <DETAIL>
    <P>
      The functions operator=, operator[], operator(), and operator-&gt;
      must be member functions based on the C++ language definition.
      These cannot be non-member functions.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0120</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Excluded</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Compound assignment operators should be defined as member functions
  </DESC>
  <DETAIL>
    <P>
      Compound assignment operators (+=, -=, *=, /=, ^=, &amp;=,
      |=, ~=, %=, &gt;&gt;=, &lt;&lt;=) should be defined as member functions
      to suppress implicit conversions.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0121</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Excluded</USAGE>
  <LANG>C++</LANG>
  <DESC>Define non-assignment binary operations as non-member friends.</DESC>
  <DETAIL>
    <P>
      All other binary operator functions should be defined as non-member
      friend functions so that both arguments are subject to the same access
      to implicit conversions.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0115</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Align with conventional meaning for overloaded operators.</DESC>
  <DETAIL>
    <P>
      Overloaded operator functions should mimic the built-in C++
      operators, rather than inventing new operator concepts. For
      example operator+ should be used for adding, concatenating, etc, but
      not for more complex operations.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0114</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use overloading of functions carefully</DESC>
  <DETAIL>
    <P>
      Reserve overloading for functions that perform the same activity
      from unrelated arguments (except for constructors). Flagrant use
      of overloading leads to confusing class designs.
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0116</ID>
  <TOPIC>Overloading</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>
    Define compliments to operators in terms of the original operator.
  </DESC>
  <DETAIL>
    <P>
      If an operator has a complement, that complementary operator
      should be defined in terms of the original operator. This prevents the
      implementations from drifting apart. For example:
      <PRE>
int
operator==(const Foo&amp; left, const Foo&amp; right)
{
  ...
}

int
operator!=(const Foo&amp; left, const Foo&amp; right)
{
  return( !(left == right));
}
      </PRE>
    </P>
  </DETAIL>
</RULE>

<!-- -------------------------------------------------------------------->

<RULESECT>
  <KEY>Preprocessor</KEY>
  <NAME>Preprocessor</NAME>
</RULESECT>

<P>The C preprocessor is quite powerful, but also must be used carefully
to avoid unexpected expansions before compilation. Fewer of its functions
are needed with C++. </P>

<RULE>
  <ID>0069</ID>
  <TOPIC>Preprocessing</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Use heavy parenthesizing in macro definitions</DESC>
  <DETAIL>
    <P>
      All arguments and the final result of a macro expansion string
      are surrounded by sets of parentheses to prevent complex expressions
      from interacting during expansion. Expressions can be placed into
      the arguments or the whole macro may be part of a complex
      expression.
      <PRE>
#define ADD(x,y) ((x)+(y))
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0070</ID>
  <TOPIC>Preprocessing</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Do not use the preprocesor to redefine language keywords.</DESC>
  <DETAIL>
    <P>
      No preprocessor commands which redefine or replace common language
      elements are allowed. This confuses C++ programmers reading the
      code, subverting their experience in recognizing the code structure.
      For example, <STRONG>do not</STRONG> use techniques like these:
      <PRE>
#define then
#define begin {
#define end }

if (x == 1) then
begin
  cout &lt;&lt; &quot;X is 1.&quot; &lt;&lt; endl;
end
      </PRE>
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0139</ID>
  <TOPIC>Preprocessor</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Do not use "//" style comments in multiline macro definitions.</DESC>
  <DETAIL>
    <P>
      Do not use &quot;//&quot; style comments in the definition
      of a multi-line macro. Since a macro definition can be composed of only
      one line (a clue that complex macros are a bad idea) all text after the
      first &quot;//&quot; will be considered a comment. For example:
      <PRE>
#define MY_MACRO(arg) arg+one+two+three+four+ \
// Now let's add five and six \
five+six;
      </PRE>
      If you would like to comment the macro, put it before the macro
      definition, or use &quot;/* */&quot; style comments.
    </P>
  </DETAIL>
</RULE>


<RULE>
  <ID>0071</ID>
  <TOPIC>Preprocessing</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>C++</LANG>
  <DESC>Define certain typedefs and <TT>#defines</TT> for convenience.</DESC>
  <DETAIL>
    <P>
      The following typedefs and <TT>#defines</TT> should be implemented or
      inherited from supporting header files:
      <PRE>
typedef int bool;
#define true 1  // As assumed by ANSI C++.
#define false 0 // As assumed by ANSI C++.
#define null 0  // 0, a typeless 0, to allow the compiler to convert it.
                // This prevents older code which uses NULL to properly
                // use a typeless 0 instead.
       </PRE>
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0106</ID>
  <TOPIC>Preprocessing</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use <TT>const</TT> and <TT>enum</TT> instead of #define</DESC>
  <DETAIL>
    <P>
      <TT>const</TT> and <TT>enum</TT> should replace the use of
      <TT>#define</TT> for manifest constants. This allows more additional
      type safety, and also is more efficient since it is evaluated at
      compile time (called "constant folding").
    </P>
  </DETAIL>
</RULE>

<RULE>
  <ID>0107</ID>
  <TOPIC>Preprocessing</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>C++</LANG>
  <DESC>Use inline functions and templates instead of macros.</DESC>
  <DETAIL>
    <P>
      Inline functions and templates should replace the use of macros.
    </P>
  </DETAIL>
</RULE>

<!-- -------------------------------------------------------------------->

<RULESECT>
  <KEY>Exceptions</KEY>
  <NAME>Errors and Exceptions</NAME>
</RULESECT>

<RULE>
  <ID>0140</ID>
  <TOPIC>Exceptions</TOPIC>
  <USAGE>Suggested</USAGE>
  <LANG>C++, Java</LANG>
  <DESC>Subsystem Exception Management</DESC>
  <DETAIL>
    <P>Each subsystem has a base exception, from which each class derived
    it's own base exception, which can then have sub exceptions as
    required for the methods of that class.</P>

    <P>The implementor of the subsystem decides how far down to supply
    detail.</P>

    <P>This allows the caller to deal with the exceptions at any of
    three levels as provided: complete details for all exceptions,
    details only on which class (one base exception for each class),
    or no details at all, for the entire subsystem.</P>

  </DETAIL>
</RULE>

<RULE>
  <ID>0142</ID>
  <TOPIC>Design,Execution</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>Java, C++, C</LANG>
  <DESC>Reusable packages should not exit.</DESC>
  <DETAIL>
    <P>
      If a package is meant as a reusable component for building larger systems,
      it should almost never stop the execution of the overall system.
      In Java this means no calls to <TT>System.exit()</TT>. In C++ and C
      this means no calls to <TT>exit()</TT>. By keeping the
      execution alive, other parts of the system may be able to continue
      execution and prevent data loss if the error is properly signaled.
      Consider the use of Exceptions instead (except C).
    </P>
  </DETAIL>
</RULE>

<!-- -------------------------------------------------------------------->

<RULESECT>
  <KEY>Multithreading</KEY>
  <NAME>Multithreading</NAME>
</RULESECT>

<RULE>
  <ID>0146</ID>
  <TOPIC>Multithreading</TOPIC>
  <USAGE>Recommended</USAGE>
  <LANG>OO, Java, C++</LANG>
  <DESC>Handle inter-subsystem calls under multithreading</DESC>
  <DETAIL>
    <P>
      Many modern applications employ multithreading to allow a single
      body of code to execute in several sections simultaneously.
      However, when these sections try to call each other,
      blocking can become a problem.
    </P>
    <P>
      Whenever one thread of control invokes another section of the
      system (called a "handler" here), especially over a network,
      it is best for the handler to return the thread of control as
      rapidly as possible to the caller.
      One way to achieve this is to make note of the message inside
      the handler, and then return immediately, allowing another
      thread belonging to the handler to work off the request.
      If the handler blocks, it puts the caller at risk while it is blocked.
    </P>
  </DETAIL>
</RULE>

<!-- -------------------------------------------------------------------->

<RULESECT>
  <KEY>Date Representation</KEY>
  <NAME>Date Representation</NAME>
</RULESECT>

<RULE>
  <ID>0147</ID>
  <TOPIC>Representing the year</TOPIC>
  <USAGE>Mandatory</USAGE>
  <LANG>OO, Java, C++, C</LANG>
  <DESC>Use sufficient precision when representing the year</DESC>
  <DETAIL>
    <P>
      When any date is represented, in running code or when stored in
      any persistent or transient storage (everywhere folks!),
      the date <STRONG>must</STRONG> be represented with at least 4 digits
      as a text string, or an integer of at least 16 bits as an internal
      number.
    </P>
    <P>
      Problems arise when computations compare pairs of dates
      that straddle January 1st, 2000 (2000-01-01).
      Although many clever schemes
      exist for making specialized assumptions and continuing to
      use 2 digit dates (for text strings) or 8-bit integers,
      these are perilous.
      Be advised that the trouble can occur any time the dates straddle
      2000-01-01. So these have been occurring for years, and will
      continue to occur in the future for software that is incorrectly
      implemented with insufficient precision in the year representation.
    </P>
    <P>
      Please overlook the storage size implications, as the reduction
      of latent bugs in the code is worth the impact.
    </P>
  </DETAIL>
</RULE>

<HR>

<P><SMALL>
$Id: style.xml,v 1.45 2005/08/19 15:43:53 rlv Exp $<BR>
$Source: /h/cm/style/style.xml,v $
</SMALL></P>

<ADDRESS>
<A HREF="http://vinci.org/rlv">
Ralph L. Vinciguerra</A> - <A HREF="http://vinci.org/trinity">TRDC</A> - Editor
</ADDRESS>

<!--

<RULE>
  <ID></ID>
  <TOPIC></TOPIC>
  <USAGE></USAGE>
  <LANG></LANG>
  <DESC></DESC>
  <DETAIL>
  </DETAIL>
</RULE>

The next available number is [0154]
Freed numbers: 0003, 0005, 0011, 0014, 0020, 0037, 0042, 0097, 0113,
0124, 0125.

-->

</BODY>
</HTML>
