C++ Code Formatter

CodeMorph C++

CodeToHtml

Coding Standards

C++/JavaScript/Perl/Python Coding Standards


You can read and download this coding standard, coding style guide, code convention, code guideline, manual and reference for C++, JavaScript, Perl and Python programming languages from here for free at your own risk. All trademarks, registered trademarks, product names and company names or logos mentioned herein are the property of their respective owners.

C++/JavaScript/Perl/Python Coding Standards

Author: Milbert Engineering, Inc.

Date: 23 Apr 2004

Contents

  1. Introduction
  2. Programs
  3. Files
  4. Classes
  5. Methods
  6. Code
  7. Variables
  8. References
  1. C++ Header File Template
  2. C++ Source File Template
  3. JavaScript Class Template
  4. JavaScript Interface Template
  5. Perl Program Template
  6. Perl Module Template
  7. Python Class Template
  8. C# Class Template

1 Introduction

The Coding Standard specifies a look and feel and provides guidelines for developing high-quality code at Milbert Engineering. The goal of the Coding Standard is to encourage the writing of highly readable and reliable code. [1]

2 Programs

  • For command line interfaces, ensure that the interface conforms to the GNU standard.
    • Define a long-named option (e.g. "--all") that is equivalent to each short-named option (e.g. "-a").
    • Support the "--version" option by displaying [PRODUCT X.Y.Z] (e.g. "Product 1.2.1").
    • Support the "--help" option by displaying usage information  (e.g. "Watchdog [--conf-file=file] [--help] [--version]").
    • For more information, see Standards for Command Line Interfaces.
  • For command line interfaces, ensure that the error messages conform to the GNU standard.
    • Format error messages as "program: message".
    • Do not capitalize the first letter of the the message.
    • Do not end the message with a period. 
    • For more information, see Formatting Error Messages.
  • Conform to the Syslog format for log entries.  The Syslog format for log entries is one of the following:
    1.     [TIMESTAMP] [MACHINE] [PROCESS]: [MESSAGE]
    2.     [TIMESTAMP] [MACHINE] last message repeated [INTEGER] times
    For example:
        Jul 19 08:54:28 wonton httpd: Cache miss for http://web.mit.edu
        Jul 19 08:54:36 wonton last message repeated 2 times

3 Files

3.1 Commenting Files

  • Identify yourself when inserting comments into someone else's code. Whenever you insert comments into code that was written by someone else, include your initials. For example:
        // You should make the following method virtual. <rlm>
  • Identify variables using the angled brackets "<" and ">". Whenever you refer to a variable in your comments, surround the variable name with angled brackets. For example:
        // What happens when <nApeCount> == -1? <rlm>

3.2 Naming Files

  • Use the class as the filename, omitting the prefix.  For example, for the class "CSummaryGenerationThread", use the filename "SummaryGenerationThread".
  • Use the appropriate file extension.

    File Type

    File Extension

    C++ Header hpp
    C++ Source cpp
    JavaScript Class js
    JavaScript Interface js
    Perl Program pl
    Perl Module pm
    C# Class cs
    Python Program py

3.3 File Guidelines

4 Classes

4.1 Commenting Classes

  • Provide a class overview. Begin by giving the name of the class and stating whether the class is mutable or immutable. Describe the services provided by the class. When possible, provide an example. Do not expose internal representation! For example:
       /**
         * Polynomial are immutable polynomials with integer coefficients
         * coefficients. A typical Polynomial is
         * c0 + c1x + c2x2 + ...
         */
        class Polynomial { ... }

4.2 Naming Classes

  • In C++, use the letter "C" as a prefix when naming classes. For example, "CSummaryGenerationThread".
  • In C++, use the letter "I" as a prefix when naming interfaces. An interface contains no code. In C++, an interface is also known as an "abstract base class" and contains all pure virtual methods. For example, "IStockPriceObserver".
  • Try to use the suffixes "able" or "ible" when naming interfaces.  For example: IComparable, IAdjustable, and IMutableTreeNode.
  • Use the word "Exception" as a suffix when naming exceptions. For example: CNullPointerException.

