Add note on assert

This commit is contained in:
Jason Turner
2017-09-01 09:31:04 -06:00
committed by GitHub
parent 361f28d57b
commit 3779f868ad

View File

@@ -31,6 +31,22 @@ See http://mortoray.com/2015/06/15/get-rid-of-those-boolean-function-parameters/
Know and understand the existing C++ standard algorithms and put them to use. See [C++ Seasoning](https://www.youtube.com/watch?v=qH6sSOr-yk8) for more details. Know and understand the existing C++ standard algorithms and put them to use. See [C++ Seasoning](https://www.youtube.com/watch?v=qH6sSOr-yk8) for more details.
## Never Use `assert` With Side Effects
```cpp
// Bad Idea
assert(set_value(something));
// Better Idea
[[maybe_unused]] const auto success = set_value(something);
assert(success);
```
The `assert()` will be removed in release builds which will prevent the `set_value` call from every happening.
So while the second version is uglier, the first version is simply not correct.
## Properly Utilize 'override' and 'final' ## Properly Utilize 'override' and 'final'
These keywords make it clear to other developers how virtual functions are being utilized, can catch potential errors if the signature of a virtual function changes, and can possibly [hint to the compiler](http://stackoverflow.com/questions/7538820/how-does-the-compiler-benefit-from-cs-new-final-keyword) of optimizations that can be performed. These keywords make it clear to other developers how virtual functions are being utilized, can catch potential errors if the signature of a virtual function changes, and can possibly [hint to the compiler](http://stackoverflow.com/questions/7538820/how-does-the-compiler-benefit-from-cs-new-final-keyword) of optimizations that can be performed.