Coding Conventions
Naming
Camel case is how we name variables, because it makes names easier to read. The first letter is lower case, and the first letter of every word after is uppercase.
- this is camelCase: myVariable
- this is not: MyVariable, MYvArIaBlE, myvariable, my_variable
Please do not create excessively long names, but also not too short to be vague.
- this is ok: timeSinceLastRun, rightMotor, chiliPineapplePizza
- this is not: time, timeSinceStartOfLastRun, motor, chiliPineapplePizzaWithExtraCheese
Enums all start with k, like kIntakeUp and kIntakeDown instead of intakeUp and intakeDown.
Class variables all start with a _, and are defined in the .h file. For example, _leftJoy and not leftJoy.
Constants: keep in all capital letters
- for example, INTAKE_MOTOR_PORT, not intakePort or intake_motor_port or intakemotorport
- constants should all be defined in the PORTS.h file.
Brackets and Indentation
An extra enter is not needed before the opening bracket, this just makes the code needlessly longer. Add another tab within every bracket (if adding an if statement in an if statement, the inside of the second if statement should have 2 tabs).
if (true) { //correct
//insert code here;
}
if (true) //wrong
{
//insert code here;
}
Miscellaneous
For loops: use i as the name of the counter variable, then j then k afterwards, etc.
Spacing: put spaces between operators
- Enter after each statement
- int a = 10; instead of int a=10;