4.3 Class Guidelines

  • Create classes with strong cohesion. A class with strong cohesion provides a public interface consisting of methods that clearly belong together. ([2], 116)
  • Create classes with loose coupling. A class with loose coupling provides a public interface designed so that the rest of the program can interact with it cleanly. ([2], 117)
  • Use inheritance to model "is-a" relationships. For example, use inheritance to model the relationship between a lion and an animal because a lion "is-an" animal.
  • Use composition to model "has-a" relationships. For example, use composition to model the relationship between a door and a lock because a door "has-a" lock.
  • Extend the root Exception class when creating a new exception. In C++, include the exception class by adding the following line to your code: "#include <exception>".

5 Methods

5.1 Commenting Methods

  • Specify a "Requires" clause. [5] The Requires clause states what is assumed to be true upon entry to the method. This means that the method does not need to check that the Requires clause is satisfied. Anything is allowed to happen if the Requires clause is not satisfied, including a program crash. Omit the Requires clause if a method makes no assumptions. Here is an example of a Requires clause:
        /**
         * Requires: <rCoefficient> > 0
         * Effects: Returns the approximate square root of <rCoefficient>.
         *   The result squared is within 1.0 of <rCoefficient>.
         */
        float SquareRoot( float rCoefficient ) throw( );

    Notes:
    • Every method has an implicit Requires clause that states that the method assumes all of it's inputs are non-null.
    • A robust method will rarely have a "Requires" clause because it will handle all possible inputs. It may be necessary, however, to create a method with a "Requires" clause if it is too costly or too difficult to handle certain inputs.
  • Specify a "Modifies" clause. [5] The Modifies clause lists the names of any objects that may be modified by the method. The absence of the Modifies clause implies that no objects are modified by the method. Examples of such modifiable objects include: argument variables, objects referenced by argument variables, globals such as stdout, and <this>. It is important to mention that if a field in <this> is modified, then the Modifies clause should only mention that <this> is modified. Here is an example of a Modifies clause:
        /**
         * Modifies: <anArray>
         * Effects: Appends <nElement> to the end of <anArray>.
         */
        void append( int[] anArray, int nElement ) throw( );
  • Specify an "Effects" clause. [5]
    • Describe the method's usual behavior. The effects clause should be made up of a series of statements. The first statement describes the case when no exceptions are thrown (usually no exceptions are thrown). The statement must also describe any relevant side effects.
    • Specifying any exceptions that the method might throw. If the method throws any exceptions, then the first statement should be followed by "Unless", and each following statement should describe each exception. The exception statements should have a cause and effect structure. The statement must also describe any relevant side effects. Here is an example of an effects clause with an exception: 
          /**
           * Effects: Deletes the first instance of <nElement> in <anArray>.
           *   Unless:
           *     <nElement> is not present in <anArray>
           *       => CNotPresentException, no modification to <this>
           */
          void delete( int[] anArray, int nElement )
            throw( CNotPresentException );

5.2 Naming Methods

  • Prefix private and protected method names with an underscore. For example, "_InsertElement" is a valid name for a private method.
  • Describe everything that the method does. In the method's name, describe all of the method's outputs and side effects. ([2], 80)
  • For a method that does not return a value, choose a method name that uses a strong verb.  For a method that does not return a value, the method name should reflect what the method does.  For example, Report.Print(), OrderInfo.Check(), and MonthlyRevenues.Calc(). ([2], 80)
  • For a method that returns a value, use a method name that describes the return value. For example, cos(), Customer.NextId(), Printer.Ready(), and Pen.CurrentColor(). ([2], 80)
  • Capitalize the first letter of each word in a method name. For example GetRevenueTotal().
  • Avoid meaningless or wishy-washy verbs. Some verbs are elastic, stretched to cover just about any meaning. Method names like HandleCalculation, PerformServices, ProcessInput, and DealWithOutput do not describe what the methods do. ([2], 80)

