-
Notifications
You must be signed in to change notification settings - Fork 636
CodingStyle
Maxim Prokhorov edited this page Jun 18, 2020
·
3 revisions
- 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.
Current style does not always match what .clang-format
might generate.
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.
If you're looking for support:
- Issues: this is the most dynamic channel at the moment, you might find an answer to your question by searching open or closed issues.
- Wiki pages: might not be as up-to-date as we all would like (hey, you can also contribute in the documentation!).
- Gitter channel: you have better chances to get fast answers from project contributors or other ESPurna users. (also available with any Matrix client!)
- Issue a question: as a last resort, you can open new question issue on GitHub. Just remember: the more info you provide the more chances you'll have to get an accurate answer.
- Backup the stock firmware
- Flash a pre-built binary image
- Flash a virgin Itead Sonoff device without opening
- Flash TUYA-based device without opening
- Flash Shelly device without opening
- Using PlatformIO
- from Visual Studio Code
- Using Arduino IDE
- Build the Web Interface
- Over-the-air updates
- Two-step updates
- ESPurna OTA Manager
- NoFUSS
- Troubleshooting
- MQTT
- REST API
- Domoticz
- Home Assistant
- InfluxDB
- Prometheus metrics
- Thingspeak
- Alexa
- Google Home
- Architecture
- 3rd Party Plugins
- Coding style
- Pull Requests