Wirte Clean Code笔记(人邮英文版)

本书深入探讨了如何通过启用编译器警告、使用lint工具、单元测试、断言验证等手段来编写无bug代码。强调了在编程过程中避免隐含假设、消除随机行为、设计透明的错误检查机制以及在接口设计上防止忽视错误条件的重要性。书中通过实例讲解了内存管理、调试技巧、代码优化和避免陷阱的方法,提倡程序员应关注代码的可读性和维护性,培养良好的编程态度。
摘要由CSDN通过智能技术生成

Chapter 1. A Hypothetical Compiler

P7. "Enable all optional compiler warnings."

P8. "Use lint to catch bugs that your compiler may miss."

P9. "If you have unit tests, use them."


Chapter 2. Assert Yourself

P15. "Maintain both ship and debug versions of your program."

P19. "Use assertions to validate function arguments."

P21. "Strip undefined behavior from your code, or use assertions to catch illegal uses of undefined behavior."

P22. assert is "Not for Errors".

P23. "Don't waste people's time. Document unclear assertions."

P23. "ARE YOU MAKING ASSUMPTIONS AGAIN?“,逐步写出一个鲁棒性好的memset。

P27. "Either remove implicit assumptions, or assert that they are valid."

P27. "Owning the Compiler Is Not Enough",默认int是4字节而不用sizeof,曾经习以为常的居然这么危险!

P29. "Use assertions to detect impossible conditions."

P33. "Don't hide bugs when you program defensively."(defensive programming是指写的函数可以容忍传入的参数有误)

P38. "Use a second algorithm to validate your results."

P38. "Hey, What Goes On Here?"-->自定义宏时最好别调用函数

P42. "Don't wait for bugs to happen; use startup checks."(例如可以在接受数据结束后立即检查数据正确性)

P43. 题2有些意思。题3:注意assert是在debug用的。


Chapter 3. Fortify Your Subsystem

P49. Mac系统,malloc分配的空间可用0xA3填充。因为0xA3A3指令将导致系统crash。该页下面的代码值得一看。

P50. "Eliminate random

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值