5.3 Method Guidelines

  • Write methods with strong cohesion. A method that does one thing and does it well is said to have "strong cohesion." Methods with strong cohesion are more reliable because they are easier to write correctly. ([2], 81)
  • Write methods with loose coupling. A method that has few dependencies on other methods is said to have "loose coupling." Methods with loose coupling can be easily called by other methods. ([2], 87)
  • Throw an exception to report an error. ([4], 37, 132)
  • Do not report errors via a return value. ([4], 37, 132)
  • In C++, always use "throw" to specify exceptions that a method might throw. ([4], 131) For example, to declare a method that throws no exceptions, use the following syntax
        float SquareRoot( float rCoefficient ) throw( );
    To declare a method that throws exceptions, use the following syntax:
        void delete( int[] anArray, int nElement ) throw( CNotPresentException );
  • In C++, avoid declaring methods as protected. Declare methods as protected instead of private only when they are necessary to service derived classes. ([4], 242)
  • In C++, declare methods as "virtual" to facilitate inheritance. When you declare a method as virtual, you tell the runtime system to automatically invoke the proper member method when a derived class overrides the method (dynamic binding). ([4], 287)
  • In C++, if you implement a destructor, copy constructor, or assignment operator, implement all three.  If the class has a destructor, you may wish to implement a private copy constructor and assignment operator to prevent copying. ([4], 415)
  • In C++, declare methods as const whenever the method does not make mutations. Declaring a method as const tells the compiler to ensure that the method does not make mutations to the class. Declare a member method as const whenever it makes no logical change to the object. ([3], 53)
  • In C++, declare small methods as "inline" to reduce overhead. The compiler will try to put the entire body of an "inline" method in the code stream instead of generating a call to the method. Note that the inlined method definition must appear in the header file and that the compiler rarely succeeds in inlining a virtual method.
  • In C++, declare a destructor if the class manages resources.

6 Code

6.1 Commenting Code

  • Include one line of PDL for every one or two lines of code. PDL (Program Design Language) consists of English-like statements that precisely describe specific operations. When writing PDL, avoid language-specific syntax, but write PDL at a low enough level that generating code from it will be nearly automatic. ([2], 54)
  • Record subtleties and complications. Note the possibilities of race conditions, subtleties in the algorithms, etc.

6.2 Code Guidelines

  • Perform one operation per line of code.  If you write a line of code that does more than one thing, the code will be harder to understand and debug. For example, the following line of code:
        // Open a connection to the summary URL.
        SummaryConnection = ( new URL( strSummaryURL ) ).OpenConnection( );

    is easier to understand and debug when rewritten as:
        // Create a URL that will be used to retrieve the summary.
        SummaryURL = new URL( strSummaryURL );
        // Open a connection to the summary URL.
        SummaryConnection = SummaryURL.OpenConnection( );
  • Avoid using arrays. The C++ container classes are portable, safe, and fast, so use them ([4], 394-398)! They include:
        vector<Value>
        list<Value>
        deque<Value>
        set<Value>
        multiset<Value>
        map<Key, Value>
        multimap<Key, Value>
  • Indent all code using two spaces.
  • In C++, avoid using "char" and "char*".  The C++ container class 'string' is portable, safe, and fast, so use it whenever possible.
  • In JavaScript, separate statements using the semicolon. Although JavaScript does not require the use of semicolons to separate statements on separate lines, it is good programming practice to include them. ([6], 28)
  • In C++, use the "CPointer" class to create pointers that you do not wish to manually delete.
  • In C++, initialize all pointers to NULL and set pointers to NULL immediately after deletion.  This policy enables the following test:
        if ( p == NULL ) {
            // Unused.
        }
        else {
            // Used.
        }

7 Variables

