From 098ae26d16188b276af77b8bfe9975fcabe8d7f4 Mon Sep 17 00:00:00 2001 From: max-001 Date: Thu, 7 Nov 2024 10:10:07 +0100 Subject: Added code styles --- contributing.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/contributing.md b/contributing.md index cd1b6a6..c7f836e 100644 --- a/contributing.md +++ b/contributing.md @@ -541,6 +541,53 @@ that you can click on to open them. #include ``` +-
+ Ensure exception safety by using RAII classes +
GoodBad
+ + ```cpp + std::unique_ptr foo = std::make_unique(); + ``` + + + ```cpp + Foo* foo = new Foo(); + // ... + delete foo; + ``` +
+-
+ Do not use malloc, calloc, or free (instead use new and delete) +
GoodBad
+ + ```cpp + Foo* foo = new Foo(); + delete foo; + ``` + + + ```cpp + Foo* foo = (Foo*)malloc(sizeof(Foo)); + free(foo); + ``` +
+-
+ Prefix member variables with this-> +
GoodBad
+ + ```cpp + void Foo::set_value(int value) { + this->value = value; + } + ``` + + + ```cpp + void Foo::set_value(int value) { + value = value; + } + ``` +
## CMakeLists-specific -- cgit v1.2.3