From 424611c6016e4a189e3a887fabe8e45b637e80f4 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 15 Nov 2024 17:39:04 +0100 Subject: merge #36 --- contributing.md | 52 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/contributing.md b/contributing.md index 64afb44..5b0c79d 100644 --- a/contributing.md +++ b/contributing.md @@ -679,30 +679,57 @@ that you can click on to open them. ``` -
- Throw exceptions using standard C++ exceptions (such as std::runtime_error) + Utilize standard exceptions where appropriate (those found in <stdexcept>)
GoodBad
```cpp - if (error) { - throw std::runtime_error("An error occurred"); + #include + + // ... + + if (foo == nullptr) { + throw std::runtime_error("What is wrong"); } ``` ```cpp - if (error) { - throw "An error occurred"; + if (foo == nullptr) { + std::cout << "What is wrong" << std::endl; + exit(1); } ```
-
- Constructors of classes derived from Component should be protected and ComponentManager should be declared as a friend class. + Mention the name of the class when throwing an exception +
GoodBad
+ + ```cpp + Foo::bar() { + if (...) + throw std::runtime_error("Foo: big error!"); + } + ``` + + + ```cpp + Foo::bar() { + if (...) + throw std::runtime_error("big error!"); + } + ``` +
+-
+ 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; + MyComponent(...); + //! Only ComponentManager is allowed to create components friend class ComponentManager; }; ``` @@ -711,16 +738,20 @@ that you can click on to open them. ```cpp class MyComponent : public Component { public: - MyComponent() = default; + MyComponent(...); }; ```
-
- Use of format specifiers (like %s and %n) are not allowed (use {} with std::format instead) + C++ std::format should be used instead of C-style format specifiers
GoodBad
```cpp std::string message = std::format("Hello, {}", name); + + dbg_logf("Here too: {}", 3); + + throw std::runtime_error(std::format("Or here: {}", 5)); ``` @@ -730,7 +761,8 @@ that you can click on to open them. ```
-
- Argument names should be added in .h files (not only in .cpp and .hpp files) + Argument names should be added in .h files (not only in + .cpp and .hpp files)
GoodBad
Foo.h: -- cgit v1.2.3