Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions 00-Table_of_Contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


6 changes: 3 additions & 3 deletions 02-Use_the_Tools_Available.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions 03-Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.

12 changes: 6 additions & 6 deletions 04-Considering_Safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,7 +47,7 @@ public:
: m_int_value(t_int_value)
{
}

const int& get_int_value() const
{
return m_int_value;
Expand All @@ -69,7 +69,7 @@ public:
: m_int_value(t_int_value)
{
}

int get_int_value() const
{
return m_int_value;
Expand Down Expand Up @@ -101,7 +101,7 @@ auto mybuffer = std::make_unique<char[]>(length); // C++14
auto mybuffer = std::unique_ptr<char[]>(new char[length]); // C++11

// or for reference counted objects
auto myobj = std::make_shared<MyClass>();
auto myobj = std::make_shared<MyClass>();

// ...
// myobj is automatically freed for you whenever it is no longer used.
Expand All @@ -111,7 +111,7 @@ auto myobj = std::make_shared<MyClass>();

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

Expand Down
2 changes: 1 addition & 1 deletion 05-Considering_Maintainability.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
9 changes: 4 additions & 5 deletions 08-Considering_Performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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`.

2 changes: 0 additions & 2 deletions 09-Considering_Correctness.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


2 changes: 1 addition & 1 deletion 11-Further_Reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion 12-Final_Thoughts.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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/.
1 change: 0 additions & 1 deletion SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
* [Enable Scripting](10-Enable_Scripting.md)
* [Further Reading](11-Further_Reading.md)
* [Final Thoughts](12-Final_Thoughts.md)