Here is a small e-Book for your attention: The Ultimate Question of Programming, Refactoring, and Everything. This book is intended for C/C++ programmers, but it could be of interest for developers using other languages as well.
What makes the book peculiar is the descriptions of real, not theoretical cases at the base of it. Each chapter starts with a code fragment taken from a real application, and then the author gives various tips of how this bug could be avoided. The questions touched upon in this book can help the readers improve the personal coding style and the coding standards used in the team.
The book covers 42 topics. In spite of the simple titles of the chapters, the bugs found are really various and non-standard. In addition to that, the text provides a lot of links to interesting materials that give more details on topics. To make more use of this book, please don’t hurry and go to the links provided.
Content:
- Don't do the compiler's job
- Larger than 0 does not mean 1
- Copy once, check twice
- Beware of the ?: operator and enclose it in parentheses
- Use available tools to analyze your code
- Check all the fragments where a pointer is explicitly cast to integer types
- Do not call the alloca() function inside loops
- Remember that an exception in the destructor is dangerous.
- Use the '\0' literal for the terminal null character
- Avoid using multiple small #ifdef blocks
- Don't try to squeeze as many operations as possible in one line
- When using Copy-Paste, be especially careful with the last lines
- Table-style formatting
- A good compiler and coding style aren't always enough
- Start using enum class in your code, if possible
- «Look what I can do!» — Unacceptable in programming
- Use dedicated functions to clear private data
- The knowledge you have, working with one language isn't always applicable to another language
- How to properly call one constructor from another
- The End-of-file (EOF) check may not be enough
- Check that the end-of-file character is reached correctly (EOF)
- Do not use #pragma warning(default:X)
- Evaluate the string literal length automatically
- Override and final identifiers should become your new friends.
- Do not compare 'this' to nullptr anymore
- Insidious VARIANT_BOOL
- Guileful BSTR strings
- Avoid using a macro if you can use a simple function
- Use a prefix increment operator (++i) in iterators instead of a postfix (i++) operator
- Visual C++ and wprintf() function
- In C and C++ arrays are not passed by value
- Dangerous printf
- Never dereference null pointers
- Undefined behavior is closer than you think
- Adding a new constant to enum don't forget to correct switch operators
- If something strange is happening to your PC, check its memory.
- Beware of the 'continue' operator inside do {...} while (...)
- Use nullptr instead of NULL from now on
- Why incorrect code works
- Start using static code analysis
- Avoid adding a new library to the project.
- Don't use function names with «empty»
For those, who find reading PDF format more convenient: https://yadi.sk/i/pBZqebxsr5Wyg
However, it should be borne in mind that we continue improving this article, making small edits in the text, so thew PDF version can become slightly outdated over the course of time. In case you want to share it with your colleagues, it’s better to use the link to this html-page http://www.viva64.com/en/b/0391/ that gets constantly updated.