When developing software, here's a partial list of things I value:
Build using multiple compilers
Sometimes you forget to #include something from a standard library that works on one compiler but doesn't on another or use constructs that don't compile on all compilers.
Static Analysis and high warning levels
I regularly run PVS-Studio, CppCheck and Clang static analyzers and use very high warning levels on my compilers.
My GCC warnings: -Wall -pedantic -Wextra -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization \
-Wdouble-promotion -Wformat=2 -Winit-self -Winvalid-pch -Wlogical-op -Wmissing-include-dirs \
-Wshadow -Wredundant-decls -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wtrampolines \
-Wunsafe-loop-optimizations -Wvector-operation-performance -Wzero-as-null-pointer-constant
Unit Tests
I have found many bugs using them. Excellent for math stuff, serialization testing, error handling testing etc.
Test graphics code on multiple GPUs
Some drivers accept bad syntax in shaders or have bugs. I test my graphics code on NVIDIA, AMD and Intel GPUs on Windows, OS X and on Linux.
Minimize variable scope
Declare variables as close as possible to their use site and try to make them const. Ternary operator and lambdas can help here.
Avoid Boolean arguments
They make the code hard to read and often break the Single Responsibility Principle.
Avoid magic numbers
Same as above.
Collect metrics
Use tools like Metrix++ to get metrics like line count, cyclomatic complexity etc.
Extract complex conditionals into descriptive variables and methods.
Comment things that can't be expressed in code
First try to name your variables/methods so the comments are unnecessary. Only after that write comments.
No comments:
Post a Comment