mirror of
https://github.com/cpp-best-practices/cppbestpractices.git
synced 2025-12-17 11:14:35 +03:00
Tools and notes updates
This commit is contained in:
@@ -8,5 +8,6 @@
|
|||||||
7. [Considering Performance](07-Considering_Performance.md)
|
7. [Considering Performance](07-Considering_Performance.md)
|
||||||
8. [Enable Scripting](08-Enable_Scripting.md)
|
8. [Enable Scripting](08-Enable_Scripting.md)
|
||||||
9. [Further Reading](09-Further_Reading.md)
|
9. [Further Reading](09-Further_Reading.md)
|
||||||
|
10. [Final Thoughts](10-Final_Thoughts.md)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# Use The Tools Available
|
# Use The Tools Available
|
||||||
|
|
||||||
|
An automated framework for executing these tools should be established very early in the development process. It should not take more than 2-3 commands to checkout the source code, build, and execute the tests. Once the tests are done executing, you should have an almost complete picture of the state and quality of the code.
|
||||||
|
|
||||||
## Source Control
|
## Source Control
|
||||||
|
|
||||||
Source control is an absolute necessity for any software development project. If you are not using one yet, start using one.
|
Source control is an absolute necessity for any software development project. If you are not using one yet, start using one.
|
||||||
@@ -105,7 +107,11 @@ Can be enabled with the `/analyze` [command line option](http://msdn.microsoft.c
|
|||||||
|
|
||||||
commercial options
|
commercial options
|
||||||
|
|
||||||
|
### Metrix++
|
||||||
|
|
||||||
|
http://metrixplusplus.sourceforge.net/
|
||||||
|
|
||||||
|
While not necessarily a static analyzer, Metrix++ can identify and report on the most complex sections of your code. Reducing complex code helps you and the compiler understand it better and optimize it better.
|
||||||
|
|
||||||
## Runtime Checkers
|
## Runtime Checkers
|
||||||
|
|
||||||
@@ -115,6 +121,7 @@ A coverage analysis tool shall be run when tests are executed to make sure the e
|
|||||||
|
|
||||||
The most likely candidate for a coverage visualization is the [lcov](http://ltp.sourceforge.net/coverage/lcov.php) project. A secondary option is [coveralls](https://coveralls.io/), which is free for open source projects.
|
The most likely candidate for a coverage visualization is the [lcov](http://ltp.sourceforge.net/coverage/lcov.php) project. A secondary option is [coveralls](https://coveralls.io/), which is free for open source projects.
|
||||||
|
|
||||||
|
An alternative to lcov is [gcovr](http://gcovr.com/). It seems to provide similar functionality, but is written in python.
|
||||||
<link to chaiscript example of using it>
|
<link to chaiscript example of using it>
|
||||||
|
|
||||||
### GCC/Clang Sanitizers
|
### GCC/Clang Sanitizers
|
||||||
@@ -130,6 +137,10 @@ If it is determined by team consensus that the compiler or analyzer is warning o
|
|||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
CMake, mentioned above, has a built in framework for executing tests. Make sure whatever build system you use has a way to execute tests built in.
|
||||||
|
|
||||||
|
To further aid in executing tests, consider a library such as [googletest](https://code.google.com/p/googletest/) or [Catch](https://github.com/philsquared/Catch) to help you organize the tests.
|
||||||
|
|
||||||
### Unit Tests
|
### Unit Tests
|
||||||
|
|
||||||
Unit tests are for small chunks of code, individual functions which can be tested standalone.
|
Unit tests are for small chunks of code, individual functions which can be tested standalone.
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
## Build Time
|
## Build Time
|
||||||
|
|
||||||
## see also
|
|
||||||
include-what-you-use
|
|
||||||
|
|
||||||
|
|
||||||
### Forward Declare when Possible
|
### Forward Declare when Possible
|
||||||
@@ -40,8 +38,14 @@ This is a proactive approach to simplify compilation time and rebuilding depende
|
|||||||
|
|
||||||
### Firewall Frequently Changing Header Files
|
### Firewall Frequently Changing Header Files
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Don't Unnecessarily Include Headers
|
### Don't Unnecessarily Include Headers
|
||||||
|
|
||||||
|
The compiler has to do something with each include directive it sees. Even if it stops as soon as it seems the `#ifndef` include guard, it still had to open the file and begin processing it.
|
||||||
|
|
||||||
|
[include-what-you-use](https://code.google.com/p/include-what-you-use) is a tool that can help you identify which headers you need.
|
||||||
|
|
||||||
### Reduce the load on the preprocessor
|
### Reduce the load on the preprocessor
|
||||||
|
|
||||||
This is a general form of "Firewall Frequently Changing Header Files" and "Don't Unnecessarily Include Headers." Tools like BOOST_PP can be very helpful, but they also put a huge burden on the preprocessor
|
This is a general form of "Firewall Frequently Changing Header Files" and "Don't Unnecessarily Include Headers." Tools like BOOST_PP can be very helpful, but they also put a huge burden on the preprocessor
|
||||||
@@ -54,9 +58,24 @@ These are not meant to supercede good design
|
|||||||
|
|
||||||
CCACHE, facebook's thing (warp)
|
CCACHE, facebook's thing (warp)
|
||||||
|
|
||||||
|
### Put tmp on Ramdisk
|
||||||
|
|
||||||
|
See [this](https://www.youtube.com/watch?v=t4M3yG1dWho) youtube video for more details.
|
||||||
|
|
||||||
|
### Use the Gold Linker
|
||||||
|
|
||||||
|
If on linux, consider using the gold linker for gcc.
|
||||||
|
|
||||||
## Runtime
|
## Runtime
|
||||||
|
|
||||||
|
### Analyze the code!
|
||||||
|
|
||||||
|
There's no real way to know where your bottlenecks are without analyzing the code.
|
||||||
|
|
||||||
|
* http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/
|
||||||
|
* http://www.codersnotes.com/sleepy
|
||||||
|
|
||||||
|
|
||||||
### Limit Variable Scope
|
### Limit Variable Scope
|
||||||
|
|
||||||
Variables should be declared as late as possible, and ideally, only when it's possible to initialize the object. Reduced variable scope results in less memory being used, more efficient code in general, and helps the compiler optimize the code further.
|
Variables should be declared as late as possible, and ideally, only when it's possible to initialize the object. Reduced variable scope results in less memory being used, more efficient code in general, and helps the compiler optimize the code further.
|
||||||
@@ -81,6 +100,9 @@ for (int i = 0; i < 15; ++i)
|
|||||||
|
|
||||||
### Prefer double to float
|
### Prefer double to float
|
||||||
|
|
||||||
|
Operations are doubles are typically faster than float. However, in vectorized operations, float might win out. Analyze the code and find out which is faster for your application!
|
||||||
|
|
||||||
|
|
||||||
### Prefer ++i to i++
|
### Prefer ++i to i++
|
||||||
... when it is semantically correct. Pre-increment is [faster](http://blog2.emptycrate.com/content/why-i-faster-i-c) then post-increment because it does not require a copy of the object to be made.
|
... when it is semantically correct. Pre-increment is [faster](http://blog2.emptycrate.com/content/why-i-faster-i-c) then post-increment because it does not require a copy of the object to be made.
|
||||||
|
|
||||||
@@ -99,3 +121,4 @@ for (int i = 0; i < 15; ++i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
4
10-Final_Thoughts.md
Normal file
4
10-Final_Thoughts.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# 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 expresive code.
|
||||||
|
|
||||||
Reference in New Issue
Block a user