Skip to Content
C++程序设计:原理与实践(基础篇)(原书第2版)
book

C++程序设计:原理与实践(基础篇)(原书第2版)

by 本贾尼 斯特劳斯特鲁普
August 2021
Intermediate to advanced
450 pages
9h 36m
Chinese
Pearson
Content preview from C++程序设计:原理与实践(基础篇)(原书第2版)

7.8.4 我们到达目的地了吗

还没有,在对程序做了诸多修改以后,还需要对程序进行测试、清理代码和修改注释等。而且,还可以定义更多的操作和变量。例如:我们还没有在程序中提供赋值操作符(见习题2),如果实现赋值操作的话,我们可能还想区分变量和常量(见习题3)。

我们先回到最初不支持命名变量的计算器程序,仔细回顾一下实现命名变量功能的代码,可能会有两种不同的反应:

1.实现变量并不那么糟,大概用三四十行代码就可以了。

2.实现变量是一个重大的扩展,几乎涉及每个函数,并且在计算器程序中引入了一个全新的概念。在没有实现赋值操作的情况下,代码量已经增加了大约45%!

计算器程序是我们第一个比较复杂的程序,站在这个角度来看,第二种反应是比较合理的。一般来说,如果一个改进程序的建议会使程序的代码量和复杂度都增加50%左右,第二个反应是很正常的。如果真按这样的建议去做了,你会发现整个过程更像是基于原来版本重写了一个新的程序。而且,你最好把这个过程当作重写程序来对待,这样会有更好的效果。特别地,如果我们能够分阶段编写和测试程序,就像设计计算器程序这样,最好就这么做,这比一下子就编写完整的程序要好得多。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普
管理Kubernetes

管理Kubernetes

Brendan Burns, Craig Tracey
Python编程入门与实战

Python编程入门与实战

Posts & Telecom Press, Fabrizio Romano

Publisher Resources

ISBN: 9787111562252