7.1 Naming Variables

  • Choose a name that fully and accurately describes the entity the variable represents. To choose a good name for a variable, begin by stating in words what the variable represents. Often that statement itself is the best variable name. It's easy to read and it is unambiguous. For example, for a variable that represents the number of people on the US Olympic team, you would choose the name NumberOfPeopleOnTheUSOlympicTeam. ([2], 186)
  • Use the following prefixes to identify a variable's scope and type.  For example, m_unApeCount is a member variable containing an unsigned number and bPassedSwimTest is a local variable containing a Boolean value.

    Prefix

    Meaning

    m_ Member variable
    g_ Global variable
    s_ Static variable
    b Boolean
    c Character
    h Handle
    n Number (integer or long)
    s String
    sz Null-terminated string
    u Unsigned
    p Pointer
    r Real (float or double)
    a Array
    vec Vector
    lst List
    deq Deque
    set Set
    mset Multiset
    map Map
    mmap Multimap
  • Capitalize the first letter of each word in a variable name. For example nRevenueTotal.
  • Choose good variable names for indexes, flags, and temporary variables.  Every variable deserves a name that fully and accurately describes the entity the variable represents. Avoid variable names like i, Flag, and Temp. ([2], 190-4)
  • Use the name of enumerated types as a prefix for the name of the members. For example:
        type COLOR is ( COLOR_RED, COLOR_GREEN, COLOR_BLUE )
  • Capitalize the names of constants and separate the words with underscores. For example: CYCLES_NEEDED or MAX_DONUTS.

7.2 Variable Guidelines

  • Do not make member variables public. Making member variables public exposes the class's internal representation to all classes. Instead of making member variables public, provide public access methods. ([3], 33)
  • In C++, do not make member variables protected. Making member variables protected exposes the class's internal representation to all derived classes. Instead of making member variables protected, provide protected access methods. ([3], 133)
  • In C++, pass objects by reference whenever possible. Use references instead of pointers when the variable will always point to an object (it will never point to null) and when the variable will point to the same object throughout its lifetime. ([4], 18, 160)
  • In C++, pass objects by constant reference whenever possible. When a method will not need to modify one of its parameters, declare the parameter as constant and the compiler will ensure that the method does not change the parameter. ([4], 19)
  • In C++, use const instead of define. The define directive does not support type checking whereas const does. Therefore, use const instead of define to declare constants.
  • In C++, place pointers inside objects and have the objects manage the pointer. The pointer returned from new should always be stored in a member variable of an object. That object's destructor should delete the allocation. ([4], 434)
  • Avoid declaring global variables. All variables should be declared within a class. You can provide access to global data by creating a class with public static methods for accessing the data.

8 References

  1. McConnell, Steve. Software Project Survival Guide. Redmond, WA. Microsoft Press. 1998.
  2. McConnell, Steve. Code Complete. Redmond, WA. Microsoft Press. 1993.
  3. Murray, Robert. C++ Strategies and Tactics. Reading, MA. Addison-Wesley Publishing Company. 1993.
  4. Marshall, Lomow, and Girou. C++ FAQs, Second Edition. Reading, MA. Addison-Wesley. 1999.
  5. Liskov, Barbara.  Program Development in Java: Abstraction, Specification, and Object-Oriented Design. Addison-Wesley. 15 Jan 00.
  6. Flanagan, David.  JavaScript: The Definitive Guide. O'Reilly.  2000.
  7. Oualline, Steve. Practical C++ Programming. O'Reilly. 1997.

Appendix A: C++ Header File Template

/**
 * (c) 2002 Milbert Engineering, Inc.
 *
 * Author: [AUTHOR]
 * Created: [DD Mmm YY]
 *
 * $Revision: 19 $
 * $Date: 4/23/04 1:38p $
 * $Author: Rmilbert $
 */

#ifndef __[CLASS_NAME_WITHOUT_PREFIX]_HPP__
#define __[CLASS_NAME_WITHOUT_PREFIX]_HPP__

