Home > Store

Ruminations on C++: A Decade of Programming Insight and Experience

Register your product to gain access to bonus material or receive a coupon.

Ruminations on C++: A Decade of Programming Insight and Experience

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1997
  • Dimensions: 6-1/4" x 9-1/4"
  • Pages: 400
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-42339-1
  • ISBN-13: 978-0-201-42339-6

A book that stands out from the herd.

Ruminations on C++ concentrates on the key C++ ideas and programming techniques--skimming the cream--to let you understand the "why" and not just the "how" of C++ programming. You need not be an expert C++ programmer to find solid fodder here, yet even experts need not fear overgrazing: You will find something worth chewing on in every chapter.

This should be your next C++ book, because it

  • covers a broad range of C++ ideas and techniques, from detailed code examples to design principles and philosophy

  • shows how to think about programming in C++, not just how to follow rules

  • explains the motivation behind its examples; sometimes even solving the same problem in two different ways

  • covers both object-oriented programming and generic programming

  • explains the ideas behind the Standard Template Library, which is the most important recent innovation in C++.

This book comes to you from two people who started using C++ when its entire user community could still fit in one room. Both of them have contributed significantly to the evolution of C++.



0201423391B04062001

Downloads

Source Code

The code is available in 3 separate formats:

  • Code.tar.Z is a Unix tarred and compressed file.
  • Code.zip is a long file name Win95/NT zip file built with WinZip.
  • Code.sea.bin is a self extracting, MacBinary encoded, stuffit archive for use with the Macintosh.

Sample Content

Table of Contents



Preface.


Prelude.

First Try.

Doing it without Classes.

Why was it Easier in C++?

A Bigger Example.

Conclusion.

I. MOTIVATION.

1. Why I Use C++.

The Problem.

History and Context.

Automatic Software Distribution.

Enter C++.

Recycled Software.

Postscript.

2. Why I Work on C++.

The Success of Small Projects.

Abstraction.

Machines Should Work for People.

3. Living in the Real World.

II. CLASSES aND INHERITANCE.

4. Checklist for Class Authors.
5. Surrogate Classes.

The Problem.

The Classical Solution.

Virtual Copy Functions.

Defining a Surrogate Class.

Summary.

6. Handles: Part 1.

The Problem.

A Simple Class.

Attaching a Handle.

Getting at the Object.

Simple Implementation.

Use-Counted Handles.

Copy on Write.

Discussion.

7. Handles: Part 2.

Review.

Separating the use Count.

Abstraction of use Counts.

Access Functions and Copy on Write.

Discussion.

8. An Object-Oriented Program.

The Problem.

An Object-Oriented Solution.

Handle Classes.

Extension 1: New Operations.

Extension 2: New Node Types.

Reflections.

9. Analysis of a Classroom Exercise: Part 1.

The Problem.

Designing the Interface.

A Few Loose Ends.

Testing the Interface.

Strategy.

Tactics.

Combining Pictures.

Conclusion.

10. Analysis of a Classroom Exercise: Part 2.

Strategy.

Exploiting the Structure.

Conclusion.

11. When not to use Virtual Functions.

The Case For.

The Case Against.

Destructors are Special.

Summary.

III. TEMPLATES.

12. Designing a Container Class.

What Does it Contain?

What Does Copying the Container Mean?

How Do You Get at Container Elements?

How Do You Distinguish Reading from Writing?

How Do You Handle Container Growth?

What Operations Does the Container Provide?

What Do You Assume about the Container Element Type?

Containers and Inheritance.

Designing an Arraylike Class.

13. Accessing Container Elements.

Imitating a Pointer.

Getting at the Data.

Remaining Problems.

Pointer to Const Array.

Useful Additions.

14. Iterators.

Completing the Pointer Class.

What is an Iterator?

Deleting an Element.

Deleting the Container.

Other Design Considerations.

Discussion.

15. Sequences.

The State of the Art.

A Radical Old Idea.

Well, Maybe a Few Extras.

Example of Use.

Maybe a Few More.

Food for Thought.

16. Templates as Interfaces.

The Problem.

The First Example.

Separating the Iteration.

Iterating Over Arbitrary Types.

Adding Other Types.

Abstracting the Storage Technique.

The Proof of the Pudding.

Summary.

17. Templates and Generic Algorithms.

A Specific Example.

Generalizing the Element Type.

Postponing the Count.

Address Independence.

Searching a Nonarray.

Discussion.

18. Generic Iterators.

A Different Algorithm.

Categories of Requirements.

Input Iterators.

Output Iterators.

Forward Iterators.

Bidirectional Iterators.

Random-Access Iterators.

Inheritance?

Performance.

Summary.

19. Using Generic Iterators.

Iterator Types.

Virtual Sequences.

An Output-Stream Iterator.

An Input-Stream Iterator.

Discussion.

