From 87ac25c1a1eec3cd0a6e8e7123e76b3e8caccdf5 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 13 Feb 2021 12:53:48 +0000 Subject: [PATCH] Update contributing guidelines for new changes --- CONTRIBUTING.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54e9f7dd..9e611f8b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -182,12 +182,28 @@ We generally support the usage of functional programming and lambda, usage of it ### References For passing any parameter which isn't a primitive prefer to use references/const references to pass them into functions or other places as a copy can be avoided that way. -In addition, always use a const reference rather than a normal reference unless the argument needs to be modified in-place as the compiler knows the intent far better in that case. +In addition, always use a const reference rather than a normal reference unless the argument needs to be modified in-place as the compiler knows the intent far better in that case. +Note: In constructors if you are copying to a member variable `std::move` is preferred as it allows copy-elision in some circumstances. ```cpp void DoSomething(const Class& class, u32 primitive); -void ClassConstructor(const Class& class) : class(class) {} // Make a copy directly from a `const reference` for class member initialization +void ClassConstructor(Class class) : class(std::move(class)) {} // Make a copy directly from a `const reference` for class member initialization ``` +### Member Variable Shadowing +Shadowing of class member variables should be avoided aside from in constructors when they are exclusively used in the initialisation list. +To avoid shadowing a prefix of p (parameter) or l (local) should be added to the offending variable: + +* Correct +```cpp +ClassA(ClassB pClassB) : classB(std::move(pClassB)) { + classB->Initialise(); +} +``` + +* Incorrect +```c++ +ClassA(ClassB pClassB) : classB(std::move(pClassB)) {} +``` ### Range-based Iterators Use C++ range-based iterators for any C++ container iteration unless it can be performed better with functional programming (After C++20 when they are merged with the container). In addition, stick to using references/const references using them