Coding Conventions
From WinBolo
Contents |
Comments
Method Header Comments
This should go above every method, both it's implementation (in .c files) and definition (in .h files).
/********************************************************* *NAME: <functionName> *AUTHOR: <functionAuthor> *CREATION DATE: <DD/MM/YY> *LAST MODIFIED: <DD/MM/YY> *PURPOSE: * Short description of function goes here * *ARGUMENTS: * firstParameter - Short explanation of what this parameter is * secondParameter - Short explanation of what this parameter is *********************************************************/
File Header Comments
Single Line Comments
As this code is trying to be 100% ANSI C compliant, you [b]must[/b] use a forward slash immediately followed by an asterisk to start the comment and then an asterisk and forward slash to close the comment.
/* This is a comment and will be ignored by the compiler */
Multiline Comments
When adding comments requiring more than one line, it's best to preceed each line with an asterisk for readability.
/* This will arrange it so that the growth from 0 -> 256 is * counter-clockwise just like radians. */
When commenting out a block of code, it's best to place the openning and closing comment marks at the start of the line. This will make it easier to find code which may need to be removed once it is verified to not be needed.
while (found == FALSE && NonEmpty(inc)) { count++; if (inc->x == x && inc->y == y) { found = TRUE; inc->life--; if (inc->life == BUILDING_DEATH) { /* returnValue = RUBBLE; */ buildingDeleteItem(bld, count); } } if (found == FALSE) { inc = BuildingTail(inc); } }
Variable Cases
Indentions
The original code of WinBolo was written using two spaces to preceed the actual start of the line of code. For each block of code (where a block is code within a set of curly braces), the indent is increased by two spaces.
Conditionals
Conditionals should follow the below syntax of having the openning curly brace on the same line as the conditional. The only brace that is on it's own line should one that ends the conditional.
if (srtDelay = 0) { srtDelay = 1; } else if (srtDelay = 1) { strDelay = 0; } else { srtDelay = -1 }
Switch statements should follow the syntax below.
switch (value) { case BsTrees: dest.left += (zoomFactor * BS_DOT_TREE_OFFSET_X); dest.top += (zoomFactor * BS_DOT_TREE_OFFSET_Y); break; case BsRoad: dest.left += (zoomFactor * BS_DOT_ROAD_OFFSET_X); dest.top += (zoomFactor * BS_DOT_ROAD_OFFSET_Y); break; case BsBuilding: dest.left += (zoomFactor * BS_DOT_BUILDING_OFFSET_X); dest.top += (zoomFactor * BS_DOT_BUILDING_OFFSET_Y); break; case BsPillbox: dest.left += (zoomFactor * BS_DOT_PILLBOX_OFFSET_X); dest.top+= (zoomFactor * BS_DOT_PILLBOX_OFFSET_Y); break; default: /* BsMine:*/ dest.left += (zoomFactor * BS_DOT_MINE_OFFSET_X); dest.top += (zoomFactor * BS_DOT_MINE_OFFSET_Y); break; }