![]() | ![]() Main Index |
| MCA2 Programmer's Guide | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Fast Forward | Next | |
#defineSense() and Control()MCA is the product of many people. Because of this, you will find a lot of different coding styles in the various classes. However, this makes maintaining the framework more difficult and also hinders new users at learning how to use MCA properly. To improve this situation in the future, this chapter provides a coding standard that has been developed in order to have some uniformity in newly written MCA code. Unfortunately, much of the older parts have not been ported completely to this standard, so don't be surprised when you look into the source and find inconsistencies. In any case, you should try to follow the guidelines detailed below. In the long run, it makes life easier for all.
This sections describes how to name things in MCA2. A few general rules apply to all names:
Every name must be an english expression. Donīt use other languages or even mix them.
Don't abbreviate words. This is often unnecessary as most editors have the possibility of auto-appending possible endings and the code is less readable.
When creating a new module, group, part or plain class, choose a name that describes the function of this class well, rather than describing whether it is a module, group or part. Capitalize each word contained in the name and do not use special separating characters like underscores. Prepend a single lowercase letter to the name according to the class type:
Prepend a 'p' to all parts.
Prepend a 'g' to all groups.
Prepend a 'm' to all modules.
Prepend a 't' to all general classes that are no parts/groups/modules.
Prepend a 's' to all purely static classes (containing utility functions etc.).
Example 6-1. Some acceptable class names.
Parts: pTestInertialSystem, pHardwareAbstraction, pControlPanTiltUnit
Groups: gStereoVision, gControlLeg, gDetectHumans
Modules: mAddOne, mReflectSensorValues, mMotionFSM
General classes: tTopologicalMap, tGraphElement
Static classes: sVisionBlackboardUtils, sTextureUtils
It is recommended to use one of the supplied scripts to generate template class files (.C and .h files) for you with the correct first letter. The following scripts exist for this purpose in the /scripts subdir of MCA:
newPart
base_path
name: Creates a new part. The .C file is
created with the given name in the $MCAHOME/base_path/src
subdirectory. A 'p' is automatically prepended. No header file is
generated.
newGroup base_path
name: Creates a new group. Parameters are
evalulated like in the newPart script. A 'g' is automatically
prepended to the given name. Additional to the .C file, a header file
is created in $MCAHOME/base_path/include.
newModule
base_path
name: Creates a new module. A 'm' is
automatically prepended to the given name. Both .C and .h files are
created.
newClass
base_path name: Creates a new class. A 't' is
automatically prepended to the given name. Both .C and .h files are
created.
newStaticClass
base_path
name: Creates a new static class. A 's' is
automatically prepended to the given name. Both .C and .h files are
created.
When you do not use the provided scripts and want to create new class files on your own, create two files for each class: A source and a header file. For parts, the header file is optional.
Avoid declaring more than one class in the same file. Sole exceptions of this rule should be nested classes and container classes exclusively used by the companion class.
Name all files exactly like the class they contain, including the leading p,g,m,t or s.
Variables may consist of phrases, but never contain capitals. Words are separated by underscores.
In function names, words are separated using capitals without underscores. Even the first letter must be a capital. The parameters of a function and of course the internal variables must conform to the coding standards for variables.
Type names are just like funktion names but contain a leading small t.
Constants start with a lowercase c, enumerations with a lowercase e. The constant or enumeration name itself can be formatted in two ways:
Completely capitalized and separated by underscores.
Like a function name, each word starting with a capitalized letter and not separated by underscores.
Example 6-5. Defining constants and enumerations
const int cCONSTANT_INT;
const float cPredefinedFloat;
enum tParameterType {ePT_BOOL,ePT_INT,ePT_FLOAT,ePT_SRING};
enum tExceptionType
{
eET_ParameterChanged,
eET_PrepareForFirstSense,
eET_PrepareForFirstControl,
eET_PrepareForBreak,
eET_PrepareForRestart,
};
enum {eERROR,eSTART,eSTOP}; |