From e968900754d8b84291f38afea1d362cf4a96e2ad Mon Sep 17 00:00:00 2001 From: "Nicholas \"LB\" Braden" Date: Sun, 21 Apr 2013 15:29:56 -0500 Subject: [PATCH 1/3] Add specifics to styleguide --- src/README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/README.md b/src/README.md index b227fd7..dfd1abe 100644 --- a/src/README.md +++ b/src/README.md @@ -1,5 +1,7 @@ Style Guide & Coding Conventions ================================ + +## General - Indentation is to be consistently four spaces, not tabs or a mixture of spaces and tabs. - All files are to have a single blank line at their end, if possible. - Prefer C++11 features to C++03 features when possible, and avoid deprecated language features. @@ -24,6 +26,46 @@ Style Guide & Coding Conventions - Use nameless scopes in functions to emphasize the lifetime of RAII objects - Place source file helper functions/classes in anonymous namespaces AND declare them static, so as to avoid name/symbol conflicts across irrelevant source files - Keep clear the separation between client and server behaviors and responsibilities -- Prefer defining one-line accessor functions that don't cause coupling inside the header file. +- Prefer inlining functions, ctors, and dtors, so long as they do not increase header file coupling. +- Try to make as many functions `noexcept` as possible, or at least use the conditional `noexcept` syntax. +- If a function is known for throwing exceptions, write `noexcept(false)` as a visual indicator. +- Try to avoid excess or repetitive "access:" specifiers. +- Avoid strange spaces before open parens and open braces and in other places unless you are lining up code with other code for readability and emphasis of relation. + +## Specifics +One-liners should be **one line**, otherwise they should be in braces: +```cpp +if(condition) one(liner); +//or +if(condition) +{ + really(long(one, liner)); +} +``` + +Constructor initializer lists should have each element on their own line and have the same indentation level as the opening brace of the ctor: +```cpp + OurClass() + : first(element) + , second(element) + , nth(element) + { + //... + } +``` + +The `const` keyword is to appear on the right side of types, to be consisten with other uses of the `const` keyword: +```cpp +char const*identifier; +``` +It should also snuggle next to * and & + +\* and & should sunggle next to identifiers: +```cpp +void func(ns::ClassName *classname, ns::OtherClass const&otherclass) const +{ + //... +} +``` To suggest changes to this guide, fork the project, make amendments, submit the pull request, and partake in discussion of the changes. From c220abd9cfbd1e297127294113359b870f0a870e Mon Sep 17 00:00:00 2001 From: "Nicholas \"LB\" Braden" Date: Mon, 22 Apr 2013 11:12:28 -0500 Subject: [PATCH 2/3] Chang snuggling rules --- src/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/README.md b/src/README.md index dfd1abe..cc92e19 100644 --- a/src/README.md +++ b/src/README.md @@ -56,13 +56,13 @@ Constructor initializer lists should have each element on their own line and hav The `const` keyword is to appear on the right side of types, to be consisten with other uses of the `const` keyword: ```cpp -char const*identifier; +char const *identifier; ``` -It should also snuggle next to * and & +It should also _not_ snuggle next to * and & \* and & should sunggle next to identifiers: ```cpp -void func(ns::ClassName *classname, ns::OtherClass const&otherclass) const +void func(ns::ClassName *classname, ns::OtherClass const &otherclass) const { //... } From d1dc8690432be01f49da669b8eca225deac9ca8e Mon Sep 17 00:00:00 2001 From: "Nicholas \"LB\" Braden" Date: Mon, 22 Apr 2013 14:45:50 -0500 Subject: [PATCH 3/3] Line limit expectations --- src/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/README.md b/src/README.md index cc92e19..88646c4 100644 --- a/src/README.md +++ b/src/README.md @@ -31,6 +31,7 @@ Style Guide & Coding Conventions - If a function is known for throwing exceptions, write `noexcept(false)` as a visual indicator. - Try to avoid excess or repetitive "access:" specifiers. - Avoid strange spaces before open parens and open braces and in other places unless you are lining up code with other code for readability and emphasis of relation. +- There is no line character limit, but that is because you shouldn't have exceedingly long lines (unless they just have exceedingly long identifiers). Instead, avoid deeply nested compound expressions - they reduce readability and hinder understanding of what code is for and/or doing. ## Specifics One-liners should be **one line**, otherwise they should be in braces: