[HelpOnLanguages] [TitleIndex] [WordIndex]


1. OMG Coding Standards

These standards should be followed by all OMG developers.

1.1. Classes

1.1.1. Names

Class in OMG begin with Omg and are formed using mixed case.


The rationale for using the Omg prefix is explained on the Trolltech Qt Naming Page.

1.1.2. Members

Class member names begin with a lower case m and are formed using mixed case.


In the case where a class member is a pointer, use the letter p to indicate as much:


All class members should be private. Public class members are STRONGLY discouraged

1.1.3. Function parameters

Prefix all function parameters with 'the' (or 'thep' in the case of pointers)I have only ever seen this suggested in one C++ book, but I really like thes naming scheme:

  bool Foo::Bar(Dog theDog, Cat * thepCat)


1.1.4. Local Variables

As above but use 'my' prefix:

  bool Foo::Bar()
    Bunny myBunny;
    Horse * mypHorse

1.1.5. Accessor and Mutator Functions

Class member values should be obtained through accesssor functions. The function should be named without a get prefix. Accessor functions for the two private members above would be:


Mutator functions should follow the same convention but must be prefixed by the word set. For example:


1.1.6. Functions

Function names begin with a lowercase letter and are formed using mixed case. The function name should convey something about the purpose of the function (usually in the form of a verb).


1.2. Qt Designer

1.2.1. Generated Classes

Classes that are generated from Qt Designer (ui) files should have a Base suffix. This identifies the class as a generated base class.


1.2.2. Dialogs

All dialogs should implement the following:

1.3. C++ Files

1.3.1. Names

One class (or struct) per file. A struct may well be upgraded to a class at some point in future so treat it like a class! C++ implementation and header files should be have a .cpp and .h extension respectively. Filename should be all lowercase and, in the case of classes, match the class name.

        Class OmgDataset source files are 
                omgdataset.cpp and omgdataset.h

1.3.2. Standard Header and License

Each source file should contain a header section patterned after the following example:

    omgfield.cpp - Describes a field in a layer or table
    Date                 : 01-Jan-2004
    Copyright            : (C) 2004 by Tim Sutton
    Email                : t.sutton at reading.ac.uk
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *

1.3.3. CVS Keyword

Each source file should contain the $Id$ keyword. This will be expanded by CVS to contain useful information about the file, revision, last committer, and date/time of last checkin.

Place the keyword right after the standard header/license that is found at the top of each source file:

        /* $Id$ */

1.4. Variable Names

Variables declared within a method should be prefixed with 'my' - this provides a clear indication of the variable's scope. Variable names begin with a lower case letter and are formed using mixed case. Parameters passed to methods should be prefixed by 'the'. As mentioned above, class members should be prefixed by 'm'.

Fictitious Examples:

class OmgDataset 
  int numberOfLayers();
  void setNumberOfLayers(int theNumberOfLayers);
  int mNumberOfLayers;

OmgDataset::setNumberOfLayers(int theNumberOfLayers)
  int myTotalCount = 100;
  if (myTotalCount < theNumberOfLayers)
     mNumberOfLayers = theNumberOfLayers;

In all cases variable names should be descriptive rather than terse.

     n = 60; // <-- bad
     numberOfReplicates = 60; // <--good

1.5. Editing

Any text editor/IDE can be used to edit OMG code, providing the following requirements are met.

1.5.1. Tabs

Set your editor to emulate tabs with spaces. Tab spacing should be set to 2 spaces.

1.5.2. Indentation

Source code should be indented to improve readability. There is a .indent.pro file in the OMG (TODO add this file) src directory that contains the switches to be used when indenting code using the GNU indent program. If you doin't use GNU indent, you should emulate these settings.

1.5.3. Braces

Braces should start on the line following the expression:

        if(foo == 1)
          // do stuff
          // do something else

2014-08-13 10:44