<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../xsl/road-faq.xsl"?>

<rf:topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xsi:schemaLocation="http://schemas.roadintranet.org/road-faq-1 ../xsl/road-faq.xsd"  
   xmlns:rf="http://schemas.roadintranet.org/road-faq-1"
 title=" C++ and Perl Guidelines"
 file="cpp-guideline.xml"
 fileid="$Id: //main/2005/road/road-faq/xml/cpp-guideline.xml#23 $$Change: 1141 $"
 fileChange="$DateTime: 2010/01/03 12:13:50 $$Author: bbarber $">
    <div><h4>C++ and Perl Guidelines  -- Notes on using C++ and Perl from Road Intranet</h4></div>
    <rf:copyright>
        <a href="../../../road/COPYING.txt">Copyright</a> (c) 2008-2010, C.B. Barber
    </rf:copyright>
   <rf:section id="cpp-cpp-links" title="Useful Links for C++">
       <div>
           <p> This
               document records guidelines for using C++ and Perl.   Many guidelines apply to C# and
               Java programming.  Some guidelines are specific to C#.
               The primary references are <i>Framework Design Guidelines</i> 
               <rf:iref item="cwalK_2006" page=""/> 
                <i> Effective C++</i> <rf:iref item="meyeS_2005"  page=""
                />, and <i>Perl Best Practices</i> <rf:iref item="conwD_2005" />.
               The primary model is Nokia's Qt framework.   Please send comments and suggestions to <a
                   href="mailto:bradb@shore.net">bradb@shore.net</a>
           </p>
       </div>
       <div class="twocol">
         <div class="col leftcol">
             Help
            <ul><li>
                C++ In a Nutshell [<a href="#liscR_2003">liscR_2003</a>] -- 
                Concise and complete description of C++.
            </li><li>
                <a href="http://www.cplusplus.com/">cplusplus.com</a> -- The C++ Resources Network with documentation, tutorials, forums, and source code.
            </li><li>
                <a href="http://codeidol.com/">CodeIdol</a> -- free, on-line books on coding and IT
            </li><li>
                <a href="http://stackoverflow.com">Stackoverflow</a> -- free, expert advice on programming
              </li><li>
                  <a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a> (<a
                      href="http://stdcxx.apache.org/doc/stdlibug/">guide</a>, <a
                          href="http://stdcxx.apache.org/doc/stdlibref">classes</a>) -- Fully documented,
                  standards-compliant STL.
              </li></ul>

            Developer Resources
             <ul><li>
                 <a href="http://msdn.microsoft.com/">Microsoft MSDN</a>
             </li><li>
                 <a href="http://www.java2s.com/">Java2s</a> -- Extensive collection of simple, example code using Java, C++, XML, etc.  Separate sections for tutorial code.
             </li><li>
                 <a href="http://www.alphaworks.ibm.com/tech/adesigner">Accessibility Designer</a>
             </li></ul>
             
             Tables
             <ul><li>
             </li><li>
                 <a href="http://www.lookuptables.com/">ASCII, Unicode, Character code</a> --
                 character tables.
                 
             </li></ul>
         </div>
         <div class="col rightcol">
             C++ usage
             <ul><li>
             </li><li>
                 Geotechnical's <a href="http://geosoft.no/development/cppstyle.html"
                     >C++ Programming Style Guidelines</a>
             </li><li>
                 Henricson and Nyquist's <a href="http://hem.passagen.se/erinyq/industrial/"
                     >Industrial Strength C++</a>  -- with <a href="http://hem.passagen.se/erinyq/industrial/IndustrialStrength-Summary.html"
                         >rules and recommendations</a> (1997)
             </li><li>
                 Mozilla's <a href="http://developer.mozilla.org/en/docs/C%2B%2B_Portability_Guide"
                     >C++ Portability Guide</a>
             </li><li>
                 Open Directory (DMOZ) for <a href="http://www.dmoz.org/Computers/Programming/Languages/C%2b%2b/Style/"
                     >C++ Style</a>
             </li><li>
                 Todd Hoff's <a href="http://www.possibility.com/Cpp/CppCodingStandard.html">C++ Coding
                     Standard</a> -- with wikis on <a
                         href="http://www.possibility.com/epowiki/Wiki.jsp?page=Agile">Agile
                         Programming</a>,
                 <a
                     href="http://www.possibility.com/epowiki/Wiki.jsp?page=CodeReviews">Code
                     Reviews</a>, <a
                         href="http://www.possibility.com/epowiki/Wiki.jsp?page=SoftwareDevelopment">Software
                         Development</a>
                 and <a
                     href="http://www.possibility.com/epowiki/Wiki.jsp?page=UnitTestingAndTestDrivenDevelopment">Test
                     Driven Development</a>.
             </li><li>
                 <rf:iref item="qt-style"/>
             </li><li>
                 Uwyn's <a href="http://www.uwyn.com/resources/uwyn_cpp_coding_standard/index.html"
                     >C++ Coding Standard</a> (2002)
             </li><li>
                 Wikibook's C++ programming <a
                     href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code_Style"
                     >conventions</a>,
                 <a href="http://en.wikibooks.org/wiki/C++_Programming/Idioms"
                     >idioms</a>, and <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms"
                         >more idioms</a>
             </li><li>
                 Wikipedia's <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)"
                     >Design Patterns</a>, <a href="http://en.wikipedia.org/wiki/Programming_style"
                         >Programming Style</a>
             </li><li>
             </li></ul>
         </div>
      </div>
       <div>
           . <!-- clear the two column display -->
       </div>
   </rf:section>
    <rf:section id="cpp-guidelines" title="C++ Guidelines">
  
         <rf:item id="cpp-overall" title="Overall guidelines" date="Feb 2008" author="bbarber">
             Established programming languages such as C++ and Perl
             offer a wealth of choices for expressing your code.    Reading the manual is not
             enough.  These guidelines and books will help you develop a good programming style.
             <ul><li>
                 A good programming style improves the robustness, efficiency, and maintainability of your
                 code.  It reduces the cost of your software by reducing the number of bugs in your
                 programs, increasing its efficiency, and  making the code comprehensible.   A good
                 programming style conveys your intentions
                 clearly; it is neither clever nor obtuse. 
               <rf:iref item="conwD_2005" page="3-5, 453-456"/>.
              </li><li>
                 "Program in the future tense " -- "Good software adapts well to change. ...  To
                 program in the future tense is to accept that things will change and to be prepared
                 for it." <rf:iref
                     item="meyeS_1996" part="item 32"/>.
             </li><li>
                 Use a revision control system -- Software changes frequently and is defined by many  files. 
                 Changes in one file often need
                 corresponding changes to other files.  Use a revision control system to keep track
                 of these changes
                 <rf:iref item="conwD_2005"  page="441-442"/>.
                 Be rigorous about the configuration of test and deployed
                 software.   Integrate  your bug tracking and revision control systems.   Know what
                 source changes fixed a bug.  For each source directory, know what bugs were fixed
                 by changes within that source directory.
             </li><li>
                Use 3-part version numbers -- Have a standard for version numbers.  You need at
                least three fields: major, minor, and release.   Have a convention for developer
                releases
                <rf:iref item="conwD_2005" page="404-407"/>.  Perforce uses
                year.version.changelistnumber (e.g., 2007.2/122958).
            </li><li>
                 "Well-designed frameworks are consistent" -- A consistent framework allows you to
                 understand all of the framework after you understand a piece of the framework. <rf:iref item="cwalK_2006" page="6"/>
                 Consistent interfaces are easy to use correctly ; inconsistent interfaces are
                 aggravating <rf:iref item="meyeS_2005" page="80"/>.
             </li><li>
                 "Make interfaces easy to use correctly and hard to use incorrectly" -- Design your
                 API for ease of use.  "When in doubt do as the ints do."   Be leery of complex
                 usage rules.  For example, return smart pointers for automatic delete.  Use a Month
                 class instead of int              <rf:iref item="meyeS_2005"
                     part="item 18"/>.
             </li><li>
                 "Most importantly, try thinking of a program as a set of interacting concepts
                 represented as classes and objects, instead of the program as a bunch of data
                 structures with functions twiddling their bits." <rf:iref item="stroB_1993"
                     page="11"/>. 
             </li><li>
                 Encapsulation allows change -- "If something is encapsulated, it is hidden from
                 view. ... The fewer things can see it, the greater flexibility we have to change
                 it. ... count the number of functions that can access [a piece] of data." <rf:iref
                     item="meyeS_2005" page="99"/>.
             </li><li>
                 Dependency Inversion Principle -- "High-level modules should not depend upon
                 low-level modules.  Rather, both should depend upon abstractions.  Abstractions
                 should not depend upon details.  Rather, details should depend upon abstractions." 
                 With fewer, more stable dependencies, applications are easier to change and enhance
                 <rf:iref
                     item="suttH_2005" part="item 36"/>.
             </li><li>
                 Declarations should depend on declarations, not definitions -- Reduce dependencies
                 between modules by depending on class declarations instead of class definitions <rf:iref item="meyeS_2005"
                       page="143-144"/>
                 <ul><li>
                     Forward declaration --  When practical, use forward declarations of a class.   Forward declarations work
                 for references, pointers, pass by value, and return by value.   A forward
                 declaration of a nested class needs public accessibility. 
                 </li><li>
                      Opaque type -- Replace data members with a private, opaque types.  
                 </li><li>
                     Declaration-only -- Consider using a
                 declaration-only header file (e.g., STL's &lt;iosfwd>) .
                 </li></ul>
             </li><li>
                 Avoid cut-and-paste, do not repeat yourself -- If you want to cut-and-paste code within a file, define a subroutine
                 instead.  If you want to cut-and-paste subroutines between files, define a class or module
                 instead 
                 <rf:iref item="conwD_2005" page="401-404"/>.  Use cut-and-paste to copy
                 templates and other structures that should be used consistently across files. 
                 Be particularly careful of changes to cut-and-pasted code.  It is easy to make an inconsistent change that appears to
                 work OK.
             </li><li>
                 Flexibility via indirection -- "Almost all flexibility in software comes with an extra layer of
                 indirection (arrays, dynamic data structures, recursion, and so on).  Not
                 surprisingly, dynamic binding also depends on an extra layer of indirection."
                 <rf:iref item="clinM_1999" page="463"/>
             </li></ul>
         </rf:item>
         
         <rf:item id="cpp-terminology"  title="C++ terminology" date="Mar 2008" author="bbarber">
             <ul><li>
                 C++ is a federation of languages -- C++ combines multiple languages with different
                 rules and conventions <rf:iref item="meyeS_2005" part="item 1"/>.
                 <ul><li>
                     C -- The language C is the programming language underlying C++
                 </li><li>
                     Object-oriented C++ -- C++ extends C with classes, constructors, destructors,
                     inheritance, function overloading, and dynamic binding.
                 </li><li>
                     Template C++ -- Templates allow compile time instantiation of classes and
                     methods by type name.  Template metaprogramming supports compile-time
                     execution.  Generic algorithms may be written with templates.
                 </li><li>
                     Framework C++ -- A framework provides a library of useful classes,
                     templates, and generic algorithms.  The best known library is the STL (Standard Template Library).
                     The Qt libraries implement implicitly shared
                     objects and Java-style iterators.   Many of the recipes in Stephens, et.
                         al..'s <i>C++ Cookbook</i> (O'Reilly, 2006) are more clearly expressed
                     in Qt. 
                 </li></ul>
             </li><li>
                 Declaration -- "A declaration is the all-encompassing term for anything that tells
                 the compiler about an identifier. ... a declaration tells you an entity's name and
                 the external view of an entity, such as an object's type or a function's parameter" <rf:iref item="liscR_2003" page="12"/>.
                 <ul><li>
                     Specifiers -- List storage class first (e.g., extern, mutable, static), 
                     then type specifiers (e.g., int), followed by cv-qualifiers (const, volatile). 
                     Each level of pointer may have cv-qualifiers. <rf:iref item="liscR_2003"
                         page="31,33"/>.
                 </li><li>
                     Function pointer -- Use a typedef when declaring a function pointer  For example, <code>typedef void
                     (*MyFunction)(int);</code> defines a one argument function returning an
                     int.  Then declare the function pointer with <code>MyFunction fp;</code>
                     <rf:iref item="liscR_2003" page="34"/>.
                 </li><li>
                 </li><li>
                 </li><li>
                 </li></ul>
             </li><li>
                 Definition -- "A <i>definition</i> defines the storage, value, body, or contents of
                 a declaration. ... a definition provides the internal workings of the entity: the
                 storage and initial value of an object, a function body, and so on." <rf:iref
                 item="liscR_2003" page="12"/>.  Do not define objects in header files at
                 namespace-level.  Use 'extern' and declarations instead <rf:iref item="suttH_2005"
                     part="item 61"/>.
             </li><li>
                 Scope -- "A <i>scope</i> is a region of source code that contains declarations. ...
                 you can think of a scope as a dictionary of names mapped to declarations." <rf:iref
                     item="liscR_2003" page="14"/>.
             </li><li>
                 Name Lookup -- For the rules used to associate declarations with names see
                 <rf:iref item="liscR_2003" page="16-22"/>.
             </li><li>
                 Policy -- For templates, a policy customizes the behavior of the template.  It is
                 itself a template                 <rf:iref
                     item="liscR_2003" page="223-224"/>, <rf:iref
                         item="dewhSC_2005" part="item 56"/>.
                 For an example, see Stephens, et. al., <i>C++ Cookbook</i> (<a 
                     href="http://examples.oreilly.com/cplusplusckbk/CPP_cookbok_source.zip">5-10.hpp</a>) 
             </li><li>
                 POD Type -- "POD is short for Plain Old Data.  The fundamental types and enumerated
                 types are POD types, as are pointers and arrays of  POD types."  A POD class, 
                 struct, or union uses only POD types for nonstatic data.  POD types are invariant
                 under memcpy.  By default, non-static POD types are uninitialized  <rf:iref item="liscR_2003"
                     page="27-28, 135-136"/>. 
             </li><li>
                 Sequence point -- "Between sequence points, the compiler is free to reorder
                 expressions in any way that preserves the original semantics."   Only access global and
                 volatile objects immediately after a sequence point.   Between sequence points, do
                 not modify or access an object after modifying the object (e.g., <code>f(i++,
                 i++)</code>).  A sequence point occurs "at the end of every expression that is
                 not a subexpression," after evaluating all of a function's arguments, and after
                 copying a function's return value <rf:iref item="liscR_2003" page="57-58"/>.
             </li><li>
                 Traits -- For templates, a traits template or class defines tag structs and typedefs to describe
                 iterators, character classes, and built-in types <rf:iref item="meyeS_2005"
                     part="item 47"/>, <rf:iref
                         item="dewhSC_2005" part="item 54"/>.
             </li><li>
             </li></ul>
         </rf:item>
         
         <rf:item id="cpp-algorithm"  title="Guidelines for algorithms" date="Mar 2008" author="bbarber">
             <p>The STL and other libraries use templates to define generic algorithms.  For
                 introduction to algorithms and their unifying principles see <rf:iref
                     item="lippSB_2005" part="chapter 11"/>.   
             </p>
             <ul><li>
                 Algorithms are defined on iterators and ranges -- Generic algorithms are defined in terms of
                 iterators and iterator operations.  They do not themselves execute container
                 operations.  "In general, the generic algorithms operate on iterator pairs that
                 denote a range of elements in a container (or other sequence)."  <rf:iref
                     item="lippSB_2005" page="395, 397"/>.
             </li><li>
                 "Use a checked STL implementation"  -- Generic algorithms do not check their
                 arguments.   Iterators may be out-of-bounds.  Iterator ranges may be inverted or
                 refer to unrelated containers.  A checked STL library will catch these and other
                 errors <rf:iref item="suttH_2005" part="item 83"/>.
             </li><li>
                 Use pure functions for predicates -- Predicates used by algorithm must be pure
                 functions.  They always return the same value for the same arguments.  An algorithm
                 may invoke predicates in any order multiple times.  The algorithm may break
                 mysteriously if predicates return different results for the same argument <rf:iref
                     item="suttH_2005" part="item 87"/>.
             </li><li>
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-design" title="Guidelines for class and type design" date="Feb 2008" author="bbarber">
             <p>Design a framework from a set of usage scenarios and code samples.  The basic
                 scenarios are most important.  What can be done without documentation?</p>
            <p>See also <rf:iref item="cpp-extend"/>, <rf:iref item="cpp-types"/>, <rf:iref
                item="cpp-type-patterns"/>, <rf:iref item="cpp-value-types"/>, and <rf:iref item="cpp-inheritance"/>.</p>
             <ul><li>
             </li><li>
                 Class design is type design -- "Good types have a natural syntax, intuitive
                 semantics, and one or more efficient implementations."  Good classes answer the
                 following questions (quoted from <rf:iref item="meyeS_2005" part="item 19"/>):
                 <ul><li>
                     How should objects of your new type be created and destroyed?
                 </li><li>
                     How should object initialization differ from object assignment? --
                     Initialization may need to check its arguments.  Assignment may need to release
                     resources.
                 </li><li>
                     What does it mean for objects of your new type to be passed by value?
                 </li><li>
                     What are the restrictions on legal values of your new type? -- What are its
                     invariants?
                 </li><li>
                     Does your new type fit into an inheritance graph?                     
                 </li><li>
                     What kind of type conversions are allowed for your new type?
                 </li><li>
                     What operators and functions make sense for the new type?        
                 </li><li>
                     What standard functions should be disallowed?
                 </li><li>
                     Who should have access to the members of your new type?
                 </li><li>
                     What is the "undeclared interface" of your new type?  -- What kind of guarantees
                     does it offer with respect to performance, exception safety ..., and resource
                     usage ...?
                     What is the exception-safety guarantee for each function? <rf:iref
                         item="meyeS_2005" page="133-134"/>.
                 </li><li>
                     How general is your new type? -- Should it be a template?
                     
                 </li><li>
                     Is a new type really what you need? -- Should you define non-member functions
                     and templates instead?
                 </li><li>
                     
                 </li></ul>
             </li><li>
                 Reduce complexity -- "If things get too complicated, make more types" [J. Richter]
                 <rf:iref item="cwalK_2006" page="69"/>
             </li><li>
                 Save the best type names -- Use the best type names for the most commonly used
                 types <rf:iref item="cwalK_2006" page="26"/>,
             </li><li>
                 Avoid many abstractions -- The mainline scenarios should use few abstractions
                 <rf:iref item="cwalK_2006" page="28"/>
             </li><li>
                 Design the interface first -- When designing a program, class, API, module, or
                 function, design the interface first.  Create samples using your interface.
                  These samples will become your test cases, demos, and documentation examples.  Is
                  the interface natural?  Is it easy to understand?  Are likely variations
                  supported?  For a publishable API, get the API into use before the interface is frozen.
                 <rf:iref item="conwD_2005" page="397-401"/>.
             </li><li>
                 Provide a complete class rather than a minimal one -- Provide classes with a full
                 set of methods.  Do not force users to write their own convenience methods.  
                 Define methods in terms of the public interface when possible
                 <rf:iref item="conwD_2005" page="351-354"/>.
            </li><li>
                 Composable options vs. distinct methods -- Is the task composable?  Is there one
                 thing to do, but multiple ways to do it?  If so, consider a single command with
                 options.  If not, does the interface support several related, distinct tasks?  If
                 so, provide a separate command for each task.  
                 <rf:iref item="conwD_2005" page="400"/>.
             </li><li>
                 Define interfaces with portable types -- For binary compatibility, restrict
                 interfaces to built-in types.  STL types may differ between  compilers and
                 versions <rf:iref item="suttH_2005" part="item 63"/>.
             </li><li>
                 Basic scenario
                 <ul><li>
                     Instantiate one type -- A basic scenario should only require one type <rf:iref
                         item="cwalK_2006" page="22"/>
                 </li><li>
                     Simple initialization -- A basic scenario should not require extensive
                     initialization <rf:iref
                         item="cwalK_2006" page="22"/>
                 </li></ul>
             </li><li>
                 Cache -- A cache  saves results for future use.  They are widely used in software
                 and hardware.  Look for opportunities to use caches.  Be rigorous about the
                 dependencies that invalidate cache entries.  Keep statistics to validate your
                 choices
                 <rf:iref item="conwD_2005" page="460-464"/>.
             </li><li>
                 Use reference counting to simplify growth -- If software is successful, it will undergo rapid expansion
                 due to customer requests and bug reports.    "New development combined with bug
                 fixes tend to wreck havoc on the original crystal-clear design. ... One of the
                 major difficulties with chaotic software is memory corruption."   Reference
                 counted objects helps avoid memory leaks and premature object deletions
              <rf:iref item="bulkD_2000" page="177"/>.   Qt's implicitly shared objects are
                 reference counted.
             </li></ul>
         </rf:item>
        
        <rf:item id="cpp-collection"  title="Guidelines for collections and containers" date="Feb 2008" author="bbarber">
             <p>A <i>collection</i> or <i>container</i> is a data structure holding multiple
                 instances of a type.  It is typically implemented as a template.
             </p>
             <ul><li>
             </li><li>
                 Code for a specific container -- Do not try to write container-independent code.  Each
                 container has different performance characteristics and APIs.  Furthermore they
                 have different rules about invalidating iterators, pointers, and references 
                 <rf:iref item="meyeS_2001" part="item 2"/>.
             </li><li>
                 Define typedefs for containers  and names for iterators --  Use typedefs to improve the readability and
                 maintainability of your code (e.g., <code>typedef vector&lt;Widget>
                     Widgets</code>) <rf:iref item="meyeS_2001" page="18"/>.  Similarly name your
                 iterators (e.g., <code>istream_iterator&lt;int> dataBegin(dataFile)</code>)<rf:iref
                     item="meyeS_2001" page="35"/>.  
             </li><li>
                 Avoid working with one element at a time --  Let  the container do the work on
                 multiple elements at a time.  The STL algorithms use iterators, avoiding
                 the need to write loops <rf:iref
                     item="meyeS_2001" part="item 43"/>.  For example, to append half the elements of an array
                 use <code>v1.assign(v2.begin() + v2.size()/2, v2.end())</code>.  This is an example
                 of a range member function.  Similarly use insert() rather than copy() <rf:iref
                     item="meyeS_2001" part="item 5"/>.  To erase elements from a vector, string, or
                 deque, use remove_if() to move elements to the end and erase() to delete them <rf:iref
                 item="meyeS_2001" part="item 9"/>.   .
             </li><li>
                 Generator -- A generator is a co-routine that produces values on the fly <rf:iref
                     item="cwalK_2006" page="215"/>.
             </li><li>
                 foreach -- Design classes to work with STL's <code>foreach()</code> or Qt's
                 <code>foreach</code>.
             </li><li>
                 Naming convention -- Name collections with its type followed
                 by 'Collection'  (e.g., "MyTypeCollection")
                 <rf:iref item="cwalK_2006" page="220"/>.
             </li><li>
                 Prefer inexpensive copying of container elements -- Copying should be cheap and reliable for container
                 elements.   The copy constructor and copy assignment operator is used for
                 initialization, assignment, and algorithms <rf:iref item="meyeS_2001" part="item
                 3"/>.   The copy constructor is invoked for uninitialized objects (e.g., MyType
                 t2 = t; calling f(t), or returning from a function).  The assignment operator is
                 used to initialize the fields during copy construction.  <rf:iref item="stroB_1993"
                     page="237-239" />
             </li><li>
                 Prefer iterator over const_iterator -- You can not compare iterator with
                 const_iterators.  You can not insert or erase using const_iterators.    Use
                 const_iterators for algorithms <rf:iref item="meyeS_2001" part="item 26"/>.
             </li><li>
             </li></ul>
             
             <p>Hints</p>
             <ul><li>
             </li><li>
                 Use empty() instead of testing size() -- The size() of a container may be expensive
                 to compute <rf:iref item="meyeS_2001" part="item 4"/>.
             </li><li>
                 Do not return NULL -- Return an empty collection instead of returning 
                 a null value
                 <rf:iref item="cwalK_2006" page="217"/>.
             </li><li>
                 Do not return copies of arrays -- If a property must return a copy of an
                 array, it is too expensive.  Use a live collection instead <rf:iref
                     item="cwalK_2006" page="219"/>.
             </li><li>
                 Convert a vector to an array -- Test that the vector is non-empty,  then use
                 <code>&amp;v[0]</code>.  Do not cast an iterator as an array.   For C string
                 returns, copy  to a std::string (e..g, <code>string
                     s(vc.begin()vc.begin()+charsWritten)</code>)  <rf:iref
                     item="meyeS_2001" part="item 16"/>.
             </li><li>
                 Trim excess capacity  -- Trim excess capacity by copying the data to a temporary
                 array, then swapping with the original  (e..g,
                 <code>vector&lt;Widget>(widgets.begin(), widgets.end()).swap(widgets)</code>)  <rf:iref
                         item="meyeS_2001" part="item 17"/>.
             </li><li>
                 Use bitset instead of vector&lt;bool> -- Use std::bitset instead of
                 vector&lt;bool>.  The later is a special-cased implementation using proxies that
                 does not implement the full, vector interface  <rf:iref
                         item="meyeS_2001" part="item 18"/>.
             </li><li>
                 Modify an element of a hash --To modify an element of a hash use
                 <code>const_cast&lt;Widget&amp;>(*i).setTitle("New title")</code>.  Do <i>not</i>
                 modify the element's key  <rf:iref
                     item="meyeS_2001" part="item 22"/>.
             </li><li>
                 Convert const_iterator to iterator -- You can not cast a const_iterator to an
                 iterator since they are different types.   Convert from one to the other using
                 advance() and distance() (i.e., <code>advance(i, distance(i, ci))</code>) <rf:iref item="meyeS_2001" part="item 26"/>.
             </li><li>
                 Erase the element of a reverse_iterator -- Erase the element preceding the base
                 element.  (i.e., <code>erase((++ri).base());</code>) <rf:iref item="meyeS_2001"
                     part="item 28"/>.
             </li><li>
                 Character input/output -- For character-by-character I/O use istreambuf_iterator
                 and ostreambuf_iterator.  These iterators work with the underlying stream buffer <rf:iref item="meyeS_2001"
                     part="item 29"/>.
             </li></ul>
             
             <p>Types of containers</p>
             <ul><li>
                 Contiguous-memory vs. node-based containers -- A contiguous-memory container stores multiple
                 elements per chunk of memory.   If an element is deleted the remaining elements
                 must shift up or down to close the gap.  In STL, the contiguous-memory containers are
                 vector, string, and deque.    A node-based container stores one element per chunk
                 of memory.  Examples include lists and hashes.  <rf:iref item="meyeS_2001" part="item 1"/>.
             </li><li>
                 Snapshot vs. live collections -- A snapshot collection captures a list at a point
                 in time (e.g., the result of a database query).  A live collection represents the
                 current state (e.g., the active windows).  Properties should return live
                 collections (i.e., a light-weight iterator) <rf:iref item="cwalK_2006" page="217"/>.
             </li><li>
                 Homogeneous container -- Use one type for the return value 
                 and parameter list of public,
                 collection methods.  Do not define an Add method that takes 'object' <rf:iref
                     item="cwalK_2006" page="212"/>.
             </li><li>
                 Container of values -- Restrict containers to values or value-like objects such as 
                 smart pointers and iterators <rf:iref item="suttH_2005" part="item 79"/>. 
             </li><li>
                 Containers of pointers -- Pointers are inexpensive to copy, but hard to track.  
                 Either explicitly delete the objects before deleting the container, or use
                 smart pointers that delete themselves.   Prefer an established implementation of
                 smart pointers <rf:iref item="meyeS_2001" part="items 3, 7, 8"/>  <rf:iref
                     item="cpp-pointer" />.
             </li><li>
                 Container of references -- References can not be used as the
                 container type (due to functions
                 that take or return references to the container's contents).  
                 To use references,  define a specialization of a wrapper template that stores
                 the reference as a pointer (see <i>Encapsulating reference traits</i> <rf:iref
                     item="liscR_2003" page="37-38"/>).
             </li></ul>
        </rf:item>
        
        <rf:item id="cpp-collection-api"  title="Guidelines for collection APIs" date="Nov 2009" author="bbarber">
            <p>Collection APIs should be consistent where practical.  This section mostly follows Qt conventions.
                See <a href="http://doc.trolltech.com/4.5/qlist.html">QList</a> for an example and prototypes.
                In the gcc distribution, see <code>include/c++/bits/stl_vector.h</code>, etc.
                In the Qhull distribution, see <code>orgQhull::Coordinates</code>.
                A similar list is doc/doxygen/tables.html of the GNU libstdc++ distribution
            </p>
            
            <ul><li>
            </li><li>
                Subtypes for STL container types [list, QLinkedList, QList, QVector, vector] -- const_iterator, 
                const_pointer, const_reference, difference_type (ptrdiff_t), iterator, size_type, value_type.  
                Qt does not use size_t, reverse_iterator, or const_reverse_iterator.  It defines size_type as int in accord with the C++ standard.
            </li><li>
                Subtypes for STL iterator and const_iterator [list, QLinkedList, QList, QVector, vector, stl_iterator.h].  The subtypes are iterator_category, value_type, difference_type (ptrdiff_t), pointer, and reference.
                Qt's foreach requires const_iterator.  The iterator types do <i>not</i> define const_pointer, const_reference, and size_type.
            </li><li>
                Qt types [QLinkedList, QList, QVector]  -- ConstIterator, Iterator, ClassnameIterator, MutableClassnameIterator.
            </li><li>
                Types for sets/maps [hash_map, QHash] -- key_compare, key_type, mapped_type
            </li><li>
                Constructor -- default constructor, copy constructor, assignment operator, destructor
            </li><li>
                Conversion -- to/from/as corresponding C, STL, and Qt constructs.  Include toQList and toStdVector.
                Do not define fromStdList and fromQList if container is not reference counted (i.e., acts like a value)
            </li><li>
                Get/set -- configuration options for class
            </li><li>
                Read-only - (int)count, empty, isEmpty, (size_t)size, ==, !=.  Count() and size() may be filtered.  If so, they may be zero when !empty().
            </li><li>
                Read-only for sets/maps - capacity, key, keys, values
            </li><li>
                Element access -- [], at (const&amp; only), back, constData, data, first, front, last, mid, second, value.  If possible, first/last/etc. should return a reference to the first/last/etc. element.
            </li><li>
                Modify -- append, clear, erase, insert, move, prepend, pop_back, pop_front, push_back, push_front, removeAll, removeAt, removeFirst, removeLast, replace,
                reserve, swap, takeAt, takeFirst, takeLast.  Also define +, +=, &lt;&lt; for appending either elements or collections.  
            </li><li>
                Read-write for sets/maps -- insertMulti, reserve, resize, squeeze, take, unite
            </li><li>
                STL-style iterator - begin, constBegin, constEnd, end, key, value, =, *, [], ->, ++, --, +, -, ==, !=, &lt;,
                &lt;=, &gt;, &gt;=, implicit const_iterator(iterator), iterator COMPARE const_iterator.
                An iterator is an abstraction of a pointer.  It is not aware of its container.
            </li><li>
                Qt's Java-style iterator [qiterator.h] - countRemaining, findNext, findPrevious, hasNext, hasPrevious, next, peekNext, peekPrevious, previous, toBack, toFront, = Coordinates.  
                These Java-style iterators are easier to read than the STL-style iterator. 
            </li><li>
                Mutable Java-style iterator also has insert, remove, setValue, and value
            </li><li>
                Search -- contains(const T &amp;), count(const T &amp;), indexOf, lastIndexOf
            </li><li>
                Search for sets/maps -- constFind, lowerBound, upperBound
            </li><li>
                Stream I/O -- stream &lt;&lt;
            </li></ul>
        </rf:item>
            
        <rf:item id="cpp-command-line"  title="Guidelines for command line processing" date="Jan 2009" author="bbarber">
            <p>
            </p>
            <ul><li>
                Enforce a single consistent command-line structure -- Keep all options for a program
                or suite of programs consistent with each other.   Require a flag before all options
                other than a list of filenames.   Assign a descriptive name for each option.  
                Allow an optional '=' between option name and value.   Allow '-' for stdin and '--'
                to stop option processing.    Standardize the meta options (--help, --version,
                --usage, --man).  Use a package to simplify and
                enforce these conventions (e.g., Perl's Getopt::Long) 
                <rf:iref item="conwD_2005" page="300-304, 306-310"/>.
            </li><li>
                Allow the same file for input and output -- If a program defines output files, allow
                them to be the same as the input file.  For example, unlink the destination after
                opening the source (assumes that the destination is not a hard link to the source).
                <rf:iref item="conwD_2005" page="304-305"/>.
            </li></ul>
         </rf:item>

        <rf:item id="cpp-component"  title="Guidelines for components" date="Feb 2008" author="bbarber">
             <p>A <i>component</i> is a piece of reusable software that may be combined with other
             components to build an application.
             </p>
             <ul><li>
                 Component-oriented design -- A simple usage model is to instantiate a type with
                 simple constructors, set some properties, call a few methods, and respond to
                 events. Microsoft calls this Create-Set-Call. <rf:iref item="cwalK_2006" page="237"/>.
             </li><li>
                 Aggregate component -- An aggregate component combines several factored types into
                 a simplified API for common scenarios (e.g., an Email component).  An aggregate
                 component emphasizes properties, events, and physical objects.  They avoid
                 configuration, modes, multiple objects <rf:iref
                     item="cwalK_2006" page="235-243"/>.
             </li><li>
                 Factored type -- A factored type is part of a component.  They do not have modes. 
                 Their lifespan is clearly defined.  Consider placing factored types in a separate
                 assembly <rf:iref item="cwalK_2006" page="240, 243"/>.
             </li><li>
             </li><li>
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-constant"  title="Guidelines for constants" date="Feb 2008" author="bbarber">
             <ul><li>
                 magic constants -- Avoid bare numbers such as 1024.  They carry no semantic
                 content.  Define a symbolic constant instead 
                 <rf:iref item="dewhSC_2003" part="gotcha 2"/>.
             </li><li>
                 enum -- An enumeration is a special case of a value type with a small set of
                 values. <rf:iref item="cwalK_2006" page="91"/>
                 <ul><li>
                     Use plural nouns for flags <rf:iref item="cwalK_2006" page="96"/>
                 </li><li>
                     Flag operations -- IsExactlyOneBitSet, CountOnBits, AreAllBitsOn, AreAnyBitsOn,
                     TurnBitsOnOff <rf:iref item="cwalK_2006" page="97"/>
                 </li><li>
                     All combinations valid -- Avoid flag enums where certain combinations are not
                     valid.
                 </li><li>
                     Enum class -- An enum class packages enum values and names.  For an example,
                     see Uwyn's <a
                         href="http://www.uwyn.com/resources/uwyn_cpp_coding_standard/x722.html">Learn
                     about enum classes</a>.
                 </li><li>
                 </li><li>
                 </li></ul>
               </li><li>
                   Do not use #define -- Do not use the preprocessor for constants or macros.  Use
                   enums, static const members, and templates instead.  In any case, do not use //
                   comments within a macro definition (the line continuation character may be
                   skipped).
               </li><li>
                   Enum or static const member -- Define constants as an enum or static const member (e.g., <code>static const double
                   AspectRatio = 1.653</code>.   For non-integral types, define the static
                   member in an implementation file (e.g., <code>const QString author("Scott
                   Meyers")</code>).  Char* strings may be defined in header files (e.g.,
                   <code>const char* const author = "Scott Meyers"</code>)
                   <rf:iref item="meyeS_2005" part="item 2"/>.  KDE and Qt discourage static const objects, especially in library code.  The order of initialization is undefined.  
                   Built-in types are OK (e.g., static const char SomeString[] = "Example";) [<rf:iref item="qt-style" part="KDE"/>]  
               </li><li>
                   All-caps prefix for constants -- Consider using an all-caps prefix for constants (e.g.,
                   MAXage or ERRopen).
             </li><li>
             </li></ul>
         </rf:item>
        <rf:item id="cpp-configuration"  title="Guidelines for configuration" date="Nov 2009" author="bbarber">
            <p>A system is configured by global information such as config files, registry values, and environment variables.  
                Parameters configure systems and programs at invocation.  Misconfiguration can prevent system startup or cause mysterious problems.   
            </p>
            <ul><li>
                Convention over configuration -- Use naming conventions to configure a system.  It works well if everyone follows the same convention, 
                but can produce a mess if different programs follow different conventions.  
                See Chen's 2006 <a href="http://softwareengineering.vazexqi.com/files/pattern.html">Convention over configuration</a>
            </li><li>
                Defaults -- Default values implicitly configure code.  They tend to be hidden in the code source or its headers.
            </li><li>
                Prefer enum over 'static const int' -- Compilers can replace enum values at compile time [<rf:iref item="qt-style" part="qt"/>]
            </li></ul>
            
        </rf:item>
         <rf:item id="cpp-constructor"  title="Guidelines for constructors" date="Feb 2008" author="bbarber">
             <p>A <i>constructor</i> allocates an object and initializes its members.  It
                 establishes the class invariant.
              </p>
             <p>See also <rf:iref item="cpp-initialize"/> and <rf:iref item="cpp-factory"/></p>
             <ul><li>
                 Prefer simple constructors -- An easy-to-use API prefers default constructors or
                 simple constructors with 
                 primitive and enum parameters <rf:iref item="cwalK_2006" page="126"/>.
             </li><li>
                 No static constructors -- Do not use constructors for globally defined data in library code (e.g., static const QString s_myQstring).  
                 It is undefined when the constructor is called.  Static contructors may be called on first usage, on libray load, prior to invoking main(), or not at all.
                 Use native types instead (e.g., pointers, array initializers, struct initializers).  In Qt, use Q_GLOBAL_STATIC (<rf:iref item="qt-style" part="qt"/>).
             </li><li>
                 Minimize the constructor -- Constructors should not perform significant work.  Delay
                 processing until work is required <rf:iref item="cwalK_2006" page="127"/>.
             </li><li>
                 Initialize every field, in order -- Objects must be initialized before
                 they are used.  A constructor should initialize every field (in declaration
                 order), even
                 those automatically initialized.    Use the constructor's initialization list
                 instead of assigning fields in the constructor's body.  Const members and
                 references must be initialized.   Use a private init() function if there
                 are many constructors <rf:iref item="meyeS_2005" part="item 4"/>.
             </li><li>
                 Properties vs. constructor -- Calling a constructor with multiple arguments should
                 be the same as setting multiple properties.  Use multiple arguments as a short cut
                 <rf:iref item="cwalK_2006" page="126"/>.
             </li><li>
                 Copy constructor -- A copy constructor for type T has the signature <code>T(const
                 T&amp;)</code>.  It creates a type T from a type T.
                 Copy assignment sets an  existing object to the value of another object.
                 See <rf:iref item="cpp-operator"/> and
                  <rf:iref item="dewhSC_2003" part="gotcha 47, 49"/>.
                 <ul><li>
                     Copy constructors are used for call by
                     value and initialized declarations (e.g., <code>Widget w3 = w2;</code>) 
                     <rf:iref item="meyeS_2005" page="6"/>.
                 </li><li>
                     If undefined by a class, the
                     default copy constructor and copy assignment perform a bitwise copy.      
                 </li><li>
                     Copy members and base class -- Be sure to copy every member, including the base class, otherwise the destination may
                     be incomplete or inconsistent.  Use the initialization list to copy 
                     the base class  (e.g., <code>Derived(const Derived&amp; other) : Base(other)
                         ...</code>) <rf:iref item="meyeS_2005" part="item 12"/>.
                 </li><li>
                     To share code with copy assignment -- If the copy constructor and copy assignment
                     use the same code, invoke a member function.  Do not try to invoke one from the
                     other <rf:iref item="meyeS_2005" page="60"/>.
                 </li><li>
                     Disable copy constructor -- To disable the copy constructor, declare it private
                     (e.g., <code>private: MyType(const MyType&amp;)  //disabled</code>) <rf:iref item="meyeS_2005"
                         part="item 6"/>.
                 </li><li>
                 </li><li>
                 </li></ul>
                 
             </li><li>
                 Copy assignment (operator=)
                 <ul><li>
                     Default assignment -- By default, C++ defines copy assignment as bitwise copy
                     of  each data member.   There is no
                     default if the class
                     includes a reference member, a const member, or a private base class constructor <rf:iref
                         item="meyeS_2005" page="36-37"/>.
                </li><li>
                     The assignment operator should return a reference to *this, allowing
                     chained assignments <rf:iref item="meyeS_2005" part="item 10"/>.  
                 </li><li>
                     Copy members and base class -- Be sure to copy every member, including the base class, otherwise the destination may
                     be incomplete or inconsistent.   Invoke copy assignment for the base class
                     (e.g., <code>Base::operator=(other);</code>) <rf:iref item="meyeS_2005" part="item 12"/>.
                 </li><li>
                     Assignment to self -- When defining copy assignment, handle assignment
                     to self <rf:iref item="meyeS_2005" part="item 11"/>.  
                 </li><li>
                     Copy and swap -- Make a local copy, then swap with the member.  This is
                     exception-safe.  It automatically handles assignment to self <rf:iref
                         item="meyeS_2005" page="56"/>.  See <rf:iref item="cpp-function"/>.
                 </li><li>
                     Pass-by-value and swap -- Pass-by-value creates a local copy.  Swap is
                     exception safe and handles assignment to self.  Document the pass-by-value since it  is
                     tricky <rf:iref item="meyeS_2005"
                         page="56"/>.
                 </li><li>
                     To disallow operator= -- To disallow operator=, declare it private with unnamed
                     parameters and no definition.  Alternatively, inherit from an "Uncopyable" class
                     with a private copy constructor and copy assignment <rf:iref item="meyeS_2005"
                         part="item 6"/>.
                 </li><li>
                 </li></ul>         
             </li><li>
                 Virtual constructor -- A virtual constructor creates different objects depending on its 
                 input.   It returns a base class pointer to the object.   A virtual copy constructor (typically, via a virtual function called clone()) constructs different
                 objects depending on its source. <rf:iref item="meyeS_1996" page="123-127"/>.
             </li><li>
                 No virtual member calls -- Avoid calling virtual members from a constructor.  In C# it
                 calls the most derived type even if its constructor has not run.  In C++, the
                 invoked member changes as the derived classes become initialized <rf:iref
                     item="cwalK_2006" page="129-130"/>
             </li><li>
                 Throw exceptions -- Throw exceptions from constructors, but be careful of resource
                 leaks and inconsistent objects at finalization time <rf:iref item="cwalK_2006"
                     page="127"/>.  Do not throw exceptions from static constructors <rf:iref
                         item="cwalK_2006" page="131"/>
             </li><li>
                     To disallow object creation -- Make the constructor private and do not define its
                     definition <rf:iref item="meyeS_1996" page="130"/>.
             </li><li>
                 Do not declare 'ClassName f()'  -- An empty parameter list is a function
                 declaration, not a local variable with a default constructor. 
             </li><li>
                 MyType a() vs. MyType a -- Do not use () for the default constructor.  It declares a function
                 'a' and leads to unusual compiler errors
                  <rf:iref item="dewhSC_2003" part="gotcha 19"/>.
                 </li><li>
                 </li></ul>
         </rf:item>
        <rf:item id="cpp-control"  title="Guidelines for control statements" date="Jan 2009" author="bbarber">
            <p>                  Make decisions stand out.  Communicate your decisions and their consequences.  
                Minimize the number of conditionals, don't phrase decisions negatively, avoid flag
                variables and count variables
                <rf:iref item="conwD_2005" page="93"/>.
            </p>
            <ul><li>
                Do not use postfix unless, until, etc. -- A postfix control statement hides the
                control expression at the end of the controlled statements.  Better to rewrite as a
                familiar control statement.
                <rf:iref item="conwD_2005" page="97"/>.
            </li><li>
                Avoid C-style for loops -- The iterative behavior of a three-part for statement is
                emergent rather than explicit.   Rephrase as a while loop or as iteration over a set
            </li><li>
                Avoid indexing within a loop -- Iterate over the values in a foreach loop, or
                iterate over the keys and values together.  To
                delete elements from a hash, create a list of keys to be deleted; then delete the
                hash slice.   If an index is necessary, retain the value or create an alias.
                <rf:iref item="conwD_2005" page="101-105"/>.
            </li><li>
                Use an iterator variable -- Assign a variable to each value in an iteration.  The
                variable should be locally defined
                <rf:iref item="conwD_2005" page="105-110"/>.
            </li><li>
                Map -- Generate new lists from old by mapping an expression over the list.  For
                example in Perl, <code>my @sqrt_results = map { sqrt $_ } @results</code>.   If
                complex, define a subroutine for the expression.  Use
                <code>for</code> to transform a list in place
                <rf:iref item="conwD_2005" page="110-111, 112-114"/>.
            </li><li>
                Grep  -- Select elements from a list  with an expression.  For example in Perl,
                <code>my @selection = grep { if_selected($_) } @list;</code> 
                <rf:iref item="conwD_2005" page="111-112"/>.
            </li><li>
                Avoid cascading ifs -- A sequence of if..then..else statements can be inefficient
                and difficult to decipher.   Prefer a table lookup or a tabular ternary.  
                <rf:iref item="conwD_2005" page="117-123"/>.
                Cascading
                ifs work well if each alternative selects a function call. 
            </li></ul>
         </rf:item>
         <rf:item id="cpp-data"  title="Guidelines for data members and instance
             variables" date="Feb 2008" author="bbarber">
             <p>See also <rf:iref item="cpp-property"/></p>
             <ul><li>
                 Global data -- Avoid globally defined objects and variables.   Limit the use of
                 static variables that are global to a class.  A global variable is an implicit
                 argument to every method that uses it.  Globals reduce reuse since all users must be
                 packaged together
                 <rf:iref item="dewhSC_2003" part="gotcha 3"/>.
                 
                 </li><li>
                 "Declare data members private" -- Everything in the public interface should be a
                 function.  It keeps the interface consistent and flexible.  "It makes it easy to
                 notify other objects when data members are read or written, to verify class
                 invariants and function pre- and post-conditions, to perform synchronization in
                 threaded environments, etc."  If you eliminate a public or protected data member an
                 unknowable amount of code may be broken <rf:iref item="meyeS_2005" part="item
                 22"/>,
                 <rf:iref item="conwD_2005" page="359"/>.
             </li><li>
                 Union type -- "An object of union type has enough memory to store the largest
                 member, and all data members share that memory. ... It is your responsibility to
                 keep track of which data member is "active."   Use an anonymous union for simplified
                 access to union members <rf:iref item="liscR_2003" page="137-138"/>.
             </li><li>
                 Const vs. mutable -- Do not assign arrays, collections, and other mutable types
                 to const or readonly fields.  Otherwise the elements of the field
                 can be modified <rf:iref item="cwalK_2006" page="141"/>
             </li><li>
                 Unsigned bit field -- A <i>bit field</i> is "a sequence of bits packed into an object.  
                 Use 'signed' or 'unsigned' on 'int' bit fields, otherwise the value is undefined <rf:iref item="liscR_2003"
                     page="140-141"/>.
             </li><li>
                 Public static readonly -- In C#, Use static readonly fields for predefined objects
                 <rf:iref item="cwalK_2006" page="140"/>.    
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-debugging" title="Guidelines for debugging" date="Feb 2008" author="bbarber">
             <ul><li>
             </li><li>
                 assert -- Use assert() liberally to document internal assumptions and invariants. 
                 For boolean asserts, add <code>&amp;&amp; "informative message"</code>
                 to describe the failure <rf:iref item="suttH_2005" part="item 68"/>.
             </li><li>
                 Custom assert -- Define your own assert for greater control over invariant testing.
                 include a level parameter to reduce the amount of assert testing in production
                 code <rf:iref item="suttH_2005" part="item 68"/>.
             </li><li>
                 autoexp.dat -- In DevStudio, use autoexp.dat to define rules for displaying variables in 
                 native code.  This file is
                 in <pre> Program Files\Microsoft Visual Studio 8\Common7\Packages\Debugger</pre>
                 For more
                 control over displaying data see "EEAddIn" in the DevStudio documentation.  
             </li><li>
                 endl -- When writing diagnostic output, end lines with  '&lt;&lt; endl' instead of
                 '\n',   The former writes a new line and flushes the buffer.  Alternatively use 
                 '&lt;&lt; flush'.  Without 'endl' or 'flush' the last
                 lines of output may not appear after a program crash.  <rf:iref item="lippSB_2005"
                     page="292"/>.  If using Qt, distinguish between STL's endl and Qt's endl.
             </li><li>
                 if(DEBUG) -- Use conditional expressions instead of #if for debugging code.  The
                 compiler checks both versions of the code, and eliminates the unexecuted branch 
                  <rf:iref item="dewhSC_2003" part="gotcha 27"/>.
             </li><li>
                 ToString -- C# displays the ToString() value of an object if it is available. 
                 It should be unique, readable, developer-appropriate.  Ideally, parsing the
                 ToString() should recreate the object <rf:iref item="cwalK_2006" page="227-228"/>.
             </li><li>
                 LogEntry() -- Define a log entry class whose constructor starts the log and whose
                 destructor stops the log entry <rf:iref item="meyeS_1996" page="161"/>.
             </li><li>
             </li></ul>
         </rf:item>
        <rf:item id="cpp-document" title="Guidelines for documentation" date="Jan 2009" author="bbarber">
            <p></p>
            <ul><li>
                User vs. technical documentation -- Do not include implementation details in user
                documentation.  Tell the user what the code does, not how it does it
                <rf:iref item="conwD_2005" page="132-133"/>.
            </li><li>
                Place user documentation in the source files -- If user documentation is in the
                source files, it is easier to maintain and keep up-to-date.
                <rf:iref item="conwD_2005" page="138-141"/>.
            </li><li>
                Define templates for user documentation -- Define and use templates for
                documenting each type of
                module.   It helps the reader understand a module.  The writer does not worry about
                organization.
                <rf:iref item="conwD_2005" page="133-138"/>.
            </li></ul>
         </rf:item>
         <rf:item id="cpp-efficiency" title="Guidelines for efficiency" date="Feb 2008" author="bbarber">
             <ul><li>
                 Flexibility is expensive -- "In the last ten years we have encountered quite a few
                 C++ projects that fell far short of their required performance.  At the heart of
                 those performance failures was a design and an implementation geared for extreme
                 flexibility and reusability.  The obsession with reusable code has produced
                 software that, due to the lack of efficiency, was not even usable, not to mention
                 reusable. ... The problem is that performance and flexibility are often enemies."
                 <rf:iref item="bulkD_2000" page="223"/>.
             </li><li>
                 Limit use of inline functions -- An inline function is either declared 'inline' or defined within a
                 class.  It may define static objects.  
                 An inline function requires recompilation on any change.  "Limit most inlining
                 to small, frequently called functions" <rf:iref item="meyeS_2005" part="item 30"/>.
                 Do not inline constructors and destructors.  It breaks binary compatibility [<rf:iref item="qt-style" part="library"/>].
             </li><li>
                 Inlining is faster -- "Inlining is probably the most significant mechanical
                 performance enhancement technique available in C++."  For example, inlining the
                 obvious candidates of a 10,000 line subsystem improved performance by 40%.  If
                 inline candidates are assigned to a ".inl" file, the preprocessor can
                 selectively include the file in the corresponding .h or .cpp file <rf:iref
                     item="bulkD_2000" page="117, 142"/>. 
             </li><li>
                 Constructors are expensive -- Creating and destroying objects is expensive.  For
                 example removing three unnecessary std::string creates from a logging class reduced
                 response time from 2,500 ms to 185 ms.  When practical, embed an object instead of
                 an object pointer.  This saves a heap allocation and deallocation.  Use a free list
                 to recycle objects.  <rf:iref item="bulkD_2000" page="21, 40, 88"/>. 
             </li><li>
                 Temporaries are expensive --   Temporary objects must be created and destroyed.  For
                 example, a Complex expression <code>i*b + 1.0</code> is faster if 1.0 is replaced
                 with a predefined <code>Complex one(1.0)</code>.  Defining <code>std::string
                 s3=s1+s2</code> avoids the temporary created for <code>s3=s1+s2</code>. 
                 Mutators avoid temporaries (e.g., <code>s3=s1; s3+=s2</code>)
                 <rf:iref item="bulkD_2000" page="71, 75, 76"/>.
             </li><li>
                 Object vectors are expensive -- A vector of BigInt objects is 18 times more
                 expensive than a vector of integers.  If vectors are frequently manipulated
                 consider using a vector of pointers instead.
                 <rf:iref item="bulkD_2000" page="159"/>.
             </li><li>
                 Vector traversal is fast -- Traversing a vector from beginning to end is fast.  
                 For example, summing the elements of a vector with std::accumulate is 23 times
                 faster than summing a list.  List traversal ignores the memory cache.
                 <rf:iref item="bulkD_2000" page="166"/>.
             </li><li>
                 Inheritance is expensive -- Inheritance adds a level of indirection to function
                 calls.   For example, a standalone object for SimpleMutex cost the same as a
                 hand-code implementation.  All calls were inlined.  A simple inheritance-based lock
                 object with a virtual destructor degraded performance about 60%              
                 <rf:iref item="bulkD_2000" page="36"/>.
             </li><li>
                 Know the memory hierarchy -- Registers have much more bandwidth than the level-1
                 cache.   The
                 level-1 cache is faster than the level-2 cache.  The level-2 cache is much faster
                 than main memory.   Accessing data in the same cache line is faster than
                 accessing data in many cache lines.  Disk access is incredibly slow, except for bulk data from
                 contiguous sectors.  Non-resident virtual memory is disk.
                 <rf:iref item="bulkD_2000" page="267"/>.
             </li><li>
                 Straight-line code is fast -- "The fastest code is straight line code: no
                 conditional tests, no loops, no calls, no returns.  In general, the more the
                 critical path of a program looks like a straight line, the faster it will execute."
                 <rf:iref item="bulkD_2000" page="280"/>
             </li><li>
                 Argument checking is slow -- Sanity-checking of arguments involves lots of
                 branches.  Keep argument checking out of the critical path.  Avoid redundant
                 checks.
                 <rf:iref item="bulkD_2000" page="280"/>
             </li><li>
                 Avoid context switches -- A context switch is expensive.  The processor must save
                 its state and execute the scheduler.  The cache and TLB are likely to be stale when
                 the process returns.  A context switch can cost thousands of cycles. 
                 Multithreaded processor architectures can make context switches for free, but they do not
                 avoid the problem of stale cache lines and TLB misses.
                 <rf:iref item="bulkD_2000" page="287, 290"/>
             </li><li>
                 return-value optimization (RVO) -- If a returned value is constructed, a compiler may
                 construct the result into the destination object <rf:iref item="meyeS_1996"
                     part="item 20"/>.  The class must define a copy constructor <rf:iref
                     item="bulkD_2000" page="64"/>.  If a function can create more than one object (e.g., a default initializer for the NULL case), return-value optimization 
                 is usually disabled.
             </li><li>
                 RTTI is expensive -- Run-time type information and dynamic casts are expensive
                 <rf:iref item="meyeS_1996" page="120-122"/>.  In Qt, use QMetaObject instead.
             </li><li>
                Precompute data -- Precomputed lookup tables moves computation from the
                performance-critical path to initialization.  For example, replace calls to
                tolower, islower, isspace, and isdigit with tables.                 
                 <rf:iref item="bulkD_2000" page="205"/>.
             </li><li>
                 Split up shared resources -- Reduce synchronization costs by defining multiple
                 resource pools  with independent locks
                 <rf:iref item="bulkD_2000" page="255"/>.
             </li><li>
                 Avoid false sharing of the data cache -- In multi-processor systems, the data cache
                 is an important resource.  When data is modified by the same process, keep it 
                 together.  When data is modified by multiple processes, separate the data.  For example, if
                 two locks are only eight bytes part, each access may invalidate the whole cache
                 line
                 <rf:iref item="bulkD_2000" page="258-259"/>.
             </li><li>
                 Wakeup a single thread -- When a lock is released, prefer waking up a single
                 thread.  Otherwise all threads will wake up, even though only one thread will
                 succeed
                 <rf:iref item="bulkD_2000" page="261"/>.
             </li></ul>
         </rf:item>
         <rf:item id="cpp-event"  title="Guidelines for events" date="Feb 2008" author="bbarber">
             <p>Events are callbacks into user code.  When an event is raised,  the
                 user-supplied event handler is called.   Instead of calling the event handler
                 immediately, the event may be posted to an event queue.  In Qt, an event handler is called a "slot" 
                 and an event is called a "signal".
                 </p>
             <ul><li>
                 Pre- and post-events -- A pre-event occurs before a state change.  A
                 post-event occurs after the state change.  Use present tense for pre-events
                 (e.g., "Form.Closing") and past tense for post-events (e.g., "Form.Closed")
                 <rf:iref item="cwalK_2006" page="133"/>,
             </li><li>
                 Canceling pre-events -- A pre-event should allow the end user to cancel the event.
                 <rf:iref item="cwalK_2006" page="137"/>
             </li><li>
                 Sender and EventArgs -- Event handlers should receive the sending object and a
                 subclass of EventArgs.  The former provides scope to the sender, while the later
                 allows new properties to be added later <rf:iref item="cwalK_2006" page="135, 138"/>
             </li><li>
                 On... -- Raise an event with a protected virtual method (e.g., "OnAlarmRaised")
                 <rf:iref item="cwalK_2006" page="137"/>.
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-exception" title="Guidelines for exceptions" date="Mar 2008" author="bbarber">
             <p>Use exceptions instead of return codes.  Exceptions provide a consistent API for
                 reporting problems.  They integrate well with object-oriented languages.  They
                 support localization.  They can not be silently ignored.  Exceptions can be
                 instrumented <rf:iref item="cwalK_2006"
                 page="179-183"/>, 
                 <rf:iref item="conwD_2005" page="274-278"/>.
             </p>
             
             <ul><li>
                 Throw exceptions for all failures -- Do not use failure returns.  Throw exceptions
                 for recoverable and unrecoverable errors.  Use an error handler to recover from an
                 error if practical.
                 <rf:iref item="conwD_2005" page="281-282"/>.
             </li><li>
                 Throw standard exceptions -- Throw a standard exception or an exception derived
                 from a standard exception.  Then the exception type defines the exception handler
                 <rf:iref item="cwalK_2006" page="189"/>.   In C++, throw an exception derived from
                 <code>&lt;stdexcept></code>.   It must have a copy constructor.  
                 Do not throw an expression <rf:iref item="liscR_2003"
                 page="81"/>.
                 Do not throw a string 
                 <rf:iref item="dewhSC_2003" part="gotcha 64"/>.
                 <ul><li>
                     InvalidOperationException -- an object is in the inappropriate state for the
                     operation <rf:iref item="cwalK_2006" page="198"/>.  Throw exceptions for incorrect usage of an API <rf:iref
                         item="cwalK_2006" page="23"/>
                 </li><li>
                     ArgumentException -- Throw an ArgumentException if an argument does not validate
                     <rf:iref item="cwalK_2006" page="153"/>
                 </li><li>
                     In Perl, throw an exception object constructed by Exception::Class.
                     <rf:iref item="conwD_2005" page="287-298"/>.
                 </li></ul>
             </li><li>
                 Write from the user's perspective --  Write the error message from the user's
                 perspective.    Write descriptive error messages.   Report the caller's location
                 instead of the exception's location.  Tell what's wrong, why it's wrong, where in
                 the data, and whence in the code.   Include the values that were not equal, the
                 filename that was not found, the expected string, and the actual string.  Give line
                 numbers and character offsets.  If practical, briefly indicate how to fix or workaround the problem. 
                For formatting, use STL's ostreamstring (&lt;sstream>) or
                     Qt's QString::arg().  Consider using an exception builder as described below.  
                     In Perl, use 'croak' instead of 'die'.
                 <rf:iref item="conwD_2005" page="283--286"/>.
             </li><li>
                 Prefixed error code -- For published software, include an error code in all error
                 messages.  Assign a unique
                 numeric identifier and a prefix that indicates the source.    Error codes provide
                 tags for documentation and discussion.  Error
                 messages are easily reworded.
             </li><li>
                 Document errors -- Document all errors.  Rewrite the error message using full
                 sentences.  List the likely causes.  Give a workaround and how to fix the problem.
                 <rf:iref item="conwD_2005" page="286--287"/>.
             </li><li>
                 Unhandled exception -- Write clear error messages.  An unhandled exception reflects a bug in the
                 application that can only be fixed by a developer <rf:iref item="cwalK_2006"
                     page="190"/>.   If an unhandled exception occurs, users must deal with it. 
                 Often, an understanding of the exception will lead to a workaround or
                 resolution.
             </li><li>
             </li><li>
                 Exception builder -- An exception builder is a method that constructs and throws
                 an exception from a list of arguments.   It reduces the cost of exceptions and
                 allows inlining <rf:iref item="cwalK_2006" page="187"/>.   
             </li><li>
                 Exception constructors -- Provide constructors for default construction, a
                 message string, an inner exception, and serialization <rf:iref item="cwalK_2006"
                     page="202"/>.
             </li><li>
                 Exception objects are copied -- Throwing an exception calls the exception object's
                 copy constructor of the object's static type <rf:iref item="meyeS_1996" page="62-63"/>.
             </li><li>
                 Avoid exception specifications -- They do not catch serious errors.  They do not
                 work well with templates.  They are easy to use incorrectly <rf:iref
                     item="meyeS_1996" part="item 14"/>.
             </li></ul>
         </rf:item>
         <rf:item id="cpp-exception-handling" title="Guidelines for exception handling" date="Feb 2008" author="bbarber">
            <p> "Even a program with no internal bugs must still interact with the environment in which
             it executes: at the very least, the operating system, filesystem, terminal I/O,
             hardware devices, and network connections.  That environment must be treated as
             hostile, because any or all of its components may fail in some unpredictable manner. 
             Robust software must allow for that possibility, detect when it occurs, and either
             overcome the problem, if possible, or report it and fail gracefully.  All of which
             comes under the mantle of error handling. ... The first [fundamental principle] is that
             all detectable run-time errors must be
             detected, classified, and reported.  The second is that it should not be possible to
             ignore any detected error without a conscious and visible effort.
             <rf:iref item="conwD_2005" page="273"/>.
            </p>
             <p>
                 Error handling is seldom tested  thoroughly.   Use exceptions to
                 reduce the amount of error handling code.   With exceptions, errors due to error
                 handling are isolated to the error handlers.
             </p>
             <ul><li>
                 Only catch exceptions that you can handle -- Rethrowing an exception just
                 confuses the issue.  Use a 'finally' block if you need to release resources
                 <rf:iref item="cwalK_2006" page="192-195"/>.
             </li><li>
                 Catch exceptions by reference -- Catch-by-value leads to double-copying of the
                 exception object.  Catch-by-pointer leads to ownership problems <rf:iref
                     item="meyeS_1996" part="item 13"/>.
             </li><li>
                 Prevent resource leaks with destructors -- Throwing an exception calls the
                 destructor for fully constructed objects <rf:iref item="meyeS_1996" page="45,
                     52"/>.  Do not throw exceptions within a destructor <rf:iref item="meyeS_1996"
                         page="59"/>.
             </li><li>
                 Try-parse --  Try-parse returns false if an operation (e.g., parse) fails.  Use
                 it for specific,  expected failures.  Name the method "Try..." <rf:iref
                     item="cwalK_2006" page="204-205"/>.
              </li><li>
                 No exceptions between modules -- Separately deployed modules may use different
                 implementations of exception handling.   Catch exceptions at module boundaries:
                 around main, callbacks, threads, module interfaces, and destructors.  Translate
                 exceptions into return codes  <rf:iref item="suttH_2005" part="item 62"/>.  For
                  example, Qt does not throw exceptions.   Unfortunately, this policy makes it 
                  easy to ignore errors.  An alternative approach is testing for module
                  compatibility at runtime.
              </li><li>
                  assert.c -- The internal code for exceptions must be particularly careful.  See 
                  Microsoft's assert.c for an example (&lt;DevStudio root>\VC\crt\src\assert.c).
              </li></ul>
         </rf:item>
         <rf:item id="cpp-exception-safety" title="Guidelines for exception safety" date="Feb 2008"
             author="bbarber">
             <p>A C++ program must be designed to recover from exceptions. 
             Even modules that use return codes may throw exceptions for memory
                 errors, divide by zero, and other runtime exceptions.</p>
             <ul><li> 
             </li><li>
                 Exception safe code -- "Exception-safe functions ... Leak no resources. ... Don't
                 allow data structures to become corrupted."   All functions must be exception-safe,
                 otherwise the system is not exception-safe <rf:iref item="meyeS_2005" part="item 29"/>. 
                 <ul><li>
                     Basic guarantee -- After an exception, objects continue to satisfy their
                     invariants, but the exact state may be unpredictable.   All functions should
                     satisfy the basic guarantee.
                 </li><li>
                     Strong guarantee -- "if an exception is thrown, the state of the program is
                     unchanged.  Calls to such functions are <i>atomic</i>"
                 </li><li>
                     No-throw guarantee -- The strongest guarantee is to never throw an exception,
                     greatly simplifying exception-safe code.  All operations on built-in types are
                     no-throw.  By convention, destructors and swap are no throw.
                 </li><li>
                     Exceptions are synchronous -- Exceptions only occur at the boundary of a
                     function call.  Function calls may occur at operators and implicit conversions
                     <rf:iref item="dewhSC_2005" part="item 38"/>.
                    
                 </li><li>
                     Delay changing status -- "[Do not] change the status of an object to indicate
                     that something has happened until something actually has."   
                 </li><li>
                     Two-phase modification -- When modifying an object, "perform all of the work
                     that might  emit an exception safely off to the side and only then, when you
                     know that the real work has succeeded, you commit and modify the program state
                     using only operations that provide the no-fail guarantee." <rf:iref
                         item="suttH_2005" page="141"/>
                 </li><li>
                     Copy and swap -- Use copy and swap to satisfy the strong guarantee.  Make a
                     local copy using the copy constructor, then swap the local copy for the member. 
                     The old contents of the member is deleted on exit.  It automatically handles
                     self-assignment  <rf:iref item="meyeS_2005" page="56, 131"/>.
                 </li><li>
                     Copy before delete -- Make a local copy of a member before deleting it.  If an
                     exception occurs, the local copy is automatically deleted <rf:iref
                         item="meyeS_2005" page="55"/>.
                 </li></ul>
             </li><li>
                 Constructors do not destruct -- Destructors are only called on fully
                 constructed objects (<rf:iref item="meyeS_1996" part="item 10"/>).   Catch and
                 handle exceptions inside constructors.   Consider auto_ptrs for dynamically allocated
                 data.    If an exception occurs, destructors are called for objects created via the
                 initialization list..  
             </li><li>
                 Destructors do not throw exceptions -- If a destructor throws an exception, the
                 program may terminate or exhibit undefined behavior.    <rf:iref item="meyeS_2005"
                     part="item 8"/> lists the alternatives for handling exceptions in constructors:
                 <ul><li>
                     Call ahead of time -- Have the caller execute code that may  throw an
                     exception beforehand.    As a backup, the same code is invoked by the destructor, but without
                     throwing exceptions.
                 </li><li>
                     Fail fast -- Terminate the application after logging information about why the program
                     failed.  
                 </li><li>
                     Swallow the error -- Doing nothing may lead to undefined behavior later.
                 </li><li>
                     Function try block -- For constructors, use a function try block to catch
                     exceptions during member initialization <rf:iref item="liscR_2003" page="147"/>.
                 </li><li>
                 </li><li>
                 </li></ul>
             </li><li>
                 ScopeGuard -- Alexandrescu and Petru Marginean created ScopeGuard to simplify
                 exception safe code.  See <a href="http://www.ddj.com/cpp/184403758"
                     >Generic: Change the Way You Write Exception-Safe Code — Forever</a>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-extend"  title="Guidelines for extensibility" date="Feb 2008" author="bbarber">
             <p>See also <rf:iref item="cpp-design"/>,  <rf:iref item="cpp-inheritance"/>  and <rf:iref item="cpp-inheritance-virtual"/>.</p>
             <ul><li>
                 Model "has-a" or "is-implemented-in-terms-of" through composition -- Compose a type
                 out of other types.  The types may come from the application domain ("has-a") or
                 the implementation domain ("is-implemented-...") <rf:iref item="meyeS_2005" 
                 part="item 38"/>.     Use private inheritance when the derived class needs
                 access to protected member, needs to redefine a virtual function, or for memory
                 efficiency <rf:iref item="meyeS_2005" part="item 39"/>.
             </li><li>
                 Limit use of abstract types and interfaces -- Abstractions are by definition
                 complex.  Always provide a concrete implementation of an abstraction, and a test
                 that the abstraction is implemented correctly <rf:iref item="cwalK_2006"
                     page="172"/>.
             </li><li>
                 Optional feature pattern -- Use CanFeature and Feature methods instead of defining
                 factored interfaces.  If a derived class does not implement the Feature method, it
                 should throw a NotSupportedException.  Do not use optional features if it only
                 applies to one derived class <rf:iref item="cwalK_2006" page="264-266"/>.
              </li><li>
                  Strategy pattern via function pointers -- Use a function pointer to provided
                  object-specific enhancements.  For example, an object's constructor may include an
                  function pointer that computes the object's "health".  The function may be changed
                  at runtime.  For greater flexibility, use tr1::function or a virtual member
                  function of a strategy hierarchy <rf:iref item="meyeS_2005" part="item 35"/>.
              </li><li>
                  Protected members -- Use protected members for advanced customization.   It
                  separates the complexity from the public API.  Do not use
                  protected members for security <rf:iref item="cwalK_2006" page="165"/>.
              </li><li>
                  
                  
              </li><li>
                  
             </li></ul>
         </rf:item>
         <rf:item id="cpp-factory"  title="Guidelines for factories" date="Feb 2008" author="bbarber">
             <p>A factory method creates a new instance of an object.</p>
             <p>See also <rf:iref item="cpp-constructor"/></p>
             <ul><li>
                 Constructors vs. factories -- Prefer constructors.  They are more usable,
                 consistent, and convenient <rf:iref item="cwalK_2006" page="261"/>.
             </li><li>
                 Named method -- Use a factory method to document a specialized constructor (e.g.,
                 <code>Repeat(char, count)</code> <rf:iref item="cwalK_2006" page="262"/>.
             </li><li>
                 Conversion -- Use a factory method for conversions, e.g., from string to object <rf:iref
                     item="cwalK_2006" page="262-263"/>.
             </li><li>
                 Naming -- Prefix factory methods with "Create" (e.g. CreateMyType).  For factory
                 types, use a "Factory" suffix (e.g., MyTypeFactory) <rf:iref item="cwalK_2006"
                     page="263"/>.
             </li><li>
             </li></ul>
         </rf:item>
         
         <rf:item id="cpp-function"  title="Guidelines for functions and methods" date="Feb 2008" author="bbarber">
             <p>
                 "A function is the basic unit of work, no matter whether you are programming C++ in
                 a structured style, an OO style, or a generic style.  A function makes assumptions
                 about its ... preconditions ... and performs one or more actions (documented as its
                 results or postconditions ...)." <rf:iref item="suttH_2005" page="134"/>
             </p>
             <ul><li>
                 Non-member function  
                 <ul><li>
                             "Prefer non-member,  non-friend functions to member functions" -- A non-member,
                         non-friend function can not modify private data, thus keeping the data encapsulated. 
                         It extends a class without increasing its size.  It improves packaging flexibility
                         <rf:iref item="meyeS_2005" part="item 23"/>.
                     </li><li>
                        Use non-member functions for implicit conversions to all parameters -- A member
                         function can not convert the 'this' argument.  Avoid making friends unnecessarily <rf:iref item="meyeS_2005" 
                         part="item 24"/>.
                     </li><li>
                         For static friends, declare the function static before declaring it a
                         friend.  Otherwise the function will have external linkage <rf:iref
                             item="liscR_2003" page="170"/>.
                     </li></ul>
             </li><li>
              </li><li>
                 Overloading vs. defaults -- Use method overloading instead of default arguments.
                 Compilers usually implement defaults by
                 compiling the default value into the call.  This breaks most calls if the default
                 value is changed <rf:iref item="cwalK_2006" page="109"/>
             </li><li>
                 Implement a non-throwing swap -- "To <i>swap</i> the values of two objects is to
                 give each the other's value."  A non-throwing swap simplifies exception-safe code
                 and assignment-to-self.  Swap is particularly useful for classes with a private data class
                 <rf:iref item="meyeS_2005" part="item 25"/>.
                 <ul><li>
                     Implement swap via a public swap function (c.f., STL  containers).
                 </li><li>
                     Use a total template specialization (prefixed with "template&lt;>") to specialize
                     STL's swap template.  
                 </li><li>
                     In the class, define a public <code>swap</code> function that invokes
                     <code>std::swap</code> on the private data pointers.
                 </li><li>
                     The template specialization is <code>a.swap(b)</code>
                 </li><li>
                     If the class and private data are themselves templates, use a non-member swap
                     function instead of a template specialization.
                 </li><li>
                     For greater flexibility, define both a non-member swap and a template
                     specialization.  
                 </li><li>
                     Never throw exceptions.  A non-throwing swap simplifies exception-safe code.  Custom swaps usually operate on built-in types, which
                     themselves never throw exceptions.
                 </li></ul>
             </li><li>
                 const return value -- Return a const reference, pointer, or iterator to provide read-only
                 access.   
             </li><li>
             </li><li>
             </li><li>
                 
             </li></ul>
         </rf:item>
         <rf:item id="cpp-inheritance"  title="Guidelines for inheritance" date="Mar 2008" author="bbarber">
             <p>A derived class inherits from a base class.  The derived class may add new
                 methods and data members, or it may redefine virtual methods.</p>
             <p>See also <rf:iref item="cpp-extend"/> and <rf:iref item="cpp-inheritance-virtual"/>.</p>
             <ul><li>
                 Limit inheritance -- Expose the fewest interfaces and inherit as little as possible
                 <rf:iref item="cwalK_2006" page="114"/>.    Seal the implementation if
                 possible.  
             </li><li>
             </li><li>
                 Public inheritance means "is-a" -- Use public inheritance only if the derived
                 class may be used in the same places as its base class.  The key attribute is
                 substitutivity.   Can you substitute the derived class for its base class?   For
                 example,  a square is <i>not</i> a rectangle because its width can not change
                 independently of its height <rf:iref item="meyeS_2005" part="item 32"/>.  "In
                 correct inheritance, a derived class models a special case of a more general base
                 concept." <rf:iref item="suttH_2005" page="66"/>.
             </li><li>
                 Provide classes without virtual or protected members -- Users can easily
                 and safely extend a class by invoking its public methods and properties <rf:iref
                     item="cwalK_2006" page="164"/>.
             </li><li>
                 "Avoid hiding inherited names" -- If you redefine an overloaded name of a base
                 class, enable the remaining names with a using declaration or forwarding function
                 <rf:iref item="meyeS_2005" part="item 33"/>.  For example,  if you derive a class
                 from std::vector and redefine one of its insert operators, enable the other
                 operators with <code>using std::vector&lt;coordT&gt;::insert</code>.
             </li><li>
                 "Never redefine an inherited non-virtual function" -- If you redefine an
                 non-virtual function, pointers and references may invoke either version depending
                 on context. <rf:iref item="meyeS_2005" part="item 36"/>.
             </li><li>
                 "Never redefine a function's inherited default parameter value" -- The default
                 parameter value depends on static types.  If you redefine the default, the actual
                 default will depend on context.   For hierarchically defined defaults, use a private, virtual function  <rf:iref item="meyeS_2005" part="item 37"/>.
             </li><li>
                 Do not inherit from non-virtual destructors -- Do not inherit from a class if it
                 lacks a virtual destructor.  For example, do not inherit from STL container types
                 <rf:iref item="meyeS_2005" page="43-44"/>.
             </li><li>
                 Do not inherit from template clases -- Many symbols are inline leading to conflicts if two classes inherit from the same template class.  
                 Virtual inheritance does not work for template base classes because their destructors are non-virtual.  [<rf:iref item="qt-style" part="qt"/>
                     
             </li><li>
                 Limit use of multiple inheritance -- With multiple inheritance the same name may
                 have different inheritance paths.    Consider combining interfaces with
                 a privately inherited implementation <rf:iref item="meyeS_2005" part="item 40"/>.
             </li></ul>
             
         </rf:item>
         <rf:item id="cpp-inheritance-virtual"  title="Guidelines for inheritance of virtual methods"
             date="Mar 2008" author="bbarber">
             <p>Inheritance may redefine virtual methods.   An interface or abstract base class only
                 contains virtual methods.</p>
             <p>See also <rf:iref item="cpp-extend"/> and <rf:iref item="cpp-inheritance"/>.</p>
             <ul><li>
             </li><li>
                 Limit use of virtual methods -- A virtual method implies a contract that must be
                 fulfilled by subclasses forever.  It may execute arbitrary code.  The interactions may be subtle and complex.  
                 A virtual method can not be modified at runtime. 
                 <rf:iref item="cwalK_2006" page="168-169"/>
             </li><li>
                 Abstract base class with at least two derived classes -- Make an abstract base
                 class only when you have two or more concrete, leaf classes <rf:iref
                     item="meyeS_1996" part="item 33"/>.   
             </li><li>
                 Make base classes abstract with a virtual destructor -- An abstract base class defines at least one pure
                 virtual function (e.g., <code>virtual ~AbstractClass()=0;</code>).  
                 It helps prevent 
                 partial assignments, heterogeneous assignments, and polymorphic arrays.  It
                 encourages explicit definitions of useful abstractions.    Make the destructor virtual if and only it
                 the class has virtual members <rf:iref item="meyeS_2005" part="item 7"/>.
             </li><li>
                 Inherit an interface -- Inherit an interface by
                 deriving from pure virtual functions.  Consider non-virtual methods 
                 that define a default  implementation <rf:iref item="meyeS_2005" 
                     part="item 34"/>.
             </li><li>
                 Inherit an interface with a mandatory implementation -- The base class should
                 define an API's usage.  Do not make virtual methods public, instead make virtual
                 methods protected and call then from public, non-virtual methods.  This is  
                 the <i>template pattern</i> or the
                 <i>non-virtual interface (NVI)</i> idiom
                 <rf:iref item="meyeS_2005" 
                     part="item 34, page 170-171"/> <rf:iref item="cwalK_2006" page="170"/>. 
             </li><li>
                 Do not call virtual functions from constructors or destructors -- Virtual
                 functions behave oddly when called from a constructor or destructor.  For example,
                 virtual functions called from a base class constructor do not call the derived
                 class.  Consider defining a static helper function to supply the base class
                 constructor with appropriate information <rf:iref item="meyeS_2005" part="item 9"/>.
             </li><li>
                 Virtual, non-member function -- A non-member function (e.g., operator&lt;&lt;) can
                 call a virtual method <rf:iref item="meyeS_1996" page="128-129"/>.
             </li><li>
                 Virtual, overloaded member  -- When defining overloaded members of increasing
                 length, only make the longest overload virtual.  The others can call the virtual
                 overload <rf:iref
                     item="cwalK_2006" page="108"/>.
             </li><li>
                 Multiple inheritance declaring a virtual base class -- If a base class is declared '<code>virtual</code>'  only one
                 instance of the class will occur in a object, otherwise multiple instances 
                 occur if a base class occurs multiple times <rf:iref item="liscR_2003"
                 page="164-166"/>.  Avoid using virtual base classes, especially those containing
                 data <rf:iref item="meyeS_2005"
                     page="194"/>.
             </li><li>
                 Double dispatch -- A virtual method may, with difficulty, dispatch on two or more of its arguments
                 <rf:iref item="meyeS_1996" part="item 31"/>.
             </li></ul>
         </rf:item>
         <rf:item id="cpp-initialize"  title="Guidelines for initialization" date="Mar 2008" author="bbarber">
             <p>Data members, stack variables, static objects, and class members need to be initialized before first use.  <rf:iref
                 item="liscR_2003" page="38-42"/></p>
             <p>See also <rf:iref item="cpp-constructor"/></p>
             <ul><li>
                 Default initialization -- By default, non-POD
                 objects are initialized with their default class constructor.  POD data members and
                 stack variables are
                 uninitialized.  An empty
                 initializer list initializes POD types to zero (e.g., 'int a[10]={}') .
             </li><li>
                 Delay initialization -- Initialize a variable when its arguments are
                 available and its use is imminent.   Initialization at use makes code
                 easier to read, and may avoid initialization altogether.  Prefer
                 initialization to  reassignment of a loop variable <rf:iref
                     item="meyeS_2005" part="item 26"/>.
             </li><li>
                 Assignment or call -- Initialization  may look like assignment (e.g., 'int x=42' or 'int a[]={57,3,2,1}') 
                 or a function call (e.g., int x(42)) <rf:iref
                     item="liscR_2003" page="117-119"/>.
             </li><li>
                 Resource acquisition is initialization (RAII) -- Manage resources by allocating
                 them in a constructor and releasing them in the destructor.  Since exceptions
                 automatically destruct local objects, the corresponding resources are
                 automatically released <rf:iref item="meyeS_2005" part="item 13"/>. 
             <ul><li>
                 "Never
                 allocate more than one resource in a single statement." <rf:iref
                 item="suttH_2005" part="item 13"/>
             </li><li>
                 Copying resource managed objects -- For complex resources such as a mutex lock,
                 be careful about copying RAII objects.   Disallow copying by defining a private copy
                 constructor and assignment operator.  Implement reference counting for
                 implicitly shared objects.  Consider using deep copies or ownership transfer
                 <rf:iref item="meyeS_2005" part="item 14"/>.
             </li><li>
                 Access to the raw resource --  For access to the resource managed by a RAII
                 object, provide either a get() method or implicit pointer
                 conversion.  Use get() to avoid unintended conversions.  Use implicit pointer
                 conversions for natural pointer references and dereferences <rf:iref
                     item="meyeS_2005" part="item 15"/>.
             </li></ul>
             </li><li>
                 Move static objects to a function -- In C++, the initialization order for non-local
                 static objects is undefined.  Move these objects from the class declaration to
                 a function definition where they are initialized on the first call.   See also
                 singleton objects and factory methods <rf:iref item="meyeS_2005" page="30-33"/>.
                 Do not call such functions from the destructor of a static object <rf:iref
                 item="liscR_2003" page="131"/>.
                 Do not initialize static data members at runtime
                 <rf:iref item="dewhSC_2003" page="164-165"/>.
             </li><li>
                 Singleton pattern -- Define a factory method that returns its static object . 
                 Use a static counter to limit the number of objects <rf:iref item="meyeS_1996" page="130-134"/>.
                 If multi-threaded, call each singleton class on the initialization thread
                 <rf:iref item="meyeS_2005" page="32"/>.   If static code must run first, define
                 a static object as in &lt;ios>, <code>ios_base::Init</code> <rf:iref
                     item="liscR_2003" page="130-131, 516-517"/>.
             </li><li>
             </li></ul>
         </rf:item>
        <rf:item id="cpp-io"  title="Guidelines for I/O" date="Jan 2009" author="bbarber">
            <ul><li>
                Always prompt for interactive input -- Prompt the user before requesting input.  Use
                IO::Interactive to test for interactivity.  For Perl, consider using IO::Prompt.
                <rf:iref item="conwD_2005" page="217-221"/>.
            </li><li>
               Use progress indicators for interactive programs -- If an operation will take a
               while, use a progress meter or prompt the user with the reason. a sequence 
               of dots, and 'done'
                <rf:iref item="conwD_2005" page="222-223"/>.
            </li></ul>
         </rf:item>
         <rf:item id="cpp-layout"  title="Guidelines for layout" date="Feb 2008" author="bbarber">
             
             General
             <ul><li>
                 Code in paragraphs -- Group related statements and definitions into paragraphs.  
                 Start the paragraph with a comment 
                 <rf:iref item="conwD_2005" page="23"/>.    
             </li><li>
                 Declare in paragraphs -- In header files, group related entities together.  Organize each group
                 alphabetically.   If you use #//Comment to indicate groups, a code outliner may
                 include the groups.   A workable order is Fields, Constructors, GetSet, and Modify.
             </li><li>
                 Align corresponding items vertically -- Use vertical alignment to group related
                 information.  It makes it easier to scan names and documentation.  
                 <rf:iref item="conwD_2005" page="26"/>.  For header files, place return types at column 4 and 
                 names of functions and fields at column 25.
             </li><li>
                 4-space indents -- Four spaces balances readability with horizontal space limits. 
                 Avoid tab characters since they may vary in appearance
                 <rf:iref item="conwD_2005" page="19, 20"/>.  Indent preprocessor directives the
                 same as code.
             </li><li>
                 Minimize spaces -- Avoid spaces before opening braces and before opening parentheses.
                 <rf:iref item="cwalK_2006" page="275-276"/>.   Do not use a space before
                 assignment.  Although non-standard, it  distinguishes left - from right-hand side,
                 and it helps avoid
                 substituting assignment for equality.  
             </li></ul>
             
             Headers
             <ul><li>
                 
             </li><li>
                 Declare fields first -- List the private fields of a class first.  It is easier
                 to read the concrete representation of a class than to deduce the representation from its
                 public interface.
             </li></ul>
             
             Code
             <ul><li>
                 #include from specific to general -- List your module's header file first, 
                 followed by application header files, then system header files.  It helps avoid circular includes 
                 and hidden dependencies. [<rf:iref item="qt-style" part="qt"/>].  See <rf:iref item="qt-style" part="library"/> for suggestions on managing include files.
             </li><li>
                 Define and declare in the same order -- Header files and code files should follow
                 the same order.  The one can act as an index to the other.  
             </li><li>
                 Two line method signatures -- Use two lines for method declarations.  Place the 
                 return type, class, and '::' on a line by itself.   The second line starts with the
                 method name.   While
                 non-standard, it places names on the left edge for quick scanning.
             </li><li>
                 switch...case -- Align the case statements with the switch.  Use either 'break' or a comment at the end of each case [<rf:iref item="qt-style" part="kde"/>]
             </li><li>
                 }else{ -- Do not use a space between a closing brace and a keyword.  While
                 non-standard, this increases the visibility of alternative expressions. 
                 Alternatively, place the keyword on the next line <rf:iref item="conwD_2005"
                     page="24"/>.
             </li><li>
                 Operator spacing -- Add spaces around low precedence operators.   It groups an
                 expression into clauses.  You may want
                 spacing around all operators <rf:iref item="conwD_2005"  page="14"/> or no
                 spacing at all <rf:iref item="cwalK_2006" page="276"/>.  Consider spacing 
                 for 'operator!'.  Spacing enhances its visibility.
             </li><li>
                 Long lines -- Break long lines before an operator.  If you break a line after the
                 operator, it is lost
                 at the end of the line.   Select the lowest precedence operator, or the assignment
                 operator.   If multiple lines, place the terminating semicolon on a
                 line by itself.    If in the middle of a comma list, define the expression as a
                 variable
                 <rf:iref item="conwD_2005"  page="27-31"/>.
             </li><li>
                 One-line statements -- A statement block may be on one line with spaces around the
                 brace delimiters.  Use one-line statements for inline function, getters, and
                 setters
                 <rf:iref item="cwalK_2006" page="274"/>.
             </li><li>
                 K&amp;R brace style -- Place the opening brace at the end of the line, without a
                 preceding space.  Place the last, closing brace on a line by itself.  Always use
                 braces around one-line blocks <rf:iref
                     item="cwalK_2006" page="274"/>
                 <rf:iref item="conwD_2005"  page="9-11"/>.
             </li><li>
                 End comments -- Use end comments for methods, classes, and namespaces.  Echo the
                 block's name (e.g., }//main). 
             </li><li>
                 Cascading conditionals -- Instead of cascading if statements, consider 
                 cascaded ternary operators aligned into columns (i.e., 'test ? if true : if false).
                 The first column is conditionals starting with a colon
                 <rf:iref item="conwD_2005"  page="31"/>.
             </li></ul>
         </rf:item>
         <rf:item id="cpp-memory"  title="Guidelines for memory mangement" date="Feb 2008" author="bbarber">
             <ul><li>
                 Store heap objects in smart pointers -- If an object is allocated on the heap,
                 initialize a smart pointer with its reference.  Otherwise exceptions may leak the
                 object <rf:iref item="meyeS_2005" part="item 17"/>.
             </li><li>
                 Reference counted objects -- See Qt's implicitly shared data and Meyer's on
                 reference counting <rf:iref item="meyeS_1996" part="item 29"/>.
             </li><li>
                 Heap-only objects -- Restrict objects to the heap by making the destructor private.
                 Then define a <code>Destroy()</code> method to explicitly delete the object.  See
                 Meyer's <a
                     href="http://www.aristeia.com/BookErrata/M27Comments_frames.html"
                     >errata</a> for a discussion of how to tell if a object is on the heap.
             </li><li>
                 Stack- and static-only objects -- Prevent heap objects by declaring operator new as
                 private <rf:iref item="meyeS_1996" page="157"/>.
             </li><li>
                 Match new with delete -- Do not mix array allocation with object deallocation.  Do
                 not deallocate objects from a different module. <rf:iref item="suttH_2005"
                     part="item 60"/>.
                 "The rule is simple: if you use [] in a new expression, you must use [] in the
                 corresponding delete expression."  To avoid confusion, do not use typedefs for
                 array types  <rf:iref item="meyeS_2005" part="item 16"/>.
             </li><li>
                 Replace new and delete together -- A class may define a custom new and delete
                 function for efficiency, reduced overhead, improved alignment, improved cache
                 consciousness, etc. <rf:iref item="meyeS_2005" part="item 50, item 51, item 52"/>.
             </li><li>
                 set_new_handle -- Classes 
                 and templates may define their own new handler.  When memory allocation fails, C++ repeatedly calls set_new_handler until
                 memory becomes available, an exception is thrown, or the program exits <rf:iref item="meyeS_2005" page="49"/>.
             </li><li>
                 Dispose pattern -- Managed C# code uses the IDisposable interface to release
                 unmanaged resources.  Avoid the use of finalizers <rf:iref item="cwalK_2006" page="249-260"/>.
             </li><li>
                 Be careful of alignment -- Different architectures require different memory alignment for native data types.  For example, pointers may need alignment to full-word boundaries.  In any case, access to aligned data is usually faster than unaligned data.  
                 Be particularly careful when casting pointers to different types.  For example casting char* to int* may crash. <rf:iref item="qt-style" part="qt"/>
             </li><li>
                 Using <code>union</code> to force alignment -- A union data type will align data to the most stringent type.  
                 For example, <code>union alignInt { char c; int i; }</code> aligns a character to the same boundary as integers. <rf:iref item="qt-style" part="qt"/>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-namespace"  title="Guidelines for namespaces" date="Mar 2008" author="bbarber">
             <p>A <i>namespace</i> defines a unique collection of names.  Java and C# use
                 hierarchical namespaces separated by dots ('.').   Hierarchical namespaces in C++
                 and Perl
                 use a double-colon ('::') separator.  Typically a Java or C# namespace
                 corresponds to a directory of the source tree.  
                 </p>
             <ul><li>
                 Place everything in a namespace.  Otherwise naming collisions may occur between unrelated
                 modules.
             </li><li>
                 Do not use a name that may also be used as a class name.
             </li><li>
                 C++ namespaces --  Nested namespaces are cumbersome in C++.  
                 Consider following Java convention (orgQhull::).  
                 Namespaces are cThe C++/Qt framework uses a flat
                 namespace with a 'Q' prefix to identify classes.  
             </li><li>
                Unnamed namespace -- Use an unnamed namespace for names restricted to a single
                 file.  All names are guaranteed to be distinct. <rf:iref item="liscR_2003" page="44"/>.
             </li><li>
                 Namespace hierarchy -- A namespace should be easily browsed for relevant APIs
                 <rf:iref item="cwalK_2006" page="69"/>.  Place rare, complex types in a
                 subnamespace <rf:iref item="cwalK_2006" page="73"/>.
             </li><li>
                 Using directive -- The using directive prepends a namespace to the search path for name
                 resolution.  Restrict using directives to function definitions <rf:iref
                 item="liscR_2003" page="48-49"/>.  Do not use them in header files or before an
                 #include <rf:iref item="suttH_2005"  part="item 59"/>.
             </li><li>
                 Separate types from templated methods and operators -- Define different
                 namespaces for types and templated
                 methods.  Otherwise, argument-dependent
                 lookup (ADL) may  accidentally select the wrong method.  Similar, assign
                 different namespaces for unrelated types.   "... avoid putting
                 non-member functions that are not part of the interface of a type <b>X</b> into the
                 same namespace as <b>X</b> <rf:iref item="suttH_2005" part="item 58"/>.
             </li><li>
                 Avoid namespaces in function declaration -- For global functions such as
                 ostream.operator&lt;&lt;, use namespaces on arguments in the definition of a
                 function, but avoid them in the declaration of the function.  In the declaration,
                 let 'using &lt;namespace>::&lt;class>' indicate the namespace.  The following problem was
                     seen with declarations with namespaces.  MSVC2005 treats declarations with and without namespaces as distinct functions  [This may be a bug in MSVC].
             </li></ul>
         </rf:item>
        <rf:item id="cpp-naming" title="Guidelines for naming" date="Feb 2008" author="bbarber">
            <p>For C++, consider adopting Microsoft's naming conventions for .NET identifiers
                <rf:iref item="cwalK_2006" page="34-66"/>.   
            Strive for syntactic and semantic consistency.
            A name should "clearly and
            accurately reflect the purpose, usage, and significance of whatever you're naming."
                <rf:iref item="conwD_2005" page="36-37"/>.   Use descriptive method names and argument names in headers <rf:iref item="qt-style" part="kde"/>.
                </p>
            <ul><li>
                Distinguish components by case -- Use upper and lower case to distinguish different
                entity types.
                <ul><li>
                    PascalCase -- Use PascalCase for class names,  and namespaces.  Consider using
                    PascalCase for public properties,
                    interfaces,  events,  enumerations, and methods.
                </li><li>
                    camelCase -- Use camelCase for parameter names and local variables
                </li><li>
                    ALLCAPS -- Use ALLCAPS for macros and #define.   ALLCAPS is frequently used for
                    constants, but it is distracting, especially for longer names.  Consider using
                    a shared, ALLCAP prefix for constants.
                </li><li>
                    PascalCase vs. camelCase for methods --  
                    Public methods are proper names 
                    with a  global identity.  .NET uses PascalCase, while 
                    most C++/Java code use camelCase.   
                    Dewhurst recommends capitalized type names to distinguish them from other
                    names
                     <rf:iref item="dewhSC_2003" page="23"/>.
                    Sutter, Alexandrescu, and Todd Hoff recommend
                    PascalCase for C++ <rf:iref item="suttH_2005" page="2"/>,
                    [<a
                        href="http://www.possibility.com/Cpp/CppCodingStandard.html#methodsnames">Hoff</a>].
                </li><li>
                </li><li>
                    Underscore -- Use underscores for ALLCAPS and private fields of a class.   .NET does not
                    use underscores <rf:iref item="cwalK_2006" page="42"/>.    Perl programmers often use
                    underscore  <rf:iref item="conwD_2005" page="44, 45"/>.  Underscore is
                    similar to a dash or a space, but it stands out.   A page of underscores can be distracting.
                </li><li>
                    Prefix -- Prefix static and global variables with 's_'.   It helps them
                    stand out.  Some users prefix private fields with 'm_' or a '_' suffix.  A more
                    readable convention is to use internal underscores for private fields (e.g., 
                    begin_node) 
                </li></ul>
            </li><li>
                Grammar rules -- Adopt a set of grammar rules for naming each entity type
                (e.g., Noun :: Adjective :: Adjective for namespaces). 
                <rf:iref item="conwD_2005" page="36-37"/>.    
                <ul><li>
                </li><li>
                    Noun phrase -- Use noun phrases (adjective* noun) for type names, properties, interfaces, and
                    variables.   For
                    namespaces, use a noun for the toplevel name, followed by adjectives (e..g,
                    <code>package Disk::DVD::Rewritable</code>).  For hashes and arrays,. consider
                    adding a preposition (e.g., %title_of, or %sales_from)
                    <rf:iref item="conwD_2005" page="37-39"/>.    
                </li><li>
                    Verb phrase -- Use verb phrases (verb, optional adjective, noun) for method names and event names.  Use past tense
                    for events that have happened.  Consider adding a preposition or participle (e.g.,
                    getRecordFor or buildExecutionProfileUsing
                    <rf:iref item="conwD_2005" page="40"/>.    
                </li><li>
                    Plural vs. singular -- Use plural for arrays and singular for hashes.    An array is
                    a collection often processed iteratively.   A hash is a
                    mapping function that is commonly used as a lookup table.  Consider naming a hash
                    with a singular noun followed by a preposition (e.g., $count_for).
                    <rf:iref item="conwD_2005" page="43"/>.    
                </li><li>
                    Type indicators -- In general, avoid type indicators (e.g., a 'i' prefix for
                    integer variables).   With C++, the use of a variable is usually near its
                    declaration..  Consider a standard prefix for statics and a standard
                    suffix for pointer to pointers (e.g., facet vs. facetp).
                </li><li>
                    Spell-out names -- Avoid using abbreviations, acronyms, and language-specific names such as 'int' <rf:iref
                        item="cwalK_2006" page="44-45"/>.  Identifiers should be spelled correctly. 
                    There's multiple misspellings, but usually only one correct spelling <rf:iref
                        item="cwalK_2006" page="287"/>.
                </li><li>
                    Avoid generic names -- Avoid generic type names such as Element, Node, Log, and
                    Message <rf:iref item="cwalK_2006" page="51"/>
                </li><li>
                    Avoid inherently ambiguous words -- Some words are inherently ambiguous,
                    particularly "last" and "set".    For
                    example:  last (previous or final), set (collection or assignment), left
                    (direction or remainder), right (direction or entitlement), no (negative or
                    number), abstract (theoretical, or summary), contract (smaller or agreement),
                    record (the best, to log, or data), second (ordinal or time), close (near or to
                    shut), bases (base or basis) 
                    <rf:iref item="conwD_2005" page="48"/>.    
                </li><li>
                    Id -- Id is an abbreviation for 'identifier'.  It is not an acronym. 
                    <rf:iref item="cwalK_2006" page="285"/>.
                </li></ul>
            </li><li>
                Use syntax and naming to distinguish entity types.   
                    <ul><li>
                        Namespaces and classes -- Use PascalCase.
                    </li><li>
                        Parameters and local variables --  Use camelCase.  Use short names for class
                       types.   Use descriptive names for builtin types (e.g., int dimension).
                        A parameter and its type should determine its meaning
                         <rf:iref item="cwalK_2006" page="64, 107"/>. 
                    </li><li>
                        Private fields of an object -- Use lower_case with at least one underscore in each 
                        name.    Class members define the static representation of an object.  They
                        should stand out from other components.
                    </li><li>
                        Boolean property and methods -- Name a boolean property with an affirmative phrase <rf:iref
                            item="cwalK_2006" page="62"/>.  The resulting conditional expression should
                        read naturally (e.g., isValid or hasEndTag)
                        <rf:iref item="conwD_2005" page="40"/>.    
                    </li><li>
                        Globals and class members -- Prefix global variables 'g_'  (file or module scope)
                        and class members with "s_" ("static class member").  Globals are implicit 
                        parameters to every procedure that
                        uses them.  They should be clearly identified.
                    </li><li>
                        Constants and enumerations -- Use PascalCase, perhaps with an ALLCAP prefix (e.g.,
                        ERRmemory).  The prefix identifies the domain.
                        Do not use "Enum" and "Flag" suffixes <rf:iref
                            item="cwalK_2006" page="59"/>
                    </li><li>
                        Derived class names -- End a derived class with the name of the base class
                        <rf:iref item="cwalK_2006" page="55"/>
                    </li><li>
                       Public methods and functions -- Use camelCase (C++, Java) or PascalCase (.NET).   
                       PascalCase is somewhat more readable, but  camelCase is well established for C++ and
                       Java programs. 
                    </li><li>
                        Event -- Use an "EventHandler" suffix for event handles (e.g., ClickedEventHandler).  Every event handler takes
                        an object (sender) and arguments (ClickedEventArgs) <rf:iref item="cwalK_2006"
                            page="63"/>
                    </li><li>
                    </li><li>
                    </li><li>
                    </li><li>
                    </li></ul>
            </li><li>
                Do not shadow names -- Avoid giving a variable or function the same name as in an outer scope.  Use -Wshadow with gcc.  These names are already defined: remainder, index [BSD strings.h].
            </li><li>
                Good names do not change -- Whenever a name changes, it breaks all uses of that name.  See Berner-Lee's 
                <a href="http://www.w3.org/Provider/Style/URI">Cool URIs don't change</a>.
            </li></ul>
        </rf:item>
        <rf:item id="cpp-operator"  title="Guidelines for operators" date="Feb 2008" author="bbarber">
             <ul><li>
             </li><li>
                 Use empty() instead of testing size() -- Prefer the empty() predicate over a
                 comparison.  The former may be defined for more types <rf:iref item="suttH_2005"
                 part="item 67"/>.
             </li><li>
                 Prefer prefix increment -- Prefix increment is more efficient than postfix since it
                 returns the newly constructed value <rf:iref item="meyeS_1996" page="34"/>,
                 <rf:iref item="dewhSC_2003" part="gotcha 87"/>.
                 C++ passes an extra zero argument to the postfix operator <rf:iref item="liscR_2003"
                     page="127"/>,
             </li><li>
                 Overload operators
                 <ul><li>
                 Avoid operator overloads -- Use operator overloads only for types with a natural
                 definition of the operator.  For example, redefine subtraction for the difference
                 between two dates <rf:iref item="cwalK_2006" page="142-143"/>,
                     <rf:iref item="conwD_2005" page="354-356"/>.
                 </li><li>
                     Overloading ostream::operator&lt;&lt; with namespace parameters -- If the parameter for operator&lt;&lt; 
                     is in a namespace, the textbook examples do not work.  In the header file, 
                     declare operator&lt;&lt; outside of the namespace with fully qualified types (e.g., std::ostream &lt;operator&lt;&lt;(std::ostream &lt;os, const orgQhull::QhullVertex::PrintVertex &lt;pr);).
                     In the code file, define the operator&lt;&lt; outside of the namespace with the same signature.  'Using' directives can simplify the code.
 <pre>
     namespace orgQhull {
         // namespace definitions
     }
     
     using std::ostream;
     using orgQhull::QhullVertex;
     
     ostream &amp;
     operator&lt;&lt;(ostream &amp;os, const QhullVertex::PrintVertex &amp;pr)
     { 
         // Definition
     }
 </pre>
                    
                     
                 </li><li>
                     Postfix operator -- Define the postfix operator in terms of the prefix operator <rf:iref
                 item="suttH_2005" part="item 28"/>. 
                 <pre>  T T::operator++(int){ T old(*this); ++*this; return old; }</pre>
             </li><li>
                 Return const objects for prefix and postfix operators -- Otherwise a chain of postfix operators will not
                 report an error <rf:iref item="meyeS_1996" page="33"/>.
             </li><li>
                 Never overload &amp;&amp;, ||, or ',' -- Overloaded implementations of  these
                 operators do not have the expected C++ semantics <rf:iref item="meyeS_1996"
                 part="item 7"/>.  The comma operator discards the results and type of the
                 left operand.  It is mainly used for evaluating functions with side effects
                 <rf:iref item="liscR_2003" page="82"/>.
                </li><li>
                 Implement op= instead of op -- Guarantee correct semantics for op= by implementing
                 the binary op in terms of op=.   If the first argument is passed by value, it may save a temporary <rf:iref
                     item="suttH_2005" part="item 27"/> <rf:iref
                     item="meyeS_1996" part="item 22"/>.
                 <pre> T operator@(const T lhs, const T&amp; rhs){ return lhs @= rhs; }</pre>
             </li><li>
                 Commutative operators -- When overloading a commutative, binary operator, you may
                 need to define two operators for differing parameter orders <rf:iref
                 item="liscR_2003" page="126"/>.
             </li></ul>
             </li><li>
                Copy assignment -- Copy assignment is closely related to copy constructors.  See
                notes on copy assignment in <rf:iref item="cpp-constructor"/>
             </li><li>
                 Be careful of the question mark operator (... ? ... : ...) 
                 <ul><li>
                     Enclose complicated selectors in parentheses -- If the selector is complicated, enclose it in parentheses.  Otherwise the '?' may associate with the wrong expression.
                 </li><li>
                     Ensure that both expressions have the same type -- If one expression is an object and the other a builtin type, the program may crash unexpectedly. [<rf:iref item="qt-style" part="qt"/>]
                 </li><li>
                     Avoid using ? with &lt;&lt; -- The ternary operator, ?, has a lower precedence than
                     the iostream operator &lt;&lt;.  This can lead to unexpected results (e.g., cout
                     &lt;&lt; a ? f() : g())
                     <rf:iref item="dewhSC_2003" page="43"/>.
                 </li></ul>
            
             </li><li>
                 Be careful of the modulus operator (%) -- In C, the result is undefined if either operator is negative 
                 and the result is non-zero. 
             </li></ul>
         </rf:item>
         <rf:item id="cpp-parameter"  title="Guidelines for parameters" date="Feb 2008" author="bbarber">
             <ul><li>
             </li><li>
                 "Prefer pass-by-reference-to-const to pass-by-value" -- For example, pass-by-value
                 of a
                 Student class costs six constructors and six destructors; none are
                 called by pass-by-reference-to-const.   Pass-by-reference avoids the slice problem
                 for base class parameters.  Use pass-by-value for built-in types, STL iterators,
                 and STL function objects <rf:iref
                     item="meyeS_2005" part="item 20"/>.
             </li><li>
                 Avoid out and ref parameters -- Pointers, aliasing, and multiple return values add
                 complexity to an API.  Return a struct if you need to return multiple values
                 <rf:iref item="cwalK_2006" page="156"/>.
             </li><li>
                 Return objects by value -- "Never return a pointer or reference to a local stack
                 object, a reference to a heap-allocated object, or a pointer or reference to a
                 local static object if there is a chance that more than one such object will be
                 needed <rf:iref item="meyeS_2005" part="item 21"/>.
             </li><li>
                 Use the least derived parameter type -- When practical, define parameters as an interface type or
                 base type.  For example, in .NET use  
                 <code>IEnumerable&lt;T></code> instead
                 of a collection  <rf:iref item="cwalK_2006" page="148, 212"/>.
             </li><li>
                 Prefer enums over boolean parameters -- Use enums if a method takes more than one
                 boolean parameter.  Use an enum if more than two choices may be required later. 
                 Enums communicate and evolve better than booleans <rf:iref item="cwalK_2006"
                     page="150-151"/>, <rf:iref item="qt-style" part="library"/>
             </li><li>
                 Validate enum parameters -- Explicitly check that an enum parameter falls into the
                 expected range <rf:iref item="cwalK_2006" page="153"/>.
             </li><li>
                 Naming -- For binary operators, use "lhs" (left-hand side) and "rhs" (right-hand
                 side) <rf:iref
                 item="meyeS_2005" page="6"/> ("left" and "right" have too many other meanings).  
                 For unary operators and copy constructors, use
                 "other" .  For the index of a vector, use "index" instead of "pos" or "i".
             </li><li>
                 Do not reserve parameters -- Define new methods instead of using reserved
                 parameters <rf:iref item="cwalK_2006" page="148"/>
             </li><li>
                 Replace long parameter lists with named arguments -- Use named arguments if  a
                 function has more than three parameters.  Named arguments are easier to remember and verify
                 than positional arguments.  Named arguments may have default values.
                 In Perl, pass an anonymous hash. of name-value pairs
                 <rf:iref item="conwD_2005" page="182-183"/>.
             </li><li>
                 Prefer const -- Parameters, methods, and return types should be const if possible  
                 <rf:iref item="meyeS_2005" part="item 3"/>.
                 <ul><li>
                     Bitwise vs. logical const -- Implement logical const.  C++ assumes
                     bitwise const for efficiency reasons.   Add 'mutable' to fields that do not affect
                     logical const (e.g., a cached value) <rf:iref item="meyeS_2005" page="21-23"/>.
                 </li><li>
                     Apply const everywhere it is appropriate -- Once a method is non-const, it may
                     only be used from non-const methods.
                 </li><li>
                     Const vs. non-const methods -- If appropriate, define methods with both a 
                     const and non-const return type.  C++ will select the appropriate method. 
                     Reduce code duplication by calling the const method from the non-const method. 
                     Invoke the const method using static_cast (e.g., <code>return
                         const_cast&lt;char&amp;>(static_cast&lt;const TextBlock&amp;>(*this)
                         [position]);</code>)
                     <rf:iref item="meyeS_2005" page="23-24"/>.
                 </li><li>
                     const T* const -- If 'const' is after the *, the pointer can not be modified.
                     If 'const' is before the *, the data can not be changed.  
                 </li><li>
                     Const return value -- A const return value prevents assignments to the returned
                     value (e.g., <code>(a+b)= c</code>) <rf:iref item="meyeS_2005" page="18-19"/>.  
                     Unfortunately, it also reduces opportunities for
                     composition (e.g., <code>(stringA + stringB).toUppercase()</code>)
                 </li><li>
                     const_iterator -- By convention, a const_iterator may not be used to modify the data.
                     Because the STL defines iterator as a template, a const modifier would apply
                     to the pointer instead of the data.
                     
                     <p>It Qt and KDE code, prefer const_iterator over iterator to avoid detaching from implicitly shared objects.
                     Use constBegin() to initialize the iterator and cache the result of constEnd() to terminate the loop.  
                     Do not mix const and non-const iterators. [<rf:iref item="qt-styel"/></p>
                 </li><li>
                     
                 </li></ul>
                 
             </li></ul>
         </rf:item>
         
         <rf:item id="cpp-pointer"  title="Guidelines for references and pointers" date="Feb 2008" author="bbarber">
             <ul><li>
                 Reference vs. pointer -- A reference is a permanent alias for another object
                 (e.g., v[0]).
                 Use references for assignment targets and parameters.  
                 Use pointers when the value may change or become null. <rf:iref item="meyeS_1996"
                 page="11"/>.
                 "A reference is an alias for its initializer. ... 
                 The only thing one can do with a reference is initialize it."
                 <rf:iref item="dewhSC_2003" part="gotcha 5"/>.
             </li><li>
                 Null pointer -- Use 0 as the null pointer
                  <rf:iref item="dewhSC_2003" part="gotcha 9"/>.
             </li><li>
                 Smart pointer -- A smart pointer or auto pointer redefines <code>operator*</code> and <code>operator-></code> on a private
                 pointer member <rf:iref item="meyeS_1996"  part="item 28"/>.
                 <ul><li>
                     Pass smart pointers by const reference.  
                 </li><li>
                     Typically the pointer will own the object and automatically delete the data on
                     destruction.   If so, define
                     assignment and copy construction to transfer ownership. 
                     For example, copy assignment of std::auto_ptr&lt;T> automatically sets the source
                     to 0.  Alternatively, use a reference count.
                 </li><li>
                     std::tr1::shared_ptr&lt;T> -- A shared_ptr is a reference-counting smart
                     pointer.  Copying a shared pointer bumps its reference count.  Similarly,
                     destruction decrements the reference count, deleting the object if zero. 
                     <rf:iref item="meyeS_2005" page="64-66"/>.
                     To call additional methods on destruction, pass a "deleter" method
                     to the constructor <rf:iref item="meyeS_2005" page="68"/>. 
                 </li><li>
                     Implicit sharing, QSharedDataPointer -- Qt uses
                     implicit sharing for many of its classes.   Each copy increments a reference
                     count.   Each destruction decrements the reference count, deleting the object on
                     reaching zero.  Each potential modification clones the object unless there is
                     only one  reference.
                     <ul><li>
                         Inexpensive return-by-value -- With implicit sharing, it is inexpensive to
                         return a data structure by value, copy a data structure, or pass a data
                         structure by value.
                     </li><li>
                         Accidental deep copies -- With implicit sharing, any non-const operation will
                         create a new instance of the data structure.   For example, operator[]
                         comes in const and non-const variations.  If the non-const operator occurs,
                         the data structure will be deep copied.  To help avoid these problems, use
                         const functions such as at() or make value parameters const.
                     </li><li>
                     </li><li>
                     </li><li>
                     </li><li>
                     </li></ul>
                 </li><li>
                     Do not implicitly convert smart pointers
                     to dumb ones. 
                 </li><li>
                     Use member templates to implicitly convert a smart pointer base class to a
                     derived class.  See <rf:iref item="cpp-template"/>.
                 </li><li>
                     Redefine <code>operator!</code> to test for null.
                 </li><li>
                     Define SmartPointerToConst to allow assignments from non-const to const
                     pointers <rf:iref item="meyeS_1996" page="180-182"/>.
                 </li></ul>
             </li><li>
                 "Avoid returning 'handles' to object internals" -- For example, do not return a
                 reference, pointer, or iterator to a data member.  A const reference is OK.  Once a
                 handle is returned, "you run the risk that the handle will outlive the object it
                 refers to."   "[Never]
                 return  a handle to a less accessible member function"  <rf:iref item="meyeS_2005" part="item 28"/>.
             </li><li>
                 Return a pointer to allocated storage -- Use a pointer to return newly allocated
                 storage.   It signals the caller that the storage needs to be deleted.  Do not return a reference
                 <rf:iref item="dewhSC_2003" page="187"/>.
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-property"  title="Guidelines for properties" date="Feb 2008" author="bbarber">
             <p>See also <rf:iref item="cpp-data"/></p>
             <ul><li>
             </li><li>
             </li><li>
                 property vs. method -- A class may use many parameters with few properties (a
                 functional contract) or few
                 parameters with many properties.   The later is easier to use, self-documenting, and
                 more easily versioned.   Multiple threads can use the same functional class invoking a
                 single call <rf:iref item="cwalK_2006" page="115-120"/>.  
             </li><li>
                 Inexpensive properties -- "Use properties for
                 simple access to simple data with a simple computation" <rf:iref
                     item="cwalK_2006" page="Mariani, 120"/>
             </li><li>
                 Define setters and getters -- The getter may be the name of the property.  Use
                 'set...'  or 'Set...' for the setter.  Do not use the same name for both
                 (especially in Perl).  
                 <rf:iref item="conwD_2005" page="340-346"/>.
             </li><li>
                 Invalid state -- Allow invalid states for properties.  Throw an exception when the
                 properties are used together <rf:iref item="cwalK_2006" page="121"/>.
             </li><li>
                 Throw exceptions for setters -- Do not throw exceptions for getters <rf:iref
                     item="cwalK_2006" page="121-122"/>.
                 
             </li></ul>
         </rf:item>
         <rf:item id="cpp-security"  title="Guidelines for security" date="Feb 2008" author="bbarber">
             <ul><li>
                 Validate a copy of mutable parameters -- If a parameter is mutable, validate and
                 use a copy of the parameter.  Otherwise, the caller may modify the parameter after
                 validation, creating a security hole <rf:iref item="cwalK_2006" page="154"/>
             </li><li>
                 Be careful of ToString -- Debugging and exception messages can leak detailed
                 security information to the user.  Be careful <rf:iref item="cwalK_2006" page="202"/>.
             </li><li>
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
        <rf:item id="cpp-testing"  title="Guidelines for testing" date="Jan 2009" author="bbarber">
            <p>
                Untested software does not work correctly.  By default, software fails to meet its
                expectations.  Just as newly written software almost always has compiler errors,
                untested code contains logic and design errors.
            </p>
            <ul><li>
                Write test cases first -- Write test cases as you design the interface.   A test
                suite is an executable specification of your code's expected behavior.   Run it
                often to catch regressions. 
                <rf:iref item="conwD_2005"  page="420"/>.
            </li><li>
                 Compile with warnings as errors -- Always compile with warnings reported as errors.
                 Disable legitimate warnings selectively.  Warnings often indicate problems with
                 your code.  Do not delay your investigation
                 <rf:iref item="conwD_2005"  page="433-436"/>.
             </li><li>
                Write test cases quickly -- Make test cases easy to write.  Use a test framework and
                enhance it for your application.   Writing a custom driver and manually reviewing
                the output is too much work.   In C++, consider QTest and Nunit.  In Perl, 
                consider Test::Simple, Test::More, and Test::Harness.
                <rf:iref item="conwD_2005"  page="421-425, 466-467"/>.
                Alternatively, make your code self-checking  and develop a command line interface to
                drive the code.  Then a test suite is a long sequence of commands.  For initial
                releases, you should exercise the code far more than your new users.
            </li><li>
                Write test cases that fail -- Try to trip up your code.  Do not write existence
                tests (i.e., does this function exist?).  Find the bugs that others will not find.
                <rf:iref item="conwD_2005"  page="425-427"/>.
            </li><li>
                 Make code fail easily -- Do not allow errors to hide in your code.   Think of a
                program's execution as a narrow maze through an immense space.   The program is
                correct if it stays within the maze.   An error is a step outside of the maze.
                Once outside of the maze, anything can happen.
                    Whenever practical, check your invariants.   Verify that you are in the maze.  Then, if
                something goes wrong, you know it quickly and know when it was last right.
                </li><li>
                Write test cases for bugs -- If someone reports a bug, your tests failed.  Add
                test cases for the bug.  Search for related problems and add tests as needed
                <rf:iref item="conwD_2005"  page="427-429"/>.
            </li><li>
                Learn to use the debugger -- Learn the debugger for your programming language. 
                Watching a program step through a routine is likely to surprise you.   New code
                should be watched at least once.   It may be the fastest way to detect bugs
                <rf:iref item="conwD_2005"  page="436-437"/>.
            </li><li>
                Benchmark your code -- Test the efficiency of your code.  You will be surprised by
                the results.  Identify the bottlenecks.  Know
                what routines are frequently called and what routines are expensive.  Test both
                space and time efficiency
                  <rf:iref item="conwD_2005" page="456-460, 464-466"/>.
 
            </li></ul>
         </rf:item>
         <rf:item id="cpp-template"  title="Guidelines for templates" date="Feb 2008" author="bbarber">
             <p>
                 With templates, polymorphism occurs at compile-time. 
                 A template defines an implicit interface based on a type's valid expressions. 
                 In contrast,  inheritance occurs at run-time, defining an explicit
                 interface based on function signatures <rf:iref
                     item="meyeS_2005" part="item 41"/>.
             </p>
             <p>Use templates wisely, not just because you can [<rf:iref item="qt-style" part="qt"/>].  Templates increase 
                 the complexity of software by generating source code at compile time.  Compile-time errors may 
                 be difficult to diagnosis.
              </p>
             <ul><li>
                 Explicitly define the points of customization -- How does a caller customize the
                 code generated by a template? <rf:iref item="suttH_2005" part="item 65"/>
                 <ul><li>
                     What are its method calls?  
                 </li><li>
                     What are its nonmember function calls? -- Most non-member calls are resolved by
                     argument lookup (ADL).
                 </li><li>
                     What are the expected semantics of these functions? -- What happens when an
                     error occurs?
                 </li><li>
                     What are its specialized templates? -- The user may specialize a template to
                     define traits or adapters.
                 </li></ul>
             </li><li>
                 Prevent unintended ADL lookup
                 <ul><li>
                     Use explicit calls in templates -- Use an explicit
                     call via <code>this-></code> or a using directive.   Otherwise C++
                     may select a name from the caller's environment.   To call the base class,  qualify
                     a base class name <rf:iref item="meyeS_2005" part="item 43"/>. 
                 </li><li>
                     Place helper functions in their own namespace -- Use an explicitly qualified, 
                 nested namespace for helper functions.
             </li></ul>
             
             </li><li>
                 Member template
                 <ul><li>
                     Member function templates -- A member function template generates member functions
                     for a class.  For example, a templated constructor or assignment operator
                     will accept any type (aka. generalized copy constructor or generalized copy assignment).  
                     Be sure to declare the normal copy constructor and assignment operator <rf:iref
                         item="meyeS_2005" part="item 45"/>.
                 </li><li>
                     Implicit conversion --
                    A member template can define an implicit 
                    conversion for derived types.  For example to convert to a base, smart pointer
                     <rf:iref item="meyeS_1996" page="176"/> [<a
                         href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Coercion_by_Member_Template">wiki</a>].
                     <pre>  template&lt;class newType></pre>
                     <pre>  operator SmartPtr&lt;newType>() { return SmartPtr&lt;newType>(pointee); }</pre>
                 </li><li>
                     Use a templated friend for non-member functions -- Implement a templated non-member function
                     (e.g., operator>>) by defining it as a friend <rf:iref item="meyeS_2005" part="item  46"/>.
                 </li><li>
                     Do not specialize function templates -- When extending a function template, write
                     an overloaded function instead of a specialization.  Avoid overloading and
                     specializing altogether by implementing the function
                     template in terms of a class template.  Then partially specialize the class
                     template <rf:iref item="suttH_2005" part="item 66"/>.  
                 </li><li>
                 </li><li>
                 </li><li>
                 </li><li>
                 </li><li>
                 </li></ul>
                </li><li>
                 Prefer 'typename T' to 'class T' -- A template parameter may be any type, not just
                 a class.  Also use 'typename' to indicate nested dependent names <rf:iref
                     item="meyeS_2005" part="item 42"/>.
             </li><li>
                 Remove parameter-independent code from templates -- A template may be instantiated
                 many times.  Move code that does not depend on the template's parameters elsewhere.
                  Non-type parameters (e.g., matrix size) may be replaced with function parameters
                  or class data members <rf:iref item="meyeS_2005" part="item 44"/>.
             </li><li>
                 Template metaprogramming -- With work, templates are Turing complete.  They can
                 execute programs at compile time <rf:iref item="meyeS_2005" part="item 48"/>.
             </li><li>
                 Do not use virtual methods in templates -- Avoid virtual methods in templates.  They
                 may lead to code bloat <rf:iref item="suttH_2005" page="121"/>.
             </li><li>
                 Pass by reference -- Since a template may be used for any type, use pass by
                 reference instead of pass by value.  The cost of copying may be high.  By
                 convention, function objects are passed by value
                  <rf:iref item="dewhSC_2003" page="109"/>.
             </li><li>
                 Use != instead of &lt;  -- In templates, prefer inequality over less than.  The former is defined
                 for many types and iterators <rf:iref item="suttH_2005" part="item 67"/>. 
             </li></ul>
         </rf:item>
         <rf:item id="cpp-threading"  title="Guidelines for threading" date="Feb 2008" author="bbarber">
             <p>
             </p>
             <ul><li>
                 Be careful of threading -- Guarantee that different threads can use different
                 objects without locking.   Specify how multiple threads can share an object.
                 <rf:iref item="suttH_2005" part="item 12"/>.
                 
             </li><li>
                 Async pattern -- Use the async pattern for asynchronous operations.  The main
                 elements are a Begin method, End method, Async Result object, a call-back, and a
                 State object given to the call-back. <rf:iref item="cwalK_2006" page="243-248"/>.
             </li><li>
                 Timeout -- Define timeouts as a TimeSpan parameter.  Consider using an int if the
                 timeout is always a small number of milliseconds.  Throw TimeoutException when the
                 timeout expires  <rf:iref item="cwalK_2006"
                     page="269-271"/>.
             </li><li>
             </li><li>
             </li><li>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-types"  title="Guidelines for types and classes" date="Feb 2008" author="bbarber">
             <p>
              See also <rf:iref item="cpp-design"/>
             </p>
             <ul><li>
                 
             </li><li>
                 "Minimize casting" -- "The rules of C++ are designed to guarantee that type errors
                 are impossible.   In theory, if your program compiles cleanly, it's not trying to
                 perform any unsafe or nonsensical operations on any objects."    <rf:iref item="meyeS_2005"
                     part="item 27"/>
                 <ul><li>
                     Use old-style casts
                     to call an explicit constructor for a function argument.                       
                 </li><li>
                     Avoid using dynamic_cast
                     by defining a homogeneous container or a virtual function.
                 </li><li>
                     Use Qt's QMetaObject to avoid the high cost of dynamic_cast and typeid().
                 </li><li>
                     Use static_cast to convert an integer to an enum <rf:iref item="liscR_2003"
                     page="55"/>.
                     Cast simple types with a constructor (e.g., <code>int(myFloat)</code> instead 
                     of <code>(int)myFloat</code>.  The compiler will warn if needed. [<rf:iref item="qt-style" part="qt"/>]
                 </li></ul>
             </li><li>
                 Limit use of get-set -- A type that defines getters and setters for its data
                 members, is not abstract.  Users become dependent on a particular
                 implementation
                 <rf:iref item="dewhSC_2003" part="gotcha 80"/>.  
                 Use get-set to configure a type.
             </li><li>
                 Avoid const and reference data members -- A const or reference data member limits
                 the usefulness of a class.  Assignment is difficult
                 <rf:iref item="dewhSC_2003" part="gotcha 81"/>.  
             </li><li>
                 Avoid implicit type conversions -- Implicit type conversions may happen
                 unexpectedly <rf:iref item="meyeS_1996" page="27"/>,
                  <rf:iref item="dewhSC_2003" part="gotcha 36"/>.
                 <ul><li>
                     Use 'explicit' for single
                     parameter constructors <rf:iref item="meyeS_1996" page="28"/>.  Consider 
                     implicit conversions between pointers and iterators.
                 </li><li>
                     Convert to <code>void*</code> -- For convenient null conditionals, convert to
                     <code>void*</code>.  For example, STL's <code>basic_ios</code> converts to
                     null if the failbit is set.  <rf:iref item="liscR_2003" page="54"/>.
                 </li><li>
                     For commonly used arguments, define overloaded methods and operators.  For
                     example, define operator= on <code>String&amp;, char*</code> and <code>char*,
                     String&amp;</code> <rf:iref item="suttH_2005" part="item 29"/>.   Be
                     parsimonious.  Do not support many types.   They lead to many, many methods,   
                 </li><li>
                     Consider conversions to bool, int, and string -- If an object has a natural
                     definition as a bool, int, or string, consider providing the appropriate
                     conversion.  It increases the usability of the class.
                     <rf:iref item="conwD_2005" page="356-358"/>.
                 </li><li>
                 </li><li>
                 </li></ul>
             </li><li>
                 Avoid type codes and runtime type queries -- Do not encode the type of an object.  An object-oriented type
                 is defined by its behavior, not by its state.  Otherwise code needs to test the
                 type of its objects, leading to brittle code.  It a type code is necessary, define
                 it with a virtual function
                 <rf:iref item="dewhSC_2003" part="gotcha 69"/>.
                Avoid the use of runtime type queries.  They are expensive and have the same
                failings as type codes
                 <rf:iref item="dewhSC_2003" part="gotcha 98"/>.
                 Avoid capability queries as well
                 <rf:iref item="dewhSC_2003" part="gotcha 99"/>.
             </li><li>
                 Prefer int to size_t -- The type, <code>size_t</code>, is returned by the sizeof operator in C
                 and C++.  It is an unsigned integral type.  It
                 leads to many type errors since it does not convert to signed values such as
                 <code>int</code>.  Qt rarely uses <code>size_t</code>
             </li></ul>
         </rf:item>
         <rf:item id="cpp-type-patterns"  title="Guidelines for type patterns" date="Feb 2008" author="bbarber">
             <ul><li>
             </li><li>
                 Opaque type -- An opaque type hides the implementation details for a public class
                 or handle class.
                 The public class has a private, smart pointer to the opaque type (Qt's d or d_ptr, Sutter's
                 pimpl).   The opaque type may have public fields.  Qt  appends "Private" for opaque
                 type names (e.g., QHostInfoPrivate).  Qt defines the type in a separate header
                 file (e.g., qhostinfo_p.h).   A less readable
                 choice is an "Impl"  suffix <rf:iref item="liscR_2003" page="133-134"/>, <rf:iref
                     item="meyeS_2005" page="142-145"/>.
             </li><li>
                 Interface type -- An interface class has no data members, no constructors, a virtual
                 destructor, and pure, virtual functions.  They often include a factory
                 method to create new objects.  The interface may be an abstract base class
                 or a mixin class for multiple inheritance (e.g.,  IComparable)
                 <rf:iref item="cwalK_2006"
                     page="82-83"/>, <rf:iref item="meyeS_2005" page="145-147"/>.
                 Be careful of defining interface classes. 
                 Interface classes can not evolve after they ship <rf:iref
                     item="cwalK_2006" page="77"/>  
                 Interfaces do not define a contract; prefer abstract
                 classes instead <rf:iref
                     item="cwalK_2006" page="80-81"/>.     Avoid marker interfaces without members <rf:iref
                         item="cwalK_2006" page="87"/>.
             </li><li>
                 Nested type -- A nested type is defined within the scope of another type.  Use
                 nested types for enumerators that need access to the outer type.  Do not use
                 nested types for enums <rf:iref item="cwalK_2006" page="101-103"/>
             </li><li>
                 Proxy class -- A proxy class automatically substitutes one class for another.  For
                 example <code>operation[]</code> can return a proxy class for distinguish
                 left-hand-side from right-hand-side uses <rf:iref item="meyeS_1996" part="item 30"/>.
             </li><li>
                 Function object -- A <i>function object</i> or <i>functor</i> is a class that overloads the function call
                 operator, <code>operator()</code>.  It makes it easy to pass functions into methods
                 or store them for later execution <rf:iref item="meyeS_2005" page="6"/> <rf:iref item="meyeS_2001"
                     part="items 38-42, 46"/>.  Connect
                 buttons to actions by defining a hierarchy of function objects <rf:iref
                     item="dewhSC_2005" part="item 19"/>.  Due to inlining, a function object can be
                 twice as fast as a function pointer <rf:iref item="bulkD_2000" page="171"/>.
             </li><li>
                 Static class -- A static class only contains static members.  They provide
                 shortcuts to other operations and the system (e.g., System.Environment) <rf:iref
                     item="cwalK_2006" page="85-86"/>
             </li><li>
             </li><li>
                 
             </li></ul>
         </rf:item>
         <rf:item id="cpp-value-types"  title="Guidelines for value types" date="Feb 2008" author="bbarber">
             <p>A <i>value type</i> acts like a built-in type.  For
                 example, POD types are value types, as are Qt's implicitly shared objects.
                 </p>
             <ul><li>
               A value type has a copy constructor
                 and an assignment operator.  Value types do not use virtual functions.
             </li><li>
                  Value types are passed by value or by const reference.
             </li><li>
                 Polymorph vs. value types.  Polymorph types have virtual functions, but no copy
                 constructor or assignment operator.   They are passed by pointer or occasionally
                 by reference..  In Qt, polymorph types inherit from QObject [vhilsheimer].
               </li><li>
                 struct -- Reserve structs for small, simple value types, similar to a language's
                 primitive types <rf:iref item="cwalK_2006" page="67"/>.   
                 <ul><li>
                     Limit their size to 16
                 bytes or less <rf:iref item="cwalK_2006" page="76"/>. 
                 </li><li>
                     Value type arrays are
                 more efficient than reference type arrays <rf:iref item="cwalK_2006" page="74"/>
                 </li><li>
                     Do not provide a default constructor -- Make zero, false, or null a valid
                     value.  This simplifies array initialization
                     <rf:iref item="cwalK_2006" page="89, 129"/>.  
                 </li><li>
                     Implement IEquatable for value types <rf:iref item="cwalK_2006" page="90"/>
                 </li><li>
                 </li><li>
                 </li></ul> 
               </li><li>
                   char -- Do not assume that a 'char' type is signed.  Architectures such as PPC use unsigned type for 'char'.
               </li><li>
               </li><li>
                   
               </li></ul>
         </rf:item>
        <rf:item id="cpp-version"  title="Guidelines for versioning" date="Mar 2009" author="bbarber">
            <p>Software changes over time. </p>
            <ul><li>
                Platform-specific files -- Place platform-specific code in one file per platform. 
                Switch platforms by including different files.  Do not use the preprocessor and
                #if statements
                 <rf:iref item="dewhSC_2003" page="69-70"/>.
            </li><li>
                Use a revision control system -- Software changes frequently and is defined by many  files. 
                Changes in one file often need
                corresponding changes to other files.  Use a revision control system to keep track
                of these changes
                <rf:iref item="conwD_2005"  page="441-442"/>.
                Be rigorous about the configuration of test and deployed
                software.   Integrate  your bug tracking and revision control systems.   Know what
                source changes fixed a bug.  For each source directory, know what bugs were fixed
                by changes within that source directory.
            </li><li>
                Use 3-part version numbers -- Have a standard for version numbers.  You need at
                least three fields: major, minor, and release.   Have a convention for developer
                releases
                <rf:iref item="conwD_2005" page="404-407"/>.  Perforce uses
                year.version.changelistnumber (e.g., 2007.2/122958).
            </li></ul>
         </rf:item>
    </rf:section>
    <rf:section id="cpp-qt" title="C++ Qt">
        <rf:item id="qt-links" title="Qt Links" date="Jan 2010" author="bbarber">
            <div class="twocol">
                <div class="col leftcol">
                    Help
                    <ul><li>
                        <a href="http://wiki.qtcentre.org">QtCentre Wiki</a> -- Qt framework 
                    </li><li>
                        <a href="http://bugreports.qt.nokia.com/secure/IssueNavigator.jspa?mode=show&amp;createNew=true"
                            >Qt Issue Navigator</a>
                    </li><li>
                        <a href="http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/"
                            >gcc 4.4 documentation</a>
                    </li></ul>
                </div>
                <div class="col rightcol">
                    C++ usage
                    <ul><li>
                    </li><li>
                    </li></ul>
                </div>
            </div>
            <div>
                . <!-- clear the two column display -->
            </div>
        </rf:item>
        <rf:item id="setup-qt" title="Setup Qt" date="Nov 2009" author="bbarber">
            <p><a href="http://qt.nokia.com/">Qt</a> is a cross-platform C++ framework for applications and UIs.  It simplifies C++ programming without using the STL.
                Many of the style guidelines were derived from Qt's source code.  <a href="http://qt.nokia.com/products/developer-tools">Qt Creator</a> is a development
                envioronment for writing and debugging Qt programs.
            </p>
            <ul><li>
                <a href="http://wiki.qtcentre.org/index.php?title=Deploying_Qt_Applications">Deploying_Qt_Applications</a>
            </li><li>
            </li></ul>
        </rf:item>
        <rf:item id="qt-style" title="Qt/KDE style guidelines" date="Nov 2009" author="bbarber">
            <p>Qt and KDE publish several guidelines for writing programs.  KDE is written with Qt.
            </p>
            <ul><li>
                [Qt] <a href="http://qt.gitorious.org/qt/pages/CodingConventions">Qt Coding Conventions</a>
            </li><li>
                <a href="http://qt.gitorious.org/qt/pages/QtCodingStyle">QtCodingStyle</a> -- Notes on spacing, layout, etc.
            </li><li>
                <a href="http://techbase.kde.org/Development/Tutorials/API_Documentation">API_Documentation</a> -- KDE's documentation guidelines
            </li><li>
                [KDE] <a href="http://techbase.kde.org/Development/Tutorials/Common_Programming_Mistakes">Common Programming Mistakes in KDE</a> -- KDE coding guidelines  
            </li><li>
                <a href="http://doc.trolltech.com/qq/qq13-apis.html">Designing Qt-Style C++ APIs</a> -- "An API is to the programmer what a GUI is to the end-user."
            </li><li>
                <a href="http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B">Binary_Compatibility_Issues_With_C++</a>
            </li><li>
                [library] <a href="http://techbase.kde.org/Policies/Library_Documentation_Policy">KDE Library Documentation Policy</a> 
            </li><li>
                [library] <a href="http://techbase.kde.org/Policies/Library_Code_Policy">KDE Library Code Policy</a> 
            </li></ul>
        </rf:item>
        <rf:item id="qt-code" title="Reading Qt code" date="Nov 2009" author="bbarber">
            <ul><li>
                Qt makes extensive use of implicitly shared objects.  These are similar to STL's auto_ptrs.
            </li><li>
                To maintain binary compatibility, Qt usually defines a private class to implement a public class.
                Read <rf:iref item="qt-style" part="library"/> for a discussion of Q-pointers and D-pointers.
            </li></ul>
        </rf:item>
        <rf:item id="qt-mingw" title="Compiling Qt with MinGW on Windows" date="Nov 2009" author="bbarber">
            <p>The Windows distribution of Qt Creator includes the MinGW environment.   To use MinGW and its g++ compiler, you need to compile Qt.
                Once compiled, you can select MinGW for the tool chain of a project.
            </p>

            <p>How to compile Qt [<a href="http://tronprog.blogspot.com/2009/02/compiling-qt-with-mingw-in-msys.html">Compiling-qt-with-mingw-in-msys</a>]</p>
            <ul><li>
                Download and install one of the <a href="http://qt.nokia.com/downloads">Qt Downloads</a>.  Install to a directory without internal spaces (e.g., <b>C:/qt/4.5.3</b>).
            </li><li>
                The STK for Windows includes Qt Creator with prebuilt libraries and binaries.  
                If you want to compile the source anyway.  Try these instructions.  
            </li><li>
                If need be, download and install Qt Creator from <a href="http://qt.nokia.com/downloads">Qt Downloads</a>.
            </li><li>
                Install <a href="http://www.qhull.org/road-bash">Road Bash</a> -- Road Bash provides a cross-platform shell for Linux, Unix, MacOS, and Windows.  For Windows, it redistributes MSYS.  
                Alternatives include <a href="http://www.mingw.org/msys.shtml">MSYS></a> itself and <a href="www.cygwin.org">Cygwin</a>.
                <ul><li>
                    Select a user name -- If your user name contains a space, consider selecting a name without spaces (<rf:iref item="setup-username"/>).
                </li><li>
                    Define environment variables for Qt and add Qt to your PATH.  Use Control Panels->System->Advanced->Environment Variables.
<pre>
    export QTDIR=/c/qt/4.5.3/
    export QMAKESPEC=$QTDIR/mkspecs/win32-g++
    export PATH=$PATH:$QTDIR/bin:$MINGW_DIR/bin
</pre>
                </li><li>
                    Mount the mingw directory by adding the following line to /etc/fstab (e.g., c:/bash/etc/fstab)
<pre>
    #Win32_Path                     Mount_Point
    C:/qt/qtcreator-1.2.92/mingw    /mingw
</pre>
                </li><li>
                    Test your bash shell -- ls /mingw $QTDIR 
                </li><li>
                    Configure Qt for compiling (i.e., generate Makefiles for each source directory).
<pre>
    cd $QTDIR
    # Make sure that all build products are removed
    if [[ -f Makefile ]]; then make distclean; fi
    # Consider moving the examples and demos directory elsewhere.  They take a long time to build

    # Create Makefiles for QMAKESPEC.  These options change every version
    #  Note configure.exe -- the configure script may fail to work
    ./configure.exe -prefix C:/Qt/4.6.0 -fast -no-dbus -no-declartive -no-scripttools -no-script -no-javascript-jit -no-webkit -no-svg -no-phonon-backend -no-multimedia -no-qt3support -no-largefile -opensource
</pre>
                </li><li>
                    Run either /bin/make or /mingw/bin/mingw32-make (they are the same program).  This builds object files, libraries, and executables.
                    It will take several hours.  Periodically, you will need to rerun the make command because it 
                    runs out of memory due to a resource leak.
                </li><li>
                    Check the Makefiles for Unix-style forward slashes.  If they used Windows back slashes, rerun 'configure' or 'qmake' to convert to 
                    Unix forward slashes.
                    
                 </li></ul>
            </li><li>
            </li></ul>
        </rf:item>
        <rf:item id="g++-trouble"  title="Troubleshooting g++" date="Nov 2009" author="bbarber">
            <ul><li>
                error: a class-key must be used when declaring a friend -- Use the keyword 'class', e.g.,
                <code>friend          class const_iterator;</code>
            </li><li>
                warning: expected ';' before "i" -- If you use a templated class within a template function, the expression may
                be ambiguous ('a&lt;b&gt;c' is a valid expression of comparison operators).  Avoid the ambiguity by preceeding the 
                class name with 'typename' (e.g., typename orgQhull::QhullLinkedList&lt;T&gt;::const_iterator i;)
            </li><li>
                QObject is inaccessible -- Use public inheritance to derive from QObject.  Otherwise the derived class and it moc files does not have access rights to QObject methods.
            </li></ul>
        </rf:item>
        <rf:item id="qt-creator-trouble"  title="Troubleshooting Qt Creator" date="Nov 2009" author="bbarber">
                <ul><li>
                    Could not find qmake configuration directory -- Did you define an environment variable QMAKESPEC?  For example, C:/qt/4.5.3/mkspecs/win32-g++ [src/shared/proparser/profileevaluator.cpp]
                </li><li>
                    Could not find qmake configuration file -- The file $QMAKESPEC/qmake.conf was not found. [src/shared/proparser/profileevaluator.cpp]
                </li><li>
                    make not found in the environment -- Add the MinGW bin directory to the PATH variable in Control Panels->System->Advanced->Environment Variables.
                </li><li>
                    
                </li></ul>
            </rf:item>
    </rf:section>
    <rf:section id="perl-guidelines" title="Perl Guidelines">
        <rf:item id="perl-layout"  title="Guidelines for layout of Perl programs" date="Dec 2008" author="bbarber">
            <p>Perl differs from C++ through its frequent use of notation, builtins, and context.  For example, '{ ... }'
                may indicate a hash literal or a program block depending on context..  The
                expression <code>@myarray</code>  may refer
                to the array's elements or the array's  size depending on context.
            </p>
            <ul><li>
               Use strict and warnings -- Strict prevents misspellings for turning into
                subtle bugs.  Most warnings indicate legitimate problems in your code.  Do not delay
                fixing them.  Do not use $a and $b outside of sort blocks (they are not checked by
                strict).
                <rf:iref item="conwD_2005" page="429-436"/>.
            </li><li>
                Spacing -- Do not remove spaces that clarify a program's structure.   Keep a space after control
                structure keywords such as 'if' and 'while'.   Keep spaces around complex hash keys
                or array indices 
                <rf:iref item="conwD_2005" page="11, 14"/>.
            </li><li>
                Terminating semicolons and commas -- Use a semicolon for the last statement
                (element) of a program block.  Use a comma for the last element
                or a literal list.  Neither are required, but they avoid problems
                when reorganizing or enhancing code
                <rf:iref item="conwD_2005" page="15, 17"/>.
            </li><li>
                _ref suffix -- Mark reference variables with a suffix (e.g., $opts_ref).   Otherwise
                a scalar may accidentally store a reference without the corresponding dereferencing
                arrow
                <rf:iref item="conwD_2005" page="41-42"/>.
            </li><li>
                Dereference with arrows -- Use the -> notation to access a reference (e.g.,
                <code>$list_ref->[0]</code>).  Use prefix syntax and braces for a slice (e.g.,
                <code>@{$list_ref}[0, 1]</code>).  
                <rf:iref item="conwD_2005" page="228-229"/>.
            </li><li>
                slices -- A hash or array <i>slice</i> is a subset  selected by indices (e.g.,
                @active{'top', 'prev', 'backup'}).  To select and assign many elements, create a
                literal hash whose keys select the elements and whose values specify the assignments.
                <rf:iref item="conwD_2005" page="89-92"/>.
            </li><li>
                Double quote vs. single quote -- Use double quotes for strings with interpolated
                variables.  Otherwise use single quotes
                <rf:iref item="conwD_2005" page="49"/>.  Use a pair of double quotes for the empty
                string ("").
            </li><li>
                Multi-line strings -- Use heredocs with an END_... terminator.  Double-quote the
                terminator if you are interpolating variables, otherwise single-quote the
                terminator.  For two line strings, concatenate two strings.
                <rf:iref item="conwD_2005" page="60-64"/>.
            </li></ul>
        </rf:item>
        <rf:item id="perl-builtin"  title="Guidelines for Perl builtins and subroutines" date="Jan 2009" author="bbarber">
            <ul><li>
                Builtins -- Do not use parenthesis with builtins such as 'split' and 'print'. 
                Always use parenthesis with subroutines.  Always use braces for print filehandles
                <rf:iref item="conwD_2005" page="12, 175, 217"/>.   
            </li><li>
                Always use a block with map and grep -- The map and grep builtins can take a block
                between braces or an expression.   The block format clearly separates processing
                from data
                <rf:iref item="conwD_2005" page="169-170"/>.
            </li><li>
                Use grep for lists -- For example, remove matching elements from a 
                list with <code>@a = grep { $_ ne 'b' } @a;</code>
            </li><li>
                Unpack arguments first -- A subroutine call in Perl sets @_ to aliases for each
                argument.  Since @_ has multiple uses, it is wise to immediately unpack it into
                local variables.   Use either 'shift'' or <code>my ($arg1, ...) = @_;</code>.  Use
                'shift' if you sanity check the arguments.
                <rf:iref item="conwD_2005" page="178-181"/>.
            </li><li>
                Assign defaults immediately -- If a parameter has a default value, assign it
                immediately.  Do not wait until the parameter is used 
                <rf:iref item="conwD_2005" page="185-186"/>.
            </li><li>
                Always return -- End every subroutine call with a return statement.  Otherwise Perl
                will return the last value.   If a subroutine only returns a scalar value, say so
                explicitly (<code>return scalar $result</code>.  Use 'return' instead of 'return undef' to return a
                failure.   If a subroutine returns a list,
                return a sensible value in scalar context .  If the list is homogeneous, return its
                size.  If the list is heterogeneous, return the most important element or return a
                string representation of the list.  If the subroutine returns an iterative list,
                return the first element
                 <rf:iref item="conwD_2005" page="186-193, 196-201"/>.
            </li><li>
                Use $warn and Data::Dumper -- Use $warn and Data::Dumper for debugging statements. 
                $warn identifies the statement and writes the output to stderr.      Data::Dumper
                gives the details about data
                <rf:iref item="conwD_2005" page="437-440"/>.
            </li><li>
                Weaken -- Use 'weaken' to avoid circular data structures that leak memory.  A
                weakened reference is not reference counted.  It becomes 'undef' if its referent is
                garbage collected.  For example, weaken a back link to
                prevent a cycle of nodes that each refer to the next node.  Such cycles can not be
                garbage collected.  
            </li><li>
            </li></ul>
        </rf:item>
        <rf:item id="perl-objects"  title="Guidelines for Perl objects" date="Jan 2009" author="bbarber">
            Perl provides several implementations of object-oriented programming.
            <ul><li>
                Do not make object-oriented a requirement -- Perl's support of object-oriented
                programming is inconsistent.  Method calls are slower than subroutine calls.
                Use objects for large
                applications, applications with lots of structured data, domains that are naturally 
                hierarchical, and software written by teams of programmers, 
                <rf:iref item="conwD_2005" page="319-321"/>.
            </li><li>
                Inside-out objects -- Inside-out objects implement fully encapsulated objects.  They
                define a hash for each
                attribute.   An object is a blessed, uninitialized scalar that indexes the attribute
                hashes.
                Inside-out objects safely handle single and multiple inheritance.  
                They require a destructor to delete the attributes.  See Class::Std and
                <rf:iref item="conwD_2005" page="323-333, 336-338, 361-364, 383-393"/>.
            </li><li>
                new -- Use 'new' as the name for an object's constructor.  Pass arguments as an
                anonymous hash.  Use a hash of hashes if a class hierarchy reuses attribute names.
                Do not use new() as a copy constructor (e.g., $object_ref->new()).  
                Define a clone() function instead. 
                <rf:iref item="conwD_2005" page="333-336, 367-371, 371-375"/>.
                If using multiple inheritance and class hierarchies, define new in the base class.
                New invokes BUILD and DEMOLISH methods in derived classes
                <rf:iref item="conwD_2005" page="376-383"/>.
            </li><li>
                Private methods and utility functions -- Perl does not use header files that define
                the public interface to a class.  Consider using a leading underscore to distinguish 
                methods and functions for internal use only.   
                <rf:iref item="conwD_2005" page="49"/>.
            </li><li>
                Overload boolean, numeric, and string coercions -- Object references do not
                naturally convert to booleans, numbers, or strings.   Define these conversions with
                'use overload' or make them throw an error.
                <rf:iref item="conwD_2005" page="356-358"/>.
            </li><li>
                
            </li></ul>
          </rf:item>
        <rf:item id="perl-avoid"  title="Guidelines for avoiding Perl traps" date="Jan 2009" author="bbarber">
            <p>
                Perl provides many alternatives.  Avoid the following constructs.
            </p>
            
            Control structures
            <ul><li>
                Avoid postfix if -- It hides the decision and its consequence.  Reserve postfix if for
                flow-of-control statements (e.g., return if  $floor == $measurement).
                <rf:iref item="conwD_2005" page="93-95"/>.
            </li><li>
                Avoid postfix control statements -- Do not use postfix until, for, or while
                statements.
                <rf:iref item="conwD_2005" page="96"/>.
            </li><li>
                Avoid negative control statements -- Do not use 'unless' or 'until'.   Programmers are
                unfamiliar with these constructs.  Restate in the positive.  If you use 'unless'
                never use a negative sub-clause such as
                <code>unless ($count != $MAX_COUNT)</code>
                <rf:iref item="conwD_2005" page="97-99"/>.
            </li><li>
                Avoid do..while loops -- Next, last, and redo do not work within do..while loops. 
                Rewrite as while loop with the condition initially true
                <rf:iref item="conwD_2005" page="123-125"/>.
             </li><li>
                Do not use <code>for (&lt;>)</code> -- A for statement reads in the entire file
                before starting the iteration.  Use <code>while (&lt;>)</code> instead.  If you need
                to slurp the file, consider using Perl6::Slurp
                <rf:iref item="conwD_2005" page="211-215"/>.
            </li><li>
                
            </li></ul>
         
            Data
            <ul><li>
            </li><li>
                Do not use lvalue accessors -- Do not return an lvalue from a subroutine.   it undoes 
                encapsulation of the object's data.  In C++, do not return a pointer
                to a data member.
                <rf:iref item="conwD_2005" page="346-348"/>.
            </li><li>
                Do not use symbolic references -- A symbolic reference is a lookup in a symbol
                table.  Use a lexical hash instead.
                <rf:iref item="conwD_2005" page="230-231"/>.
            </li><li>
                Do not use pseudohashes -- A pseudohash is a hash with an included schema.  They are
                expensive in memory and execution time.  They are prone to obtuse errors when 
                inherited
                <rf:iref item="conwD_2005" page="322"/>.
            </li><li>
                Do not use restricted hashes -- A restricted hash disallows access to unknown
                elements.  Unfortunately, its restrictions are easily circumvented
                <rf:iref item="conwD_2005" page="322-323"/>.
            </li><li>
                
            </li></ul>
         
            Objects and modules
            <ul><li>
            </li><li>
            </li><li>
                Do not set @ISA -- Define inherited classes at compile time with 'use base'
                <rf:iref item="conwD_2005" page="360"/>.
            </li><li>
                Do not bless without a package -- Do not use the one-argument form of 'bless'
                <rf:iref item="conwD_2005" page="365-367"/>.
            </li><li>
                Do not use indirect object syntax -- An indirect object call mimics Perl's builtins
                (e.g. method $obj instead of $obj->method()).   It leads to difficult errors.
                <rf:iref item="conwD_2005" page="349-351"/>.
             </li><li>
                Avoid AUTOLOAD -- Perl invokes AUTOLOAD for unknown methods in a class hierarchy,
                potentially adding any number of methods to a class.  For example, if a class does
                not define DESTROY(), AUTOLOAD will see the call on every object destruction.
                Do not define more than one AUTOLOAD.
                <rf:iref item="conwD_2005" page="393-396"/>.
            </li><li>
                Avoid export by default -- If you export a routine named 'fail', it will override
                similarly name subroutines from other modules.  Require explicit export for most
                subroutines
                <rf:iref item="conwD_2005" page="407-410"/>.
            </li><li>
                Do not export variables from a module -- Variables (like fields of an object) should
                be private to the module
                <rf:iref item="conwD_2005" page="411-415"/>.
           
            </li></ul>
         
            Builtins
            <ul><li>
            </li><li>
                Do not modify $_ in map, grep, or first -- For these functions, $_ is an alias, not
                a value.  Make a copy first.  Modifications to $_ modify the source element.
                <rf:iref item="conwD_2005" page="114-116"/>.
            </li><li>
                Avoid eval of a string -- String eval does not  produce warnings at compile time. 
                Use anonymous subroutines and Sub::Installer instead
                <rf:iref item="conwD_2005" page="161-164"/>.
            </li><li>
                Avoid lvalue substr -- Use a 4-argument substr instead of assigning to a substr
                <rf:iref item="conwD_2005" page="165"/>.
            </li><li>
                Do not use bareword filehandles -- Use indirect, local filehandles instead of
                bareword filehandles.  Either use 3-argument open or IO::File..  Check for errors.  Close filehandles
                explicitly, as soon as practical
                <rf:iref item="conwD_2005" page="202-210"/>.
           </li><li>
                Do not use autoflush -- Do not use autoflush, especially with <code>select</code>. 
                IO::Handle autoflush() is better
                <rf:iref item="conwD_2005" page="224-226"/>.
            </li><li>
                Do not use 'format '-- If you need ascii formated tables, consider using Perl6::Form
                <rf:iref item="conwD_2005" page="449-451"/>.
                Spreadsheet output gives you flexibility.
            </li><li>
                Do not tie variables or filehandles -- The tie builtin works behind the scenes to
                call a function whenever you
                access or modify a variable.   Use explicit calls to methods or subroutines instead
                <rf:iref item="conwD_2005" page="451-453"/>.
                
            
            </li></ul>
         
            Subroutines
            <ul><li>
            </li><li>
            </li><li>
                Do not test for undefined arguments by value -- Use <code>if (defined $arg)</code>
                or <code>if (exists $arg)</code> instead of <code>if ($arg)</code>.  The false
                values 0 and "" may become legitimate values for $arg
                <rf:iref item="conwD_2005" page="184-185"/>.
            </li><li>
                Do not use subroutine prototypes -- Subroutine prototypes lead to surprising
                behavior.  Do not use them
                <rf:iref item="conwD_2005" page="194-196"/>.

            </li></ul>
        </rf:item>
        <rf:item id="perl-regexp"  title="Guidelines for Perl regular expressions" date="Jan 2009" author="bbarber">
            Regular expressions are  a compact representation of a string
            transformation.   Treat them with care., like any programming code.    
            Mistakes are easy to make.  See <rf:iref item="conwD_2005" page="250-271"/> for additional notes on minimal
            matches, capturing parentheses, captured substrings, tokenized matching with /gc, 
            tabular regular expressions, complex regexes, alternations, and backtracking, 
            <ul><li>
                String eq is faster than regexp -- Use string eq for matching specific strings.  A
                regular expression with literal, alternative strings is slower.
            </li><li>
                Always use xms flags -- The 'x' flag allows comments and
                spaces.  The 'm' flag matches ^ and $ to the beginning
                and end of a line (as in Unix).  The 's' flag matches '.' to any character including newlines. 
                Use '[ ]' to represent a single space.  Use '\A' and \'\z' to match the beginning and end
                of a string
                <rf:iref item="conwD_2005" page="236-242"/>.
            </li><li>
                Always use brace delimiters -- Use braces for
                delimiters { e.g., <code>m{...}xms</code> and <code>s{...} {...}xms</code>.  Braces
                nest and reduce the likelihood that regexp comments become code (as in <code>
                ([^/n]*) # value of file/option/mode</code>).  Use slashes for short, embedded
                patterns within a 'map' or 'grep' expression.
                <rf:iref item="conwD_2005" page="242-246"/>.
            </li><li>
                Escaped metacharacters -- Use singular character classes for escaped metacharacters
                such as '[.]', '[*]', etc.  An alternative is named characters  (e.g.,
                <code>\N{SPACE}</code>.
                <rf:iref item="conwD_2005" page="247-248"/>.
            </li><li>
                Prefer \s to [ ] -- The character class \s matches any space character. 
                Alternatively, reduce all runs of space characters to a literal space, then match
                single spaces.
                <rf:iref item="conwD_2005" page="249-250"/>.
            </li><li>
                Prefer properties -- A Unicode property matches a character class across all
                languages {e.g., <code>\p{Uppercase}</code>
                <rf:iref item="conwD_2005" page="248-249"/>.
            </li><li>
                Use list assignment for captured substrings -- Assign a list of lexical variables to
                each captured substring (e.g., <code>my ($opt_name, $operator) = $config- =~ m{ \A (\S+)
                \s* (*|[+]=)}xms</code>
                <rf:iref item="conwD_2005" page="256"/>.
            </li><li>
                <a href="http://swtch.com/~rsc/regexp/regexp1.html">Thompson NFA for regular expressions</a> -- Thompson NFA are
                faster than Perl's implementation.  They are used in grep and awk.
            </li></ul>
        </rf:item>
        <rf:item id="perl-modules"  title="Guidelines for Perl modules" date="Jan 2009" author="bbarber">
            Perl has a wealth of modules in CPAN and the standard module library.  
            For additional recommendations, see perlmodlib and  
            <rf:iref item="conwD_2005" page="487-492"/>.
            <ul><li>
                Benchmark -- Time your routines 
                <rf:iref item="conwD_2005" page="456-348"/>.
            </li><li>
                Class::Std -- Encapsulated object-oriented classes using inside-out objects
                <rf:iref item="conwD_2005" page="323-333, 336-338, 361-364, 383-393"/>.
            </li><li>
                Config::Std -- Flexible and straight-forward configuration of your programs.  
                Provides named sections, key/value pairs, multiline values, and
                comments
                <rf:iref item="conwD_2005" page="445-448"/>.
            </li><li>
                Data::Alias -- Create an alias for most expressions.   For example, iterate over the
                keys of a hash and create an alias to each value.  Unlike the <code>each</code>
                keyword, you can modify the value through the alias
                <rf:iref item="conwD_2005" page="104"/>.
            </li><li>
                Devel::Size -- Measure the size of your data structures
                <rf:iref item="conwD_2005" page="459-460"/>.
     </li><li>
                Exception::Class -- An exception object conveys failure data to the handler.  It
                allows a hierarchy of error classes with type specific error handlers.  For example,
                <code>if (my $exception = X::EOF->caught()) { ... }</code> makes a local copy of
                $EVAL_ERROR to prevent overwrites.
                <rf:iref item="conwD_2005" page="293-298"/>.
            </li><li>
                Fatal -- Makes builtins throw exceptions.
                <rf:iref item="conwD_2005" page="278-280"/>.
            </li><li>
                Inline -- Include source code from other programming languages in your Perl modules.
                <rf:iref item="conwD_2005" page="442-445"/>.
            </li><li>
                List::MoreUtil --  Includes all, first_index, apply, pairwise, zip, uniq 
                <rf:iref item="conwD_2005" page="173"/>.
            </li><li>
                List::Util --  Includes first, max, min, shuffle, sum, and reduce.
               Util::first() returns the first element that matches an expression
                <rf:iref item="conwD_2005" page="112, 172"/>.
            </li><li>
                Module::Starter::PBP -- Module templates with test code and documentation
                <rf:iref item="conwD_2005" page="415-417"/>.
            </li><li>
                only -- Enforce dependency requirements by version.
                <rf:iref item="conwD_2005" page="407"/>.
            </li><li>
                Perl::Critic -- Static analysis for Perl Best Practices.
            </li><li>
                POE -- Portable multitasking and networking.
            </li><li>
                Regexp::Common -- Regular expressions for zipcodes, etc.
                <rf:iref item="conwD_2005" page="263-265"/>.
            </li><li>
                Scalar::Util -- Includes blessed, reftype, readonly, tainted, openhandle, weaken,
                looks_like 
                <rf:iref item="conwD_2005" page="171"/>.
            </li><li>
                Spreadsheet::ParseExcel -- Work with Excel spreadsheets
            </li><li>
                Text::CSV_XS -- Split complex lines of variable-width data
                <rf:iref item="conwD_2005" page="158-161"/>.
            </li><li>
            </li><li>
                version -- Support three-part version numbers.  Use with 'only'
                <rf:iref item="conwD_2005" page="404-407"/>.
            </li><li>
                YAML -- Compact, readable string representation of Perl data<rf:iref item="conwD_2005" page="404-407"/>.
            </li></ul>
        </rf:item>
    </rf:section>
     <rf:section id="cpp-ref" title="C++ References" order="sorted">
         <rf:item id="bulkD_2000" title="[bulkD_2000] Efficient C++: Performance Programming
             Techniques" date="Dec 2008" author="bbarber">
             <p>Bulka, Mayhew, Addison-Wesley, 2000, ISBN 0-201-37950-3</p>
             <p>Efficient C++ programming with timing comparisons.</p>
         </rf:item>
         <rf:item id="clinM_1999" title="[clinM_1999] C++ FAQs, Second Edition" date="Mar 2008" author="bbarber">
             <p>Cline, Lomow, Girou, Addison-Wesley, 1999, ISBN 0-201-30983-1</p>
             <p>Introduction to C++, its usage, and COM via FAQs.</p>
         </rf:item>
         <rf:item id="carrMD_1995" title="[carrMD_1995] Designing and coding reusable C++" date="Mar 2008" author="bbarber">
             <p>Carroll, Ellis, Addison-Wesley, 1995, ISBN 0-201-51284-X</p>
             <p>Reusable C++.  A classic.</p>
         </rf:item>
         <rf:item id="conwD_2005" title="[conwD_2005] Perl Best Practices" date="Dec 2008" author="bbarber">
             <p>Conway, O'Reilly Media, 2005, ISBN 0-596-00173-8</p>
             <p>Perl best practices are surprising relevant to C++</p>
         </rf:item>
         <rf:item id="cwalK_2006" title="[cwalK_2006] Framework Design Guidelines.  Conventions,
          Idioms, and Patterns for Reusable .NET libraries" date="Feb 2008" author="bbarber">
         <p>Cwalina and Abrams, Microsoft Press, 2006</p>
         <p>Microsoft's style guide for the .NET framework.  Thorough with lots of commentary and
             advice</p>
         </rf:item>
         <rf:item id="dewhSC_2003" title="[dewhSC_2003] C++ Gotchas :  Avoiding Common Problems in
             Coding and Design" date="Mar 2009" author="bbarber">
             <p>Dewhurst, Addison-Wesley, 2003, ISBN 0-321-12518-5</p>
             <p>An advanced course in C++ programming.  "A significant  portion of  this book is
                 spent describing the nuances of certain areas of the C++ language that are commonly
             misunderstood and frequently lead to gotchas." </p>
         </rf:item>
         <rf:item id="dewhSC_2005" title="[dewhSC_2005] C++ Common Knowledge : Essential Intermediate
             Programming" date="Mar 2008" author="bbarber">
             <p>Dewhurst, Addison-Wesley, 2005, ISBN 0-321-32192-8</p>
             <p>"Essential, common knowledge that every programmer needs to know, in a form that is
                 pared to its essentials and that can be efficiently and accurately absorbed." 
                 Includes advice on templates.</p>
         </rf:item>
         <rf:item id="lippSB_2005" title="[lippSB_2005] C++ Primer, Fourth Edition" date="Mar 2008" author="bbarber">
             <p>Lippman, Lajoie, Moo, Addison-Wesley, 2005, ISBN 0-201-72148-1</p>
             <p>A thorough introduction to the C++ language, libraries, and usage.</p>

         </rf:item>
         <rf:item id="liscR_2003" title="[liscR_2003] C++ In a Nutshell.  A language and Library
             Reference" date="Mar 2008" author="bbarber">
             <p>Lischner, O'Reilly, 2003, ISBN 0-596-00298-X</p>
             <p>Complete, concise reference to the C++ language and standard libraries</p>
         </rf:item>
         <rf:item id="meyeS_1996" title="[meyeS_1996] More Effective C++.  35 New Ways to Improve
             Your Programs and Designs" date="Feb 2008" author="bbarber">
             <p>Meyers, Addison-Wesley, 1996, ISBN 020163371X</p>
             <p>Technical details not covered by Meyers' classic, <i>Effective C++</i>.  </p>
         </rf:item>
         <rf:item id="meyeS_2001" title="[meyeS_2001] Effective STL,  50 Specific ways to Improve
             Your Use of the Standard Template Library" date="Nov 2008" author="bbarber">
             <p>Meyers, Addison-Wesley, 2001, ISBN 0201749629</p>
             <p>How to use STL well. </p>
         </rf:item>
         <rf:item id="meyeS_2005" title="[meyeS_2005] Effective C++, Third Edition:  55 Specific ways to Improve
             Your Programs and Designs" date="Feb 2008" author="bbarber">
             <p>Meyers, Addison-Wesley, 2005, ISBN 0321334876</p>
             <p>How to use C++ well.  The best advice on using C++.</p>
         </rf:item>
         <rf:item id="stroB_1993" title="[stroB_1993] The C++ Programming Language, Second Edition" date="Mar 2008" author="bbarber">
             <p>Stroustrup, Addison-Wesley, 1993, ISBN 0-201-53992-6</p>
             <p>C++ described by its creator.   Includes chapters on designing classes and libraries.</p>
         </rf:item>
         <rf:item id="suttH_2005" title="[suttH_2005] C++ Coding Standards.  101 Rules, Guidelines,
             and Best Practices" date="Mar 2008" author="bbarber">
             <p>Sutter and Alexandrescu, Addison-Wesley, 2005, ISBN 0321113586</p>
             <p>Coding standards gathered from multiple sources.</p>
         </rf:item>
     </rf:section>
</rf:topic>
