WCS: Coding Standards

This page contains a collection of hints, tips and agreed methods for writing code for the WCS-project. This information will help other project members to understand the code that one writes more easily. If possible, please use these rules. If you have suggestions for changes or additions then please let me know.

File and program structure

Per class 2 files should be created: A *.h file will contain the class-definition and all one-line functions. A companioning *.cpp file will contain the definitions of the larger member-functions.

Include files can be made, but must be documented carefully. The file "global.h" contains definitions that are commonly used throughout the program. The file "platform.h" contains macro's that have platform dependent elements in them. These macro's must be written in such a manner, using conditional parts, that the program will compile on any platform that supports GCC. These include Linux, DOS, Windows and Mac.

Naming constants and variables

Constants should be named using all UPPERCASE characters. Variables should be named using lowercase characters. Names may use the underscore ('_') character (example: "map_editor" and "VIDEO_MODE").

Naming classes

Names of classes should be all UPPERCASE. Classes that will be used a lot should also be short-named when possible (examples: POINT, BOB). Classes that are only intended as wrapper classes may (or should) have a longer name to prevent regulat use (example: ALLEGRO_BITMAP should never be used by developer directly).

Naming functions and class-members

functions and class-members should be named using all lowercase characters. Also the underscore ('_') character may be used.

Class structure

A class should have the following structure:

class NAME : public BASECLASS {

Function & member structure

The functions and class-members should have the following structure:
type name(parameterlist) { function body }.

A functions body should not exceed a maximum of 40 lines. If a function (in printed form) doesn't fit om one sheet of paper then this may be an indication that the function is to long. In case of doubt please ask another team-member to inspect the code for you.