diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 12:28:39 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-07 12:28:39 +0100 |
commit | ce8debc03d2ed291285535462cbf4411bf298278 (patch) | |
tree | 4327c52ffa8a1ac9b2f6e86a474f5ed2532a634a | |
parent | 89616381251ba892c36bced5f84e91ef8ad6efbe (diff) |
update contributing.md
-rw-r--r-- | contributing.md | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/contributing.md b/contributing.md index c7f836e..ba8ad68 100644 --- a/contributing.md +++ b/contributing.md @@ -78,8 +78,8 @@ that you can click on to open them. } ``` </td></tr></table></details> -- Header includes are split into paragraphs separated by a blank line. The - order is: +- Header includes (at the top of files) are split into paragraphs separated by + a blank line. The order is: 1. system headers (using `<`brackets`>`) 2. relative headers NOT in the same folder as the current file 3. relative headers in the same folder as the current file @@ -112,6 +112,52 @@ that you can click on to open them. ``` </td></tr></table></details> - <details><summary> + If there is one, the matching template header (<code>.hpp</code>) is included + at the bottom of the regular header (<code>.h</code>) + </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> + + Foo.h: + ```cpp + #pragma once + + template <typename T> + void foo(); + + #include "Foo.hpp" + ``` + + Foo.hpp: + ```cpp + #pragma once + #include "Foo.h" + + template <typename T> + void foo() { + // ... + } + ``` + </td><td> + + Foo.h: + ```cpp + #pragma once + + template <typename T> + void foo(); + ``` + + Foo.hpp: + ```cpp + #pragma once + #include "Foo.h" + + template <typename T> + void foo() { + // ... + } + ``` + </td></tr></table></details> +- <details><summary> <code>using namespace</code> may not be used in header files (.h, .hpp), only in source files (.cpp). </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> @@ -546,7 +592,7 @@ that you can click on to open them. </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> ```cpp - std::unique_ptr<Foo> foo = std::make_unique<Foo>(); + auto foo = std::make_unique<Foo>(); ``` </td><td> @@ -557,22 +603,23 @@ that you can click on to open them. ``` </td></tr></table></details> - <details><summary> - Do not use <code>malloc</code>, <code>calloc</code>, or <code>free</code> (instead use <code>new</code> and <code>delete</code>) + Do not use C-style memory management APIs (<code>malloc</code>, + <code>calloc</code>, <code>free</code>) </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> ```cpp - Foo* foo = new Foo(); + Foo * foo = new Foo(); delete foo; ``` </td><td> ```cpp - Foo* foo = (Foo*)malloc(sizeof(Foo)); + Foo * foo = (Foo *) malloc(sizeof(Foo)); free(foo); ``` </td></tr></table></details> - <details><summary> - Prefix member variables with <code>this-></code> + Prefix all class members with <code>this-></code> </summary><table><tr><th>Good</th><th>Bad</th></tr><tr><td> ```cpp @@ -583,8 +630,8 @@ that you can click on to open them. </td><td> ```cpp - void Foo::set_value(int value) { - value = value; + void Foo::set_value(int new_value) { + value = new_value; } ``` </td></tr></table></details> |