Skip to content
Austen Adler edited this page Mar 22, 2015 · 8 revisions

Hitchhikers 2015 C++ Style Guide

Naming Conventions

Classes and functions are in start case:

DentMain
DentDrive
GetNumber()

Variables and classes are in camel case and should be descriptive unless the variable is iterative:

float potValue, currentSpeedValue //for private, public, or global variables
int i, j, k //for iterations

Multiple variables can be declared on the same statement:

int i,j,currentSpeedValue;

Variables should not contain underscores or be declared in a larger scope than necessary:

Good:

int robotDriveSpeed;
int robotDriveSpeed2,robotDriveSpeed3;

Bad:

int robot_drive_speed;
int robot_Drive_Speed_2;
int Robot_Drive_Speed_3;

Good:

for(int i=0;i<100;i++){
    //code
} //Never use variable i again

Bad:

int i;
for(i=0;i<100;i++){
    //code
} //Never use variable i again

Get and Set functions should be named conventionally and all functions can have default values:

Good:

bool GetDriveSpeed();
void SetDriveSpeed();
int CalculateAngle(int sensor=2);

Bad:

bool ReturnDriveSpeed();
void PutDriveSpeed();

Formatting

Formatting rules should be inherited from 1TBS

Brackets, curly braces, parentheses, variables, and functions should not contain extra padding

Two spaces used per indentation level

No space before, one space after the inheritance colon

One space after commas

All floating point numbers should be declared in decimal notation

Good:

float number = 0.3;
double anotherNumber = 5.0;

Bad:

float number = .3;
double anotherNumber = 5;

No trailing whitespace

Good:

bool testDrive, anotherBool;

for(int i = 0; i < 10; i++){
  statements;
}
bool notTrue = false;
if(notTrue){
  statement1;
}else{
  statement2;
}

class Autonomous: CommandGroup(){
}

Bad:

bool testDrive,anotherBool;

for ( int i=0 ;i<10 ;i++) {
  statements;
}
bool notTrue=false;
if ( notTrue == false ) 
{
  statement1;
} 
else 
{
  statement2;
}

class Autonomous : CommandGroup () {
}

Comments can be written in the document, but must be necessary. Comments can also be included as TODOs:

Good:

//currentAngle must be lower than 100
//TODO: Implement this
void shootRobot(int currentAngle);

Bad:

//Drives robot
//We should implement this
void driveRobot();

Vim marker comments can be included, but must contain the name of the function or have a short description of the function. The marker text should go before the marker:

Good:

//Declerations{{{
int testMode=0;
int otherMode=2;
}}}

//Drives Robot{{{
void driveRobot(){
  //Code
}
//}}}

//driveRobot{{{
void driveRobot(){
  //Code
}
//}}}

Bad:

//{{{Drives Robot
void driveRobot(){
  //Code
}
//}}}

//This function activates the driving capabilities of the robot by providing electricity to the motors causing a rotation of the wheels that propels the robot forward, backward, or in any other direction{{{
void driveRobot(){
  //Code
}
//}}}

Git

Git projects should follow the Git Flow model

Branches use lowercase letters separated by dashes

Feature, patch, or tag branches begin with feature/, patch/, or tag/

Good:

feature/auto-power

develop

master

tag/v1.0

Bad:

feature/NewBranch

new_branch

new-branch-feature