The C++/Programming books I recommend

本文推荐了一系列C++及编程书籍,包括《C编程语言》、《C++编程语言》等经典著作,并介绍了如何通过这些资源学习C++语法、标准库使用、避免常见陷阱等内容。

The C++/Programming books I recommend

People often ask me which C++ and programming books I recommend, perhaps because PowerDNS has a reputation for being "readable C++".  This post is intended as my answer to this question, and also contains some broader notes on programming. If you have any additions or favorites I missed, please drop me a note, I intend to keep this page updated as new books come out!

An initial note: if you want to learn C++, by all means learn C++2011, the newest version. It removes quite a lot of the pain that comes with the power of C++. Also, don't fear books about C++2014, most compilers support it already!

Programming


Important parts of programming are: 
  • knowing the syntax of the language,  
  • knowing which features to use and when, 
  • writing readable code
    • the compiler may get it, but will the next human reader?
  • designing programs that make sense on a higher level 
To learn a language, typically we can head for the book called 'The X Programming Language'. There appears to be a rule that you have to write that book whenever you create a serious language. Learning the language however is like learning how to write cursive. It does not mean you've suddenly become a great author of prose!

For C++, there are two language books that matter:
  • The C Programming Language (Brian W. Kernighan, Denis M. Ritchie, TCPL)
    This book isn't about C++, but, everything relevant to C is also relevant to C++. For example, all examples in this book compile as valid C++. This is not generally true of  C, since C++ is more strict than its predecessor. But most quality C programs compile fine as C++. TCPL is a small book, and is widely hailed as one of the best 'The X Programming Language' books ever written. There is wisdom on almost every page. 
  • The C++ Programming Language (4th edition, Bjarne Stroustrup)
    An astounding book. It too has wisdom on every page. It also has 1400 pages. A hilarious review by Verity Stob can be found on The Register. In TCPL we read "C is not a big language, and it is not well served by a big book.". Hence the 1400 pages for C++. Even though the book is far too huge to read from cover to cover (although I think I've now hit almost every page), everyone should have a copy. It does indeed explain all of C++, and it does so pretty well. The book also is strong on C++ idioms that will make your life easier. 
I want to reiterate that TC++PL is not a book to learn C++ from. It is a book to keep nearby while you are doing so, however. An extract of TC++PL " A Tour of C++" is also available separately.
C++ is not just the language, but also a library. While the entire library is covered in TC++PL, for full details I recommend:
  • The Standard C++ Library (Nikolai Josuttis)
    Like TC++PL, this is a vast book. But it has Everything on the C++ libraries (also known as the Standard Template Library, STL). Get the second edition, which covers C++2011.
If you come from a higher level language like Python, Perl or Java, C and hence C++ can be daunting. Unlike these languages, C/C++ is very close to the actual hardware. This has great benefits in terms of fully exploiting that hardware, but also confronts you with the associated realities.  Simon Tatham (famous for 1: authoring Putty, 2:  lacking the ability to smell. He still uses C, though) has written a wonderful document called  The Descent to C. It may ease your pain and even seasoned C programmers may pick up a thing or two.

If you've read these three books and links, you'll be able to express yourself well in C++, and make good use of its libraries. However, you've not learned which of the many features to use, nor when. C++ is a powerful language. It has been said that in C, if you make a mistake,  you blow off your own foot. C++ is  then supposed to take your whole leg, and this is true.

Also, C++ is powerful enough to enable you to continue programming in your old language in C++. " I can write FORTRAN in any language". This will however not help you code better programs!

Making good use of C++


Here are three books, all by Scott Meyers, that greatly simplify the life of an aspiring C++ programmer:
  • Effective C++ - lists common pitfalls, wonderful features and problematic areas to avoid. Most recently updated in 2005.
  • More Effective C++ - more of the same, but getting a bit dated. Still worth your while.
  • Effective STL - last updated in 2001, and like Effective C++, but then with a stronger focus on the standard library.
If you want to get one of these, get Effective C++. If you want two, get Effective STL too. 
It is important to note that Scott has mostly completed a new book fully covering C++2014 (which can be seen as a refined version of C++2011. Most current compilers already support C++2014).  Once this book comes out, get it immediately as the previews already look great. 
UPDATE: Various people have recommended ' C++ Primer' by Stanley Lippman cs. I don't know the book, but it has been updated for C++2011 and has received lots of praise. Please let me know your thoughts!

Writing readable code


All books mentioned above discuss coding styles, things (not) to do, but it is all rather spread out. Wisdom on how to write readable code be found in:
  • The Practice of Programming (Brian W. Kernighan, Rob Pike, TPoP) - not specifically a C++ book, but has a a lot to say on how to structure code, when to optimize, when not, how to debug, how to prevent the need for debugging etc. Every office should have a copy.
  • Linux Kernel Coding Style (Linus Torvalds) - specifically not about C++, but still has a lot to tell us in chapters 4 ('Naming'), 6 ('Functions'), and 8 ('Commenting').
TPoP should probably be read from cover to cover by every programmer wanting to improve their code.

Designing larger scale code


I know of only one book that touches on this, and it has been instrumental in my thinking:
  • Large Scale C++ Software Design (John Lakos). Although dated in places, containing advice of use for people building on underpowered machines with very slow storage, this book is where I learned how to decompose complex problems into components that make sense. Of particular note is the material on cyclic dependencies in code. These quickly crop up, and make your components nearly impossible to test, since each component quickly relies on every other component.
Good luck learning C++! 
内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机与路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用与配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池与全局池)、NAT转换(静态与动态)、静态路由、RIP与OSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分与基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换与路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建与调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
### 关于电影推荐API接口 对于电影推荐系统的API接口,通常会提供一系列参数以便更精准地为用户提供个性化的影片建议。假设存在一个名为`/rexxar/v2/movie/recommend`的GET请求端点用于获取个性化电影推荐列表。 此类型的API可能会接受如下几个重要查询参数来定制化返回的结果集: - `userId`: 用户ID,用来识别特定用户的偏好历史记录。 - `count`: 返回条目数量,默认可能是10条或由服务提供商设定的最大值限制。 - `genre`: 可选参数,指定感兴趣的电影类型如动作片、喜剧片等。 - `yearRange`: 年份范围筛选条件,帮助聚焦某一时间段内的作品。 - `ratingThreshold`: 评分阈值过滤器,只显示高于给定平均分的作品。 下面是一个简单的Python脚本示例,展示如何通过HTTP GET方法调用这样的API并处理响应数据[^1]: ```python import requests url = "http://example.com/rexxar/v2/movie/recommend" params = { 'userId': '12345', 'count': 5, 'genre': 'action', 'yearRange': '[2010 TO *]', 'ratingThreshold': 7.5 } response = requests.get(url, params=params) if response.status_code == 200: movies = response.json() for movie in movies['results']: print(f"{movie['title']} ({movie['release_date']}) Rating:{movie['vote_average']}") else: print('Error:', response.status_code) ``` 需要注意的是上述URL仅为示意用途,在实际应用中应当替换为目标平台的真实API路径,并遵循其文档中的指导完成集成工作。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值