Skip to content

Team Style Guide

Noxilus edited this page May 15, 2018 · 3 revisions

Code Style

Naming Conventions

Variables

  • All variables are to be camel case - start with lowercase, then capitalize the first letter of each word.

    • Example: int camelCase;
  • All enumerated values are to be pascal case - the first letter of every word is capitalized.

    • Example: fieldPos = Center;
  • Words in variable names may be abbreviated unless it causes conflict with understanding its purpose.

    • Acceptable: Spark left1 (Given that there is no other first left spark on the robot)

    • Acceptable: Spark l1 (Using L and R for left and right is an acceptable abbreviation)

    • Acceptable: FieldPosition fieldPos (Pos is a good abbreviation for position)

    • Unacceptable: FieldPosition fPos (When the variable is by itself, it is unclear what 'f' stands for)

  • Booleans are not to be named "is..."

    • Acceptable: bool leftSwitch

    • Unacceptable: bool isSwitchLeft

Structures and Objects

  • All structures and objects are to be named in pascal case.

    • Example: class Robot

    • Example: enum FieldPosition

Functions

  • Functions are to be named in pascal case.

    • Example: void TankDrive();

Syntax and Spacing

Braces

  • Open curly braces are to be inline and one space away from the end.

  • Close curly braces are to be on a new line.

    • Example:
void TankDrive() {
// Some stuff here
}

Operators

  • There is to be a space surrounding every operator.

    • Acceptable: someVar == someVal

    • Acceptable: someVar = 1;

    • Unacceptable: someVar=1;

Conditionals

  • There is to be a space between if (or else if) and its condition.

    • Acceptable: if (someCondition) {

    • Unacceptable: if(someCondition) {

  • else and else if are to be on the subsequent line below the closing brace of the preceding statement.

    • Example:
if (someVal == 1) {
// Some stuff here
}
else if (someVal == 2) {
// Some different stuff here
} 
else {
// Some completely different stuff here
}

Constants

  • All constants are to be declared and defined in the source file.

  • All constants are to be declared and defined in the same line.

  • All constants are to be grouped as follows:

    • All representing different ports of the same type are to be on subsequent lines in numerical order.

    • There is to be one empty line to separate different port types.

    • Port types are to be declared in alphabetical order.

  • Example:

const int pwm0 = 0;
const int pwm1 = 1;
const int pwm2 = 2;

const int usb0 = 0;
const int usb1 = 1;

Comments

Single Line

  • To be used as explanations or labels for existing code.

  • As an explanation:

    • The comment is to be inline.

    • The comment is to be one space away from the end of the code in that line.

    • Example: void Robot::TeleopInit() { // Runs at start of teleoperated phase, only once

  • As a label:

    • The comment is to be on the line directly above the code it labels.

    • The comment is to have one empty line above it.

    • Example:

// Values and Structures
	bool leftswitch;
	bool leftscale;

Commit Style

  • All messages are to be in the past tense.

    • Example: Added some stuff

Style Guide Style

  • Nah