Exceptional C++中文版

萨特 (Sutter Herb)

出版时间

1970-01-01

ISBN

9787508314853

评分

★★★★★
书籍介绍
这本书最特别之处,在于它不给你现成的答案,而是先抛出47个让人挠头的工程难题,再引导你自己去拆解。它把异常安全、资源管理、异常传播这些C++里最易踩坑的领域,浓缩成一个个具体的代码谜题——RAII怎么用、析构函数为什么不能抛异常、什么时候该让异常向上抛出而非强行吞掉。读者读完最大的收获,不是记住几条规则,而是养成一种'看到代码就本能地想:这里会不会泄漏?会不会在异常时留下半成品状态?'的工程师直觉。它适合已经写过几年代码、却总被各种诡异bug困扰的中高级开发者。唯一需要提醒的是:翻译质量参差,建议配合原著阅读。
AI导读
核心看点
  • 深入解析C++异常安全编程与资源管理
  • 通过47个工程谜题剖析健壮代码设计
  • 探讨RAII惯用法及模块高内聚设计原则
读者共识
  • C++程序员必读经典,醍醐灌顶
  • 难度高于Effective C++,信息量大
  • 虽内容稍显老旧,但核心思想永不过时
精彩摘录
  • "If a function isn't going to handle (or translate or deliberately absorb) an exception, it should allow the exception to propagate up to a caller who can handle it."
  • "Always structure your code so that resources are correctly freed and data is in a consistent state even in the presence of exceptions."
  • "Observe the canonical exception safety rules: Never allow an exception to escape from a destructor or from an overloaded operator delete() or operator delete[](); write every destructor and deallocation function as though it had an exception specification of "throw()"."
  • "Observe the canonical exception-safety rules: in each function, take all the code that right emit an exception and do all that work safely off to the side. Only then, when you know that the real work has succeeded, should you modify the program state (and clean up) using only nonthrowing operations."
  • "Prefer cohesion. Always endeavor to give each piece of code – each module, each class, each function – a single, well-defined responsibility."
  • "Always use the "resource acquisition is initialization" idiom to isolate resource ownership and management."
  • "Exception specifications can incur a performance overhead whether an exception is thrown or not, although many compilers are getting better at minimizing this. For widely-used operations and general-purpose containers, it may be better not to use exception specifications in order to avoid this overh"
  • "All destructors should always be implemented as though they had an exception specification of throw() -- that is, no exception must ever be allowed to propagate."
用户评论
读完了,有时间还是必读的,尤其是使用STL和关于Impl
翻译的不好啊
C++是个令人抓狂的语言,这本书其实还不错
当时这一系列的C++书是百读不厌!
内容有点老,但是紧凑而深入。
如果读了 E 和 ME,就没必要读这本书了。GotW式到表现形式导致信息量不多,三星足矣。
非常好的总结,大部分已看完
读过 Effective C++/More Effective C++后,仍能震撼你的作品。
可以说是对C++的高级技巧总结的最好的一套小册子了 很适合有一段开发经验后看,和之前自己遇到的问题总结类比,会有一种醍醐灌顶的大彻大悟
求书
收藏