20. Iterator Adaptors.

An Example.

Directional Asymmetry.

Consistency and Asymmetry.

Automatic Reversal.

Discussion.

21. Function Objects.

An Example.

Function Pointers.

Function Objects.

Function-Object Templates.

Hiding Intermediate Types.

One Type Covers Many.

Implementation.

Discussion.

22. Function Adaptors.

Why Function Objects?

Function Objects For Built-In Operators.

Binders.

A Closer Look.

Interface Inheritance.

Using These Classes.

Discussion.

IV. LIBRARIES.

23. Libraries in Everyday Use.

The Problem.

Understanding the Problem—Part 1.

Implementation—Part 1.

Understanding the Problem—Part 2.

Implementation—Part 2.

Discussion.

24. An Object Lesson in Library-Interface Design.

Complications.

Improving the Interface.

Taking Stock.

Writing the Code.

Conclusion.

25. Library Design is Language Design.

Character Strings.

Memory Exhaustion.

Copying.

Hiding the Implementation.

Default Constructor.

Other Operations.

Substrings.

Conclusion.

26. Language Design is Library Design.

Abstract Data Types.

Libraries and Abstract Data Types.

Memory Allocation.

Memberwise Assignment and Initialization.

Exception Handling.

Summary.

V. TECHNIQUE.

27. Classes that Keep Track of Themselves.

Design of a Trace Class.

Creating Dead Code.

Generating Audit Trails for Objects.

Verifying Container Behavior.

Summary.

28. Allocating Objects in Clusters.

The Problem.

Designing the Solution.

Implementation.

Enter Inheritance.

Summary.

29. Applicators, Manipulators, and Function Objects.

The Problem.

A Solution.

A Different Solution.

Multiple Arguments.

An Example.

Abbreviations.

Musings.

Historical Notes, References, and Acknowledgments.

30. Decoupling Application Libraries from Input-Output.

The Problem.

Solution 1: Trickery and Brute Force.

Solution 2: Abstract Output.

Solution 3: Trickery without Brute Force.

Remarks.

VI. WRAPUP.

31. Simplicity through Complexity.

The World is Complicated.

Complexity Becomes Hidden.

Computers are no Different.

Computers Solve Real Problems.

Class Libraries and Language Semantics.

Making Things Easy is Hard.

Abstraction and Interface.

Conservation of Complexity.

32. What Do You Do After You Say Hello World?

Find the Local Experts.

Pick a Tool Kit and Become Comfortable with it.

Some Parts of C are Essential.

But Others are not.

Set Yourself a Series of Problems.

Conclusion.

Index. 0201423391T04062001

Preface

Origins

Early in 1988, about when I had finished writing C Traps and Pitfalls, Bjarne Stroustrup told me that he had just been invited to join the editorial board of a new magazine called the Journal of Object-Oriented Programming(JOOP). The magazine was intended to fit between the conventional academic journals and the magazines that are mostly product reviews and advertising. They were seeking a C++ columnist; was I interested?

C++ was just beginning to become an important influence on the programming community. Usenix had recently held its first C++ workshop, in Santa Fe, New Mexico.They had expected 50 people; more than 200 showed up. Many more would hop on the C++ bandwagon, which meant that the community would need an articulate, reasoned voice to speak against the torrent of hype that was sure to come. It would need someone who could make clear the difference between hype and substance and keep a cool head in all the turmoil. I took the offer anyway.

I am writing these words while thinking about my sixty-third column for JOOP. The column has appeared in every issue but two, during which time I badly needed a break and was lucky enough to be able to get Jonathan Shopiro to take my place. On a third occasion, I wrote only the introduction to the column, stepping aside for the distinguished Danish computer scientist Bjorn Stavtrup. In addition, Livleen Singh talked me into writing a column for the quarterlyC++ Journal, which lasted six issues before folding, and Stan Lippman cajoled me into doing a column for the C++ Reportwhen it changed from a newsletter into a full-fledged magazine. Adding my 29 C++ Reportcolumns to the others brings the total to 98.

That's a lot of stuff to be scattered in periodicals all over the place.If the articles are useful individually, they should be evenmore useful when collected.In consequence, Barbara and I (mostly Barbara) have gone back over the columns, selected the best, and added to or rewritten them as needed for coherence and continuity.

Just what the world needs--another C++ book

Now that you know why the book exists, let me tell you why you should read it instead of some other C++ book. Goodness knows, there are enough of them; why pick this one?

The first reason is that I think you'll enjoy it. Most C++ books don't have that in mind: They are curriculum-based. Enjoyment is secondary at best.

Magazine columns are different. I suppose there must be some people out there who thumb through a copy of JOOPin a bookstore and skim my column before deciding whether to buy the magazine, but it would be arrogant to think that there are more than a few. Most readers will be seeing my column after they've already paid for it, which means that they have a completely free choice about whether to read it or not. So each column has to be worth reading on its own.

