...
Code Block | ||||
---|---|---|---|---|
| ||||
enum class Color { red, blue }; //NOT enum Color { red, blue }; |
using, not typedef
Use the using type alias rather than typedef:
Code Block | ||
---|---|---|
| ||
using distance_t = double; // define distance_t as an alias for type double
//NOT
typedef double distance_t; // define distance_t as an alias for type double |
const, not define
Avoid using #define to create symbolic constants macros.
Code Block | ||
---|---|---|
| ||
const double GRAVITY{ 9.8 }; // preferred use of const before type |
Naming conventions
Variables are camelCase.
Methods are camelCase.
Classes are PascalCase.
Static constants are UPPER_SNAKE_CASE.
Code Block | ||||
---|---|---|---|---|
| ||||
class EncodedPacket {
public:
EncodedPacket(uint8_t *data, uint8_t len);
const uint8_t *getData() const;
uint8_t getLen() const;
DecodedPacket *decode();
private:
const uint8_t * const data;
const uint8_t len;
Static const
void print(){
std::cout << "This is a function!";
}
}; |