diff --git a/00-Table_of_Contents.md b/00-Table_of_Contents.md index 67008eb..7f2b1a3 100644 --- a/00-Table_of_Contents.md +++ b/00-Table_of_Contents.md @@ -11,5 +11,3 @@ 10. [Enable Scripting](10-Enable_Scripting.md) 11. [Further Reading](11-Further_Reading.md) 12. [Final Thoughts](12-Final_Thoughts.md) - - diff --git a/02-Use_the_Tools_Available.md b/02-Use_the_Tools_Available.md index 25b59a0..2b6f441 100644 --- a/02-Use_the_Tools_Available.md +++ b/02-Use_the_Tools_Available.md @@ -33,7 +33,7 @@ Use an industry standard widely accepted build tool. This prevents you from rein * [maiken](https://github.com/Dekken/maiken) - Crossplatform build tool with Maven-esque configuration style. * [Qt Build Suite](http://doc.qt.io/qbs/) - Crossplatform build tool From Qt. * [meson](http://mesonbuild.com/index.html) - Open source build system meant to be both extremely fast, and, even more importantly, as user friendly as possible. - * [premake](https://premake.github.io/) + * [premake](https://premake.github.io/) * [xmake](https://xmake.io) - A cross-platform build utility based on Lua. Modern C/C++ build tools, Support multi-language hybrid compilation * [build2](https://build2.org) - A cargo-like complete toolchain (build system, package manager, project manager) @@ -410,6 +410,6 @@ Don't forget to make sure that your error handling is being tested and works pro [pahole](https://linux.die.net/man/1/pahole) generates data on holes in the packing of data structures and classes in compiled code. It can also the size of structures and how they fit within the system's cache lines. -### BinSkim +### BinSkim -[BinSkim](https://github.com/Microsoft/binskim) is a binary static analysis tool that provides security and correctness results for Windows Portable Executable and *nix ELF binary formats +[BinSkim](https://github.com/Microsoft/binskim) is a binary static analysis tool that provides security and correctness results for Windows Portable Executable and *nix ELF binary formats diff --git a/03-Style.md b/03-Style.md index 241f5c7..db2c7f6 100644 --- a/03-Style.md +++ b/03-Style.md @@ -240,7 +240,7 @@ It also makes it possible to have two separate files next to each other on one s ``` ## Initialize Member Variables -...with the member initializer list. +...with the member initializer list. For POD types, the performance of an initializer list is the same as manual initialization, but for other types there is a clear performance gain, see below. @@ -288,8 +288,8 @@ private: }; // Good Idea -// The default constructor for m_myOtherClass is never called here, so -// there is a performance gain if MyOtherClass is not is_trivially_default_constructible. +// The default constructor for m_myOtherClass is never called here, so +// there is a performance gain if MyOtherClass is not is_trivially_default_constructible. class MyClass { public: @@ -454,4 +454,3 @@ The Rule of Zero states that you do not provide any of the functions that the co The goal is to let the compiler provide optimal versions that are automatically maintained when more member variables are added. [This article](http://www.nirfriedman.com/2015/06/27/cpp-rule-of-zero/) provides a background and explains techniques for implementing nearly 100% of the time. - diff --git a/04-Considering_Safety.md b/04-Considering_Safety.md index 5df8298..0592ff9 100644 --- a/04-Considering_Safety.md +++ b/04-Considering_Safety.md @@ -34,9 +34,9 @@ public: * Always return by value. -references: https://github.com/lefticus/cppbestpractices/issues/21 https://twitter.com/lefticus/status/635943577328095232 +references: https://github.com/lefticus/cppbestpractices/issues/21 https://twitter.com/lefticus/status/635943577328095232 -### Do not pass and return simple types by const ref +### Do not pass and return simple types by const ref ```cpp // Very Bad Idea @@ -47,7 +47,7 @@ public: : m_int_value(t_int_value) { } - + const int& get_int_value() const { return m_int_value; @@ -69,7 +69,7 @@ public: : m_int_value(t_int_value) { } - + int get_int_value() const { return m_int_value; @@ -101,7 +101,7 @@ auto mybuffer = std::make_unique(length); // C++14 auto mybuffer = std::unique_ptr(new char[length]); // C++11 // or for reference counted objects -auto myobj = std::make_shared(); +auto myobj = std::make_shared(); // ... // myobj is automatically freed for you whenever it is no longer used. @@ -111,7 +111,7 @@ auto myobj = std::make_shared(); Both of these guarantee contiguous memory layout of objects and can (and should) completely replace your usage of C-style arrays for many of the reasons listed for not using bare pointers. -Also, [avoid](http://stackoverflow.com/questions/3266443/can-you-use-a-shared-ptr-for-raii-of-c-style-arrays) using `std::shared_ptr` to hold an array. +Also, [avoid](http://stackoverflow.com/questions/3266443/can-you-use-a-shared-ptr-for-raii-of-c-style-arrays) using `std::shared_ptr` to hold an array. ## Use Exceptions diff --git a/05-Considering_Maintainability.md b/05-Considering_Maintainability.md index 4547559..2c9a250 100644 --- a/05-Considering_Maintainability.md +++ b/05-Considering_Maintainability.md @@ -33,7 +33,7 @@ Know and understand the existing C++ standard algorithms and put them to use. * See [cppreference](https://en.cppreference.com/w/cpp/algorithm) * Watch [C++ Seasoning](https://www.youtube.com/watch?v=qH6sSOr-yk8) - + Consider a call to `[]` as a potential code smell, indicating that an algorithm was not used where it could have been. diff --git a/08-Considering_Performance.md b/08-Considering_Performance.md index 9318611..467be02 100644 --- a/08-Considering_Performance.md +++ b/08-Considering_Performance.md @@ -43,7 +43,7 @@ For more examples see [this article](http://blog2.emptycrate.com/content/templat ### Avoid Recursive Template Instantiations -Recursive template instantiations can result in a significant load on the compiler and more difficult to understand code. +Recursive template instantiations can result in a significant load on the compiler and more difficult to understand code. [Consider using variadic expansions and folds when possible instead.](http://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html) @@ -294,11 +294,11 @@ if (MyObject obj(index); obj.good()) { ### Prefer `double` to `float`, But Test First -Depending on the situation and the compiler's ability to optimize, one may be faster over the other. Choosing `float` will result in lower precision and may be slower due to conversions. On vectorizable operations `float` may be faster if you are able to sacrifice precision. +Depending on the situation and the compiler's ability to optimize, one may be faster over the other. Choosing `float` will result in lower precision and may be slower due to conversions. On vectorizable operations `float` may be faster if you are able to sacrifice precision. `double` is the recommended default choice as it is the default type for floating point values in C++. -See this [stackoverflow](http://stackoverflow.com/questions/4584637/double-or-float-which-is-faster) discussion for some more information. +See this [stackoverflow](http://stackoverflow.com/questions/4584637/double-or-float-which-is-faster) discussion for some more information. ### Prefer `++i` to `i++` ... when it is semantically correct. Pre-increment is [faster](http://blog2.emptycrate.com/content/why-i-faster-i-c) than post-increment because it does not require a copy of the object to be made. @@ -318,7 +318,7 @@ for (int i = 0; i < 15; ++i) ``` Even if many modern compilers will optimize these two loops to the same assembly code, it is still good practice to prefer `++i`. There is absolutely no reason not to and you can never be certain that your code will not pass a compiler that does not optimize this. -You should be also aware that the compiler will not be able optimize this only for integer types and not necessarily for all iterator or other user defined types. +You should be also aware that the compiler will not be able optimize this only for integer types and not necessarily for all iterator or other user defined types. The bottom line is that it is always easier and recommended to use the pre-increment operator if it is semantically identical to the post-increment operator. ### Char is a char, string is a string @@ -358,4 +358,3 @@ Properly use the already highly optimized components of the vendor provided stan #### `in_place_t` And Related Be aware of how to use `in_place_t` and related tags for efficient creation of objects such as `std::tuple`, `std::any` and `std::variant`. - diff --git a/09-Considering_Correctness.md b/09-Considering_Correctness.md index 5bc8b61..8313374 100644 --- a/09-Considering_Correctness.md +++ b/09-Considering_Correctness.md @@ -26,5 +26,3 @@ Consider using a typesafe library like Note that stronger typing can also allow for more compiler optimizations. * [Sorting in C vs C++](Sorting in C vs C++.pdf) - - diff --git a/11-Further_Reading.md b/11-Further_Reading.md index 515e16f..cc7b721 100644 --- a/11-Further_Reading.md +++ b/11-Further_Reading.md @@ -4,7 +4,7 @@ ## C++ - * https://github.com/isocpp/CppCoreGuidelines The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++ + * https://github.com/isocpp/CppCoreGuidelines The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++ * https://www.gitbook.com/book/alexastva/the-ultimate-question-of-programming-refactoring-/details - The Ultimate Question of Programming, Refactoring, and Everything * http://llvm.org/docs/CodingStandards.html - LLVM Coding Standards - very well written * http://geosoft.no/development/cppstyle.html diff --git a/12-Final_Thoughts.md b/12-Final_Thoughts.md index e7f711b..bb4b8f6 100644 --- a/12-Final_Thoughts.md +++ b/12-Final_Thoughts.md @@ -1,4 +1,3 @@ # Final Thoughts Expand your horizons and use other programming languages. Other languages have different constructs and expressions. Learning what else is out there will encourage you to be more creative with your C++ and write cleaner, more expressive code. - diff --git a/LICENSE b/LICENSE index 0bde2a8..85c55a6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,2 +1,2 @@ -This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. +This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/. diff --git a/SUMMARY.md b/SUMMARY.md index 6ecc4de..c4a9540 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -12,4 +12,3 @@ * [Enable Scripting](10-Enable_Scripting.md) * [Further Reading](11-Further_Reading.md) * [Final Thoughts](12-Final_Thoughts.md) -