This book contains no long, boring discussions of obscure details. Beginners are not intended to be able to learn C++ from this book alone. A few people, who already know several programming languages thoroughly, and who have figured out how to infer the rules for a new language by reading code, will be able to use this book to get an overview of C++. Most readers starting from scratch would do well to read The C++ Programming Language(Addison-Wesley 1991)by Bjarne Stroustrup, or Stan Lippman's C++ Primer(Addison-Wesley 1991), and then read this book.

This is a book about ideas and techniques, not details. If you want to find out how to make virtual base classes do double reverse backflips, you will have to turn elsewhere.What you will find here is lots of code to read.Try the examples for yourself. Classroom experience indicates that getting these programs to run and then modifying them is a good way to cement your understanding. For those who prefer to start with working code, we have made available selected examples from the book by anonymous FTP from ftp.aw.com in directory cseng/authors/koenig/ruminations.

If you know some C++ already, I think that this book will not only entertain but also enlighten you. This is the second reason to read it. My intent isn't to teach C++ per se. Instead, I want to show you how to think about programming in C++, and how to look at problems and express a solution in C++. Knowledge can be acquired systematically; wisdom cannot.

Organization

Although I intended each column to stand alone, I believe that the collection will be easier and more enjoyable to read when grouped by concept. The book is therefore divided into six parts.

Part I is an extended introduction to themes that will pervade the rest of the book. You won't find much code, but the ideas of abstraction and pragmatism explored there underlie both this book and, more important, the design of C++ and strategies for its effective use.

Part II looks at inheritance and object-oriented programming, which most people think are the most important ideas in C++. You will learn why inheritance is important and what it can do.You will also learn why it can be useful to conceal inheritance from its users and when to avoid inheritance altogether.

Part III explores templates, which I think constitute the most important idea in C++. The reason I think templates are so important is that they provide a particularly powerful kind of abstraction. Not only do templates allow the construction of containers that know almost nothing about the types of what they will contain, but they make it possible to abstract away things far more general than just types.

One reason that inheritance and templates are important is that they are ways of extending C++ without waiting (or paying) for people to produce new languages and compilers. The way to organize such extensions is through class libraries. Part IV talks about libraries--both their design and use.

With the basics well understood, we can look at some specialized programming techniques in Part V. Here you will find ways to tie classes inextricably together, as well as ways to keep them as far apart as possible.

Finally, in Part VI, we turn back for a last look at the terrain we have covered.

Compilation and editing

One artifact of these papers having been written over a number of years is that they do not always use all the current features of the language.This raises a problem: Do we rewrite the columns as if full-fledged ISO C++ were the norm when the standard hasn't been approved yet?Or do we deliberately write in an archaic style?

As with so much else in C++, we compromised. Where the original column was simply incorrect--either in light of how the language has changed since the column was written or because of a change in our understanding of how things should be--we'vefixed it. A particularly pervasive example is our use of const the importance of which has steadily grown in our understanding since const entered the language.

On the other hand, for instance, lots of examples here use int to represent true or false values, even though the standards committee has accepted bool as a built-in data type. The reasoning is that the columns were written that way originally, using int for such values will still work, and it will be years before most compilers support bool.

Acknowledgments

In addition to publishing our ideas in JOOP, the C++ Report, and the C++ Journal, we refined them through giving talks (and listening to students) in many places. Particularly noteworthy were the conferences organized by the Usenix Association and by SIGS Publications, publishers of JOOPand the C++ Report. In addition, there are the weeklong courses that the two of us have taught at Stanford University under the auspices of the Western Institute in Computer Science, and at Bell Labs for members of the Acoustics Research Laboratory and Network Services Research Laboratory, as well as several courses and lectures that Dag Bruck, then at the Department of Automatic Control at the Lund Institute of Technology and now at Dynasim AB, organized in Sweden.

We are also grateful to the people who read and commented on drafts of the book and the columns that it comprises: Dag Bruck, Jim Coplien, Tony Hansen, Bill Hopkins, Brian Kernighan (who gets extra credit for reading the entire book twice carefully with pen in hand), Stan Lippman, Rob Murray, George Otto, and Bjarne Stroustrup.

The columns would never have become a book without the help of Deborah Lafferty, Loren Stevens and Tom Stone at Addison-Wesley, and the copy editing of Lyn Dupre.

We are particularly grateful to the enlightened managers at AT&T who made it possible to write these columns and to compile this book, including Dave Belanger, Ron Brachman, Jim Finucane, Sandy Fraser, Wayne Hunt, Brian Kernighan, Rob Murray, Ravi Sethi, Bjarne Stroustrup, and Eric Sumner.

Andrew Koenig
Barbara Moo

Gillette, New Jersey
April, 1996


0201423391P04062001

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020