[INCLUDE_DIRECTIVES]

[FORWARD_CLASS_DECLARATIONS]

[STRUCT_DECLARATIONS]

[TYPEDEF_DECLARATIONS]

/**
 * [CLASS_NAME] is [ a mutable | an immutable ] class. [TODO: Describe
 * the services of the class without revealing the implementation.]
 */
class [CLASS_NAME] extends [SUPER_CLASS_NAME] {

public:

  /**
   * Requires: [TODO: State what is assumed to be true upon entry.]
   * Modifies: [TODO: List the names objects that may be modified.]
   * Effects: [TODO: Describe the method's behavior.]
   */
  virtual [TYPE] [METHOD_NAME]
    throw( [EXCEPTION_SPECIFICATION] );

  ...

  /**
   * Effects: Performs a complete black-box test of every public
   *   method in the class.  Outputs test results using the
   *   following format:
   *     [PASS|FAIL] [TEST_NAME_01]
   *     [PASS|FAIL] [TEST_NAME_02]
   *     ...
   *   where [PASS|FAIL] is either "PASS" or "FAIL" and [TEST_NAME]
   *   uniquely identifies the test.
   */
  static void Test( );

private:

  ...

};

#endif /* __[CLASS_NAME_WITHOUT_PREFIX]_HPP__ */

Appendix B: C++ Source File Template

/**
 * (c) 2002 Milbert Engineering, Inc.
 *
 * Author: [AUTHOR]
 * Created: [DD Mmm YY]
 *
 * $Revision: 19 $
 * $Date: 4/23/04 1:38p $
 * $Author: Rmilbert $
 */

...

static void [CLASS_NAME]::Test( ) {

  // TODO: Implement Test( ).

}

Appendix C: JavaScript Class Template

/**
 * (c) 2002 Milbert Engineering, Inc.
 *
 * Author: [AUTHOR]
 * Created: [DD Mmm YY]
 *
 * $Revision: 19 $
 * $Date: 4/23/04 1:38p $
 * $Author: Rmilbert $
 */

[INCLUDE DIRECTIVES]

/**
 * [CLASS_NAME] is [ a mutable | an immutable ] class. [TODO: Describe
 * the services of the class without revealing the implementation.]
 */

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
function [CLASS_NAME]( /* [TYPE] */ [ARG], ... )
/* throws [ none | [EXCEPTION], ... ] */ {

  // TODO: Implement constructor.

}

// Inheritance from super class (if applicable)
[CLASS_NAME].prototype = new [SUPER_CLASS_NAME]( );

/* [ private | private ] [TYPE] */
[CLASS_NAME].prototype.[PROPERTY_NAME] = [DEFAULT_VALUE];

/* [ public | private ] static [TYPE] */
[CLASS_NAME].[STATIC_PROPERTY_NAME] = [VALUE];

/* [ public | private ] const static [TYPE] */
[CLASS_NAME].[STATIC_PROPERTY_NAME] = [VALUE];

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
[CLASS_NAME].prototype.[METHOD_NAME] =
/* [ public | private ] [TYPE] */ function( /* [TYPE] */ [ARG], ... )
/* throws [ none | [EXCEPTION], ... ] */ {

  // TODO: Implement method.

};

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
[CLASS_NAME].[METHOD_NAME] =
/* [ public | private ] static [TYPE] */
function( /* [TYPE] */ [ARG], ... )
/* throws [ none | [EXCEPTION], ... ] */ {

  // TODO: Implement static method.

};

...

/**
 * Effects: Performs a complete black-box test of every public
 *   method in the class.  Outputs test results using the
 *   following format:
 *     [PASS|FAIL] [TEST_NAME_01]
 *     [PASS|FAIL] [TEST_NAME_02]
 *     ...
 *   where [PASS|FAIL] is either "PASS" or "FAIL" and [TEST_NAME]
 *   uniquely identifies the test.
 */
