Comments

  • General Regulations
  • Programme Source
  • Files
  • Classes
  • Data Objects
  • Functions
  • Function Declarations
  • Function Definitions

  • General Regulations

    1. An unneccessary comment wastes space – a missing comment wastes money!
    2. Comments are written in the programmer's native language. This avoids information loss caused by the translation into a language the programmer isn't familiar with.
    3. The topic tags in file, class und function headers (‘CREATED’, ‘DECLARATION’ etc.) have the significance of key words (even if not supported by the compiler) and are therefore always written in english.
    4. (C++, Delphi) All line of a multi-line comment start with //.
      1. // this is a multi-line comment,
        // which illustrates the formatting
        // of follow-up lines in C++ and Delphi.

    5. (C, Pascal) The follow-up lines of a multi-line comment start with „//". Since the comment-terminating symbol „*/" (Pascal „*)", „}") has the character of a closing bracket, it is to be placed in the same column as the comment-starting symbol „/*" (Pascal „(*", „{").
      1. C

        Pascal

        /* this is a multi-line comment,
        // which illustrates the formatting
        // of follow-up lines in C.
        */
        (* this is a multi-line comment,
        // which illustrates the formatting
        // of follow-up lines Pascal.
        *)

      This regulation makes it easier to define a single setting for updating C/C++/Pascal/Delphi files in the PVCS version control tool.

    Programme Source

    Comments are to insert into the source code (in seperate lines), if parts of functions or algorithms are difficult to understand.

    Files

    All files contain a descriptive header (sample description in italics):

      //-------------------------------------------------------------------
      // PROJECT      project name/subsystem name/…
      // $Workfile$
      // $Revision$
      // PREFIX       prefix for public functions and variables
      // DESCRIPTION  description of the module implemented in this file.
      // CREATED      11-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
      // MODIFIED     20-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
      //                  Abstract of all changes, if they are made at
      //                  different places in the file
      //-------------------------------------------------------------------
      // $Log$
      //-------------------------------------------------------------------
      // TABSIZE      4
      // CHARSET      WINDOWS
      //-------------------------------------------------------------------

    Classes

    Class declarations contain the following header:

      //-------------------------------------------------------------------

      class CConfiguration : public CSuperclass

      // PATTERN      design pattern index and name
      // PREFIX       type prefix abbreviation (e.g. cnf)
      // DESCRIPTION  description of the class and its responsibilities
      // CREATED      11-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
      // MODIFIED     20-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
      //                  description of the changes
      {
          // declarations
      };

    Data Objects

    Constants, global variables and types are commented in the same line or with an indented comment in the following line. The comment describes the purpose of the declared object.

    Functions

    Function Declarations

    1. Function definitions are commented and formatted as follows:

      Example:

      Function Definitions

      The function definition's head list all changes of the function.

        //------------------------------------------------------------------

        int CClass::Function
            (void)
            // CREATED  18-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
            // MODIFIED 12-Dec-96, U.Sauerland - © ADVICE Softwarelösungen
            //              Description of the change

      Example:

        //------------------------------------------------------------------

        int CIntList::Maximium
            (void)
            const
            throw (xmsg)
            // CREATED  18-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
            // MODIFIED 20-Dec-95, U.Sauerland - © ADVICE Softwarelösungen
            //              Sign error within compare fixed
            //          17-Apr-96, U.Sauerland - © ADVICE Softwarelösungen
            //              BORLAND-iterator-bug workaround
        {
            REQUIRE(0 != Length());
                // The list is not empty..
            OLD(CIntListe);

            int nResult = -MAXINT;

            // Statements

            ENSURE(old.Laenge() == Laenge());
                // The function didn't change the list's length.
        }


    [back] | [next] | [TOC] | [Introduction] | [Layout] | [Programming Style Guide] | [Annexes]


    Copyright © 1997-98 by Uwe Sauerland