Style guide should be followed for all C++ code developed for WARG.
Functions
Naming and Brackets
Functions should use lower camel case in their names. There should be no spaces between the function name and the parameter list. The open curly-bracket must be on the same line as the function name, and must be separated from the parameter list by one space:
int hewwoThereFwend() { return 0; }
Parameters
Pointers
The *
in pointers must be separated on both sides by one space.
void hewwoThereFwend(string * fwendName) { ... }
NOTE: Moving forward, we will prefer to use reference parameters over pointers when passing by reference. It is a more C++ style of programming.
Reference Parameters
The &
in reference parameters must be appended to the datatype of the parameter.
void hewwoThereFwend(string& fwendName) { ... }
We will prefer to use this C++ feature when passing values by reference from now on. To learn more about reference parameters, you can refer to the following links:
http://www.fredosaurus.com/notes-cpp/functions/refparams.html
https://stackoverflow.com/questions/2564873/how-do-i-use-reference-parameters-in-c (first answer)
More than one Parameter
Parameters in a list must be separated by commas (obviously lol), but a space must separate a comma and a parameter:
void hewwoThereFwend(string& fwendName, string fwendTwoName) { ... }
If the parameter list is very long, creating a vertical list of parameters is acceptable too:
void hewwoThereFwend(string fwendOne, string fwendOne, string fwendOne, string fwendOne, )
Mathematics
Mathematical Operations
There should always be spaces around all mathematical operators. There should always be spaces between equal signs.
int b = (1 + 2 - 3) * 4/5.0 + 6 % 7;
Add Comment