[CLASS_NAME].Test =
/* public static void */ function( )
/* throws none */ {

  // TODO: Implement Test( ).

};

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
[CLASS_NAME].Main =
/* public static void */ function ()
/* throws none */ {

  // TODO: Implement Main( ).

};

Appendix D: JavaScript Interface Template

/**
 * (c) 2002 Milbert Engineering, Inc.
 *
 * Author: [AUTHOR]
 * Created: [DD Mmm YY]
 *
 * $Revision: 19 $
 * $Date: 4/23/04 1:38p $
 * $Author: Rmilbert $
 */

/**
 * [INTERFACE_NAME] is [ a mutable | an immutable ] interface. [TODO:
 * Describe the services of the class without revealing the
 * implementation.]
 */

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
/* function [INTERFACE_NAME]( [TYPE] [ARG], ... ) */
/* throws [ none | [EXCEPTION], ... ] */

/**
 * Requires: [TODO: State what is assumed to be true upon entry.]
 * Modifies: [TODO: List the names objects that may be modified.]
 * Effects: [TODO: Describe the method's behavior.]
 */
/* [INTERFACE_NAME].prototype.[METHOD_NAME] = */
/* public [TYPE] function( [TYPE] [ARG], ... */
/* throws [ none | [EXCEPTION], ... ] */

...

Appendix E: Perl Program Template

#!/usr/bin/perl -w

############################################################
#
# (c) 2002 Milbert Engineering, Inc.
#
# Author: [AUTHOR]
# Created: [DD Mmm YY]
#
# $Revision: 19 $
# $Date: 4/23/04 1:38p $
# $Author: Rmilbert $
#
############################################################

# Imports
############################################################

use strict;
use Getopt::Long;
require "[PROGRAM_NAME].pm";

# Constants
############################################################

# None

# Main
############################################################

# Execute the [PROGRAM_NAME] program.
&Main();

# Requires: [TODO: State what is assumed to be true upon entry.]
# Modifies: [TODO: List the names objects that may be modified.]
# Effects: [TODO: Describe the method's behavior.]
sub Main {

    my $sCommandLineArgs;
    my $[ARG_VAR_1];
    my $[ARG_VAR_2];

    # Get the command line arguments.
    $sCommandLineArgs =
        GetOptions( "[ARG_NAME_1]=s" => \$[ARG_VAR_1],
                    "[ARG_NAME_2]=s" => \$[ARG_VAR_2] );

    # If the user did not provide the required arguments...
    if( ! $[ARG_VAR_1] || ! $[ARG_VAR_2] ) {

        # Display the usage information.
        print( "Usage: [PROGRAM_NAME]\n" .
               "\t--[ARG_NAME_1]=[ARG_VALS_1]\n" .
               "\t--[ARG_NAME_2]=[ARG_VALS_2]\n" .
               "Example: [PROGRAM_NAME]\n" .
               "\t--[ARG_NAME_1]=[ARG_EXAMPLE_1]\n" .
               "\t--[ARG_NAME_2]=[ARG_EXAMPLE_2]\n" );

        # Exit the method.
        exit( 0 );

    }

    # Run [PROGRAM_NAME].
    [PROGRAM_NAME]( $[ARG_VAR_1], $[ARG_VAR_2] );

}

# Methods
############################################################

# None

Appendix F: Perl Module Template

#!/usr/bin/perl -w

############################################################
#
# (c) 2002 Milbert Engineering, Inc.
#
# Author: [AUTHOR]
# Created: [DD Mmm YY]
#
# $Revision: 19 $
# $Date: 4/23/04 1:38p $
# $Author: Rmilbert $
#
############################################################

package [PROGRAM_NAME];

# Imports
############################################################

use strict;
use English;

# Constants
############################################################

# None

# Main
############################################################

# Module has to return true.
return 1;

# Methods
############################################################

