C++
The provided C++ coding standards outline conventions for naming variables, structs, classes, constants, and formatting if and else statements. Let's elaborate on each of these standards:
- CamelCase for variables, structs, and classes. CamelCase means that each word in the name starts with an uppercase letter, without any spaces or underscores between words. For example, a struct could be named "BobBox".
- Variables should start with a lowercase. Variable names should begin with a lowercase letter. For example, a variable could be named "lockerPin".
- Constants should be uppercase with underscores. Constants, which are typically used for values that should not be modified, are named using uppercase letters and underscores between words. For instance, a constant representing the baud rate could be named "BAUD_RATE".
- Subsequent capital letters in a word should be lowercase. When naming variables, structs, or classes, subsequent capital letters within a word should be lowercase. This convention is often referred to as "lowerCamelCase". For example, a variable representing a locker ID could be named "lockerId".
- Braces should always be used with if statements. Use braces with if statements, even if the block of code within the if statement contains only a single line. The recommended format would be:
if (true) {
// do something
}
- Else statements should be inline. Else statements should be placed inline with the closing brace of the if statement. For example:
if (true) {
// do something
} else {
// do something else
}
-
Use full and descriptive names. Use full and descriptive names for variables, functions, and other entities in the code. For example, using "sendMessage" instead of abbreviations like "sendMesg" would make the code more understandable.
-
Limit TODOs in code. While "TODO" comments are often used to indicate areas of code that need attention or further development, excessive usage can clutter the codebase. It's recommended to use "TODO" comments sparingly and prioritize resolving them.