简单介绍
这本书本身是针对C/C++程序员的,但其实对其他语言也一样有效。
这本书的特别之处在于,书中的例子都基于实例而不是理论。书中每个小节的都以一段从实际项目中提炼出来的有bug的代码,然后作者会通过不同角度分析如何避免这些bug。整本书所针对的问题以及解决方式,可以帮助读者提高个人在团队内的编码风格和编程规范。
这本书覆盖了42个主题(详见下面的目录),尽管每个主题的标题很简单,但其对应bug的发现喝解决是多种多样的。另外,每个主题还给出了相关的有趣资料链接,可以让读者得到和主题相关颈详细的信息。**在这个目录后面,还有更多对标题所谓“终极问题”的简单回答,内容介绍和作者介绍,不要错过**。
---
目录
Preface
1. Don't do the compiler's job
2. Larger than 0 does not mean 1
3. Copy once, check twice
4. Beware of the ?: operator and enclose it in parentheses
5. Use available tools to analyze your code
6. Check all the fragments where a pointer is explicitly cast to integer types
7. Do not call the alloca() function inside loops
8. Remember that an exception in the destructor is dangerous.
9. Use the '\0' literal for the terminal null character
10. Avoid using multiple small #ifdef blocks
11. Don't try to squeeze as many operations as possible in one line
12. When using Copy-Paste, be especially careful with the last lines
13. Table-style formatting
14. A good compiler and coding style aren't always enough
15. Start using enum class in your code, if possible
16. "Look what I can do!" - Unacceptable in programming
17. Use dedicated functions to clear private data
18. The knowledge you have, working with one language isn't always applicable to another language
19. How to properly call one constructor from another
20. The End-of-file (EOF) check may not be enough
21. Check that the end-of-file character is reached correctly (EOF)
22. Do not use #pragma warning(default:X)
23. Evaluate the string literal length automatically
24. Override and final specifiers should become your new friends.
25. Do not compare 'this' to nullptr anymore
26. Insidious VARIANT_BOOL
27. Guileful BSTR strings
28. Avoid using a macro if you can use a simple function
29. Use a prefix increment operator (++i) in iterators instead of a postfix (i++) operator
30. Visual C++ and wprintf() function
31. In C and C++ arrays are not passed by value
32. Dangerous printf
33. Never dereference null pointers
34. Undefined behavior is closer than you think
35. Adding a new constant to enum don't forget to correct switch operators
36. If something strange is happening to your PC, check its memory.
37. Beware of the 'continue' operator inside do {...} while (...)
38. Use nullptr instead of NULL from now on
39. Why incorrect code works
40. Start using static code analysis
41. Avoid adding a new library to the project.
42. Don't use function names with "empty"
Conclusion
更多介绍
是的,你猜得对——答案就是“42”。在这本书中,你会发现42个关于C++编程的好建议,都是关于如何帮助一名程序员避免许多错误,节省开发时间,提高开发效率的。这本书的作者是Andrey Karpov,也是‘Program Verification System’研发团队的技术总监,我们这个团队主要负责PVS-Studio静态代码分析器的研发。在经历过大量的开源项目后,我们已经找到了很多规则来让你的编程更厉害,我们也准备把这些规则分享出来。每条规则都辅以一些经过历练的的代码示例。这些规则不光对C/C++程序员有帮助,大家知道编程思想是相通的,所以其他语言的程序员也会受益于此。
https://www.viva64.com/en/b/0391/