c++编程惯用法读书笔记

本文是关于C++编程的高级程序员惯用法读书笔记,涵盖抽象设计、模板高级用法和异常处理等多个方面。强调了设计迭代过程、边界条件的考虑、避免公共数据、智能指针的使用、模版特化和异常的安全使用等核心要点,旨在提高C++编程的效率和代码质量。
摘要由CSDN通过智能技术生成

c++编程惯用法

----高级程序员常用方法和技巧


第1章 抽象

  • 设计抽象模型和设计实现细节应该是两个相互独立且相关的行为。
  • 没有出现在抽象模型中的东西和出现在其中的东西一样重要
  • 如果存在疑问,先不要考虑它。添加新的功能通常都不会有兼容性的问题,但是去除一个已有的功能则可能导致代码失效。
  • 彻底的检测和记录下设计中的关键点。
  • 设计是一个迭代的过程。
  • 请考虑边界条件。
  • 在设计初始阶段使用CRC卡片。
第2章 类

  • 判断缺省的复制构造函数和赋值操作符的行为是否符合我们的期望,必要时重新实现它们。
  • 避免使用赋值操作来初始化成员,使用构造函数初始化语法来完成初始化操作。
  • 当编写赋值操作符时,请检测s = s 这种情况。
  • 避免出现公用数据。
  • 尽可能少的声明和使用隐式类型转换。避免在同一个类中出现两个(或者多个)转换操作符。
  • 一元操作符,赋值操作符,(),  [] ,以及 -> 应该被定义为成员函数,其它操作符应该被定义为非成员函数。
  • 使用缺省值来为同一个函数提供不同的调用方式,使用函数重载来为同一个抽象操作提供多种实现。
  • 除非被调用函数需要它自己的对象拷贝,否则请使用传递常量引用的方式来调用函数。
Product Description The author uses practical, concise code examples to illuminate a useful programming stratagem or warn against a dangerous practice. Readers will come away with a better understanding of how C++ is used in the real world. From the Inside Flap In the hands of an expert, C++ helps designers and programmers build systems that are modular, maintainable, and fast. To the novice, however, the size of the language can be intimidating. There are a lot of features in C++ and it takes some experience to learn which ones are appropriate for any situation. This book is intended to enhance and expedite that learning process. Most successful C++ programmers cannot recite chapter and verse from the language rules; instead, they have acquired a set of idioms and techniques that have worked well for them. Our goal is to help the C++ novice learn those idioms that have been most useful in practice. We also point out some of the most common pitfalls. We do not try to cover the entire language and we leave the ultra-precise definitions of language semantics to the reference manuals. Instead, we concentrate on helping the reader build programs that can be understood by someone who is not a C++ language lawyer. We not only discuss techniques for making programs elegant and fast; we also show how to make them easier to understand and maintain. Acknowledgements Almost none of the ideas and programming idioms in this book are my invention. My goal has been to present, in a way that allows novice C++ programmers to learn them quickly, what I consider to be the most important strategies and tactics I have learned from others in the eight years I have been using C++. Some of these lessons were learned by studying actual development projects as they moved from C to C++; others came from discussions with talented individuals. Many of the best ideas on templates and library design, including the ideas behind many of the container classes in this book, came from classes in the USL Standard Components that were originally designed by Martin Carroll, Andrew Koenig, and Jonathan Shopiro. I claim exclusive ownership of any errors in my versions. Andrew Koenig was a valuable resource as the local C++ language lawyer. The participants in the "C++ Strategies and Tactics" seminars I presented at several conferences helped inspire this book and refine its ideas. Other important ideas came from Tom Cargill, John Carolan, Jim Coplien, Mark Linton, Gerald Schwarz, and of course Bjarne Stroustrup, who also invented the C++ programming language that made the book possible in the first place. Brian Kernighan read several drafts of this book, and his excellent feedback has been a lot of help. I would also like to thank David Annatone, Steve Buroff, Tom Cargill, Bill Hopkins, Cay Horstman, Lorraine Juhl, Peter Juhl, Stan Lippman, Dennis Mancl, Scott Meyers, Barbara Moo, Lorraine Weisbrot Murray, Bjarne Stroustrup, Clovis Tondo, Steve Vinoski, and Christopher Van Wyk for their comments on early drafts of this book. Lorraine Weisbrot Murray also contributed the encouragement, understanding, support, and love that helped make the entire effort feasible. Rob Murray
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值