From 20d4d711f8d300682d560548ec1a5501ce7b9978 Mon Sep 17 00:00:00 2001 From: max-001 Date: Wed, 6 Nov 2024 16:31:16 +0100 Subject: Added extra code-style guidelines --- contributing.md | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/contributing.md b/contributing.md index 88cba32..91cd12b 100644 --- a/contributing.md +++ b/contributing.md @@ -421,6 +421,118 @@ that you can click on to open them. void bar(Point p); ``` +-
+ Follow the rule-of-five +
GoodBad
+ + ```cpp + class Foo { + public: + Foo(); + ~Foo(); + Foo(const Foo &); + Foo(Foo &&) noexcept; + Foo & operator=(const Foo &); + Foo & operator=(Foo &&) noexcept; + }; + ``` + + + ```cpp + class Foo { + public: + Foo(); + ~Foo(); + Foo(const Foo &); + }; + ``` +
+-
+ Ensure const-correctness +
GoodBad
+ + ```cpp + class Foo { + public: + int get_value() const; + void set_value(int new_value); + const std::string & get_name() const; + void set_name(const std::string & new_name); + private: + int value; + std::string name; + }; + ``` + + + ```cpp + class Foo { + public: + int get_value(); + void set_value(int new_value); + std::string get_name(); + void set_name(std::string new_name); + private: + int value; + std::string name; + }; + ``` +
+-
+ File names (.h/.cpp/.hpp) should be written using CamelCase +
GoodBad
+ + ```cpp + MyClass.h + MyClass.cpp + MyClass.hpp + ``` + + + ```cpp + my_class.h + my_class.cpp + my_class.hpp + ``` +
+-
+ Implementation is not allowed in header files, except if the method only returns a constant value +
GoodBad
+ + ```cpp + class Foo { + public: + int get_value() const { return 42; } + }; + ``` + + + ```cpp + class Foo { + public: + int calculate_value() const { + int result = 0; + // complex calculation + return result; + } + }; + ``` +
+-
+ Use angle brackets (`<>`) for including libraries and double quotes (`""`) for including local files. +
GoodBad
+ + ```cpp + #include + #include "MyClass.h" + ``` + + + ```cpp + #include "iostream" + #include + ``` +
## CMakeLists-specific -- cgit v1.2.3