About: Coding Rules |
Required Rules |
01 |
GeneralThere are many coding rules, and nearly all of them share some common things that can be summarized with the term 'common sense' nowadays.This common sense includes naming the things about what they do/are, writing functions of less than about two to three monitor pages (Yes, depends on resolution and font size...) and the like. | Look at existing code to copy its format. |
02 |
There are more rules than written here that I follow - those listed here are the most important ones. |
03 |
Jump Statements
| Any construct can be written under these rules. Look at the code if in doubt. |
04 |
Names
|
05 |
Context of variablesVariables should be declared as local as possible. Exceptions can be with often used counter variables or performance considerations (constructor/destructor). |
06 |
Global variablesThere shall be as few global variables as possible. While C code often needs them, code of object oriented languages should at least use static member variables. |
07 |
MarkerBlocks that require some attention (unfinished, bug, problem, ...) are to be marked by five (5) exclamation marks at the beginning of a comment and a further descriptive text. | Personally I don't like these TODO or BUG or whatever words. |
08 |
Function separatorFunctions shall be preceeded by one comment line, ending at column 78:C:
Others:
|
09 |
Class/Section separatorClasses and sections should be preceeded by one comment block, ending at column 78:C:
Others:
| Their use is not enforced for /every/ place. |
10 |
General Format
|
11 |
Constant NULL (C/C++)The constant 0 shall be used for a reset pointer value. | Awkward at first, I now like it to do it that way. (And even 4 keystrokes less ;) |
|
Recommended Rules |
12 |
Tabulator widthGenerally there should be no assumption on the configured tabulator width. (This has already been bent by the function separator line).Semys was and is written using a tabulator width of 2. |
13 |
Names of container classes
|
14 |
Use of defines (C/C++)Generally, there should be as few defined constants as possible. For integers, use enums; Strings should be stored as static members.Reason: Defines are often overused - Java and C# hardly even have them anymore. |
15 |
Length of source linesA new line should be used after reaching the area between columns 80 - 110.The current statement should be continued in the next line with one more indentation level. Reason: vertical scrolling reveals much more information at once than horizontal. |
16 |
C Boolean typeint32 or int shall be used for boolean (true(!0), false(0) ) variables.Reason: C has no standard boolean type, and before any different type is encountered, one is defined. |
Examples |
17 |
|
Goto: Main Page; This page is part of the Semys software documentation. See About: Documentation for details. |