CodingStyle - xoseperez/espurna GitHub Wiki
Coding style
- Current style follows closely (but not fully) the WebKitCode Style Guidelines
- This project uses 4 space indentation, not tabs.
- Function definitions and
if
/for
/while
starting bracket is in the same line:
int _domoticzRelay(unsigned int idx) {
[...]
}
- One-line control clauses should use braces:
do {
if (something) {
break;
}
[...]
} while (blah);
if (...) return;
can sometimes be an exception, where it is the only expression.
- Class names are UpperCamelCased
class DigitalSensor : public BaseSensor {
[...]
}
- Method names are lowerCamelCased:
int buttonFromRelay(unsigned int relay_id) {
[...]
}
- Constants (Enumerations,
const
,constexpr const
) should be UpperCamelCased:
constexpr const size_t ValuesMax = 5;
enum class Colors {
Red,
Green,
Blue
};
- Variables should be underscored_lower_case (I know, I don't always follow this rule myself - in many cases they are also lowerCamelCased):
// Preferred:
bool delete_flag = false;
// Less preferred:
unsigned long rfCodeON = 0;
- Private methods and variables (even if private to the module they are declared on) are prefixed with an underscore (
_
):
bool _dcz_enabled = false;
int _domoticzRelay(unsigned int idx) {
[...]
}
- Prefer
static_cast<T>(...)
andreinterpret_cast<T>(...)
over C-style casts. - When creating a new subclass of a class that contains virtual methods (like
BaseSensor
,BasePin
etc.), it should specifyoverride
keyword when overriding virtual methods.
TODO: clang-format
Current style does not always match what .clang-format
might generate.
Linting
Code is checked using cppcheck.
I know current code does not always follow these rules. I'm fixing it as I rework each of the modules.