# Requires: [TODO: State what is assumed to be true upon entry.]
# Modifies: [TODO: List the names objects that may be modified.]
# Effects: [TODO: Describe the method's behavior.]
sub [PROGRAM_NAME] {

    my ( $[ARG_VAR_1], $[ARG_VAR_2] ) = @_;

    ...

}

Appendix G: Python Class Template

#!/usr/bin/env python

############################################################
#
# (c) 2002 Milbert Engineering, Inc.
#
# Author: [AUTHOR]
# Created: [DD Mmm YY]
#
# $Revision: 19 $
# $Date: 4/23/04 1:38p $
# $Author: Rmilbert $
#
############################################################

# [IMPORTS]

# [CONSTANTS]

# Overview
#
# [CLASS_NAME] is [ a mutable | an immutable ] class.  [TODO: Describe
# the services of the class without revealing the implementation.]

class [CLASS_NAME]:

  # Public interface
  ############################################################

  # [TODO: Declare the public member variables of the class.]

  # Requires: [TODO: State what is assumed to be true upon entry.]
  # Modifies: [TODO: List the names objects that may be modified.]
  # Effects: [TODO: Describe the method's behavior.]
  def [METHOD_NAME]:
    # [METHOD_BODY]

  # [TODO: Insert more public methods.]

  # Effects: Performs a complete black-box test of every public
  #   method in the class.  Outputs test results using the
  #   following format:
  #     [PASS|FAIL] [TEST_NAME_01]
  #     [PASS|FAIL] [TEST_NAME_02]
  #     ...
  #   where [PASS|FAIL] is either "PASS" or "FAIL" and [TEST_NAME]
  #   uniquely identifies the test.
  def Test:
    # [TEST_METHOD_BODY]

  # Private interface
  ############################################################

  # [TODO: Declare the private member variables of the class.]

  # Requires: [TODO: State what is assumed to be true upon entry.]
  # Modifies: [TODO: List the names objects that may be modified.]
  # Effects: [TODO: Describe the method's behavior.]
  def _[METHOD_NAME]:
    # [METHOD_BODY]

  # [TODO: Insert more private methods.]

# Main
############################################################

# Requires: [TODO: State what is assumed to be true upon entry.]
# Modifies: [TODO: List the names objects that may be modified.]
# Effects: [TODO: Describe the method's behavior.]
if __name__ == "__main__":
  # [MAIN_METHOD_BODY]

Appendix H: C# Class Template

/**
 * (c) 2002 Milbert Engineering, Inc.
 *
 * Author: [AUTHOR]
 * Created: [DD Mmm YY]
 *
 * $Revision: 19 $
 * $Date: 4/23/04 1:38p $
 * $Author: Rmilbert $
 */


/**
 * [CLASS_NAME] is [ a mutable | an immutable ] class. [TODO: Describe
 * the services of the class without revealing the implementation.]
 */

public class [CLASS_NAME] {

  // TODO: Declare members.

  /**
   * Requires: [TODO: State what is assumed to be true upon entry.]
   * Modifies: [TODO: List the names objects that may be modified.]
   * Effects: [TODO: Describe the method's behavior.]
   */
  [ public | private ] [RETURN_VALUE] [METHOD_NAME] {

    // TODO: Implement method.

  }

  ...

  /**
   * Effects: Performs a complete black-box test of every public
   *   method in the class.  Outputs test results using the
   *   following format:
   *     [PASS|FAIL] [TEST_NAME_01]
   *     [PASS|FAIL] [TEST_NAME_02]
   *     ...
   *   where [PASS|FAIL] is either "PASS" or "FAIL" and [TEST_NAME]
   *   uniquely identifies the test.
   */
  public static void Test( ) {

    // TODO: Implement Test( ).

  }

}

  Original Article: http://www.primordial.com/CodingStandard.html

  Want to format C++ and JavaScript code automatically?  Download SourceFormatX Free Trial to format all code files Now!