From 8ff89409c7ee5399d98fe4a8e2a67961fab8add1 Mon Sep 17 00:00:00 2001 From: max-001 Date: Fri, 15 Nov 2024 17:24:03 +0100 Subject: Added code style --- contributing.md | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/contributing.md b/contributing.md index 3090727..64afb44 100644 --- a/contributing.md +++ b/contributing.md @@ -678,6 +678,86 @@ that you can click on to open them. uint64_t foo(); ``` +-
+ Throw exceptions using standard C++ exceptions (such as std::runtime_error) +
GoodBad
+ + ```cpp + if (error) { + throw std::runtime_error("An error occurred"); + } + ``` + + + ```cpp + if (error) { + throw "An error occurred"; + } + ``` +
+-
+ Constructors of classes derived from Component should be protected and ComponentManager should be declared as a friend class. +
GoodBad
+ + ```cpp + class MyComponent : public Component { + protected: + MyComponent() = default; + friend class ComponentManager; + }; + ``` + + + ```cpp + class MyComponent : public Component { + public: + MyComponent() = default; + }; + ``` +
+-
+ Use of format specifiers (like %s and %n) are not allowed (use {} with std::format instead) +
GoodBad
+ + ```cpp + std::string message = std::format("Hello, {}", name); + ``` + + + ```cpp + char message[50]; + sprintf(message, "Hello, %s", name); + ``` +
+-
+ Argument names should be added in .h files (not only in .cpp and .hpp files) +
GoodBad
+ + Foo.h: + ```cpp + void foo(int bar); + ``` + + Foo.cpp: + ```cpp + void foo(int bar) { + // ... + } + ``` + + + Foo.h: + ```cpp + void foo(int); + ``` + + Foo.cpp: + ```cpp + void foo(int bar) { + // ... + } + ``` +
## CMakeLists-specific -- cgit v1.2.3