Home Blog Talks Books & Articles Training & Consulting


On the
RSS feed November 4: Other Concurrency Sessions at PDC
November 3
: PDC'09: Tutorial & Panel
October 26: Hoare on Testing
October 23
: Deprecating export Considered for ISO C++0x

Conversations (a.k.a. Conversations With a Guru) is a series of 60 narrative C++ programming articles coauthored by Herb Sutter and Jim Hyslop. If you enjoy a dose of interesting characters along with your code, check it out. The Conversations column began in 2000 as a regular print column in C++ Report and continued in C/C++ Users Journal through July 2005, when it ended at installment #60.

The articles can generally be read in any order. For the first 23 issues only, each article additionally had a framing science-fiction story set in the future, whose characters reminisced to introduce the main retrospective C++ topic set in today's present. Readers interested in following the science-fiction plot, or in the central story's early character development, should read those articles in sequence.

Conversations book: Due to sustained reader feedback and requests for a Conversations book, the authors are contemplating reworking and compiling the 60 columns into book form sometime in the future. If you're interested in that, watch Herb's Blog as well as the News page on this site for details as plans gradually firm up.

Conversations Archive (Most Recent First)

Issue #Title and Description
(July 2005 C/C++ Users Journal)
Graceful Exits. When you detect an error or invalid state in a function, what’s the best way to handle it: return an error code, throw an exception, or call assert()? Well, as is frequently the case, the answer is “that depends...”
(May 2005 C/C++ Users Journal)
Logically Shallow Views. const is logical, not physical; shallow, not deep; and a promise on the view, not necessarily a promise on the object.
(April 2005 C/C++ Users Journal)
Polymorphic Exceptions. What do you do when you want to throw an exception, the exception object is a derived class, but all you have is a reference to the base class?
(March 2005 C/C++ Users Journal)
Implicit Virtual. One person’s “bug” is another person’s “feature.” This month, we consider the implicit nature of virtual and how it can produce cool or unsettling results in your code, depending on your point of view.
(February 2005 C/C++ Users Journal)
Order, Order. Getting the order right for a standard associative container can take a bit of thought.
(January 2005 C/C++ Users Journal)
Tagged Unions. Some of our C heritage is slim and fast—and fragile—in the name of performance. Unions are such a beast.
(December 2004 C/C++ Users Journal)
Alias. When are two variables really two variables? When the real problem can be aliasing, don’t be too quick to blame macros…
(November 2004 C/C++ Users Journal)
Adaptations. Say you're using multiple inheritance and each of two base classes has a virtual function with the same name. You want to provide separate overrides for each function, to be called in the context of the specific override. How do you do it?
(October 2004 C/C++ Users Journal)
Friendly Nesting. This month, we consider why nested classes should (but don't) have access to the members of their enclosing class, and what the committee is doing about it.!
(September 2004 C/C++ Users Journal)
Typedefs and Iterators: If you've Got 'Em, Use 'Em. Typedefs do more than just reduce clutter and save keystrokes; they can help smooth the transition when requirements change. Iterators are an even more powerful tool for implementation hiding and reducing coupling due to container choices. But both techniques can only help if you actually use them!
(August 2004 C/C++ Users Journal)

Collecting Shared Objects. Avoid using bald pointers. Avoid using auto_ptr, instead use shared_ptr which is widely available and being added to the standard library. Store only values and smart pointers in containers; specifically, use either a container<value_type> to hold objects directly by value and ensure that they really do have value semantics, or else use a container< some_refcounted_smart_ptr<any_type> >, preferably a container< shared_ptr<any_type> >. If you don't, you'll wish you had.

(July 2004 C/C++ Users Journal)

Delete This Thread? Are self-deleting objects a good idea? Could they be inherently thread-unsafe? As with many thread-safety issues, a careful analysis is needed, and in this case will reveal there is no problem but only a design decision. Bob, alas, is not known for careful analysis…

(June 2004 C/C++ Users Journal)

Getting Abstractions. Are getter and setter functions inherently evil, or are they just a little misunderstood?

(May 2004 C/C++ Users Journal)

Enumerations. As Stroustrup himself once wrote: “C enumerations constitute a curiously half-baked concept.” And C++ enumerations are only slightly better…

(April 2004 C/C++ Users Journal)

Using Me. The using directive is a contentious feature -- more contentious, in fact, than it needs to be. If you choose to use it, this article examines some rules and guidelines around its use.

(March 2004 C/C++ Users Journal)

Im-Paired Programming. std::pair can make your life easier. But as with many things, moderation is the key: excessive use can lead to unmanageable code.

(February 2004 C/C++ Users Journal)

Virtually Misbehavin'. C++ implicit overriding at work.

(January 2004 C/C++ Users Journal)

Of Many Things. “The time has come,” the Walrus said, “to talk of many things. Of std::string -- and magic numbers -- and constness in references.”

(December 2003 C/C++ Users Journal)

Reusing Streams. There once was a stream reuse style / After close() to re-open() a while / And the questions grew hot: / “Will it open or not? / Is the style ‘clearly’ vile, or worthwhile?”

(November 2003 C/C++ Users Journal)

Pointing in the Right Direction. What’s in a pointer? Not much, really. Raw pointers invite memory leaks – because they cannot tell the programmer how they should be handled.

(October 2003 C/C++ Users Journal)

Self-Sufficient Headers. A good C++ (and C) coding standard is that every header file should be self-sufficient. But is it always so? This article looks at the coding standard, how it applies in the presence of templates and member templates, and how nonmember functions can improve modular dependencies in addition to encapsulation.

(September 2003 C/C++ Users Journal)

From C++ to Shining C. So you have a C++ type, and you have a C program that wants to use it. Is it a case of “never the twain shall meet,” or can true objects be reasonably exposed to non-object oriented languages? The twain can indeed meet, and this article shows how.

(August 2003 C/C++ Users Journal)

Factory Redux, Part 2. Continuing to revisit the Template Method factory, with a generic<twist> to it.

(July 2003 C/C++ Users Journal)

Factory Redux, Part 1. Revisiting the Template Method factory, with a generic<twist> to it.

(June 2003 C/C++ Users Journal)

Imagine. If you want to write portable code, you're going to need a lot of conditional compilation -- #if this, #else that --, right? Imagine if that were not the case...

(May 2003 C/C++ Users Journal)

Delegating Constructors? Delegating constructors aren’t (yet) supported in the C++ Standard. This article demonstrates the common technique that gets us most of the way there in Standard C++, and its drawbacks. It also demonstrates that Standard C++ does allow two apparent “workarounds” that may look good at first, but which are bad and atrocious, respectively – one of them is a simple mistake, the other an outright appeal to Machiavelli.

(April 2003 C/C++ Users Journal)

Sharing Causes Contention. Following up on themes introduced in the two preceding Conversations columns, the Guru demonstrates why needless sharing might be considered harmful.

(March 2003 C/C++ Users Journal)

Once Is Not Enough. Some reasons why the ubiquitous Singleton Pattern is, perhaps, a little too ubiquitous.

(February 2003 C/C++ Users Journal)

Points of Order. Of shoes, socks, arguments, and locks: Why order is important in programming as in life.

(January 2003 C/C++ Users Journal)

Value Lessons. When is an object not an object? When it is a value. Knowing when to use value types and when to use object types can simplify your design.

(December 2002 C/C++ Users Journal Experts Forum)

It's an Object-Ful Lifetime (by Jim Hyslop). References, temporaries, and accidental references to temporaries... a full stomach can make one dream up all sorts of creative problems and solutions.

(November 2002 C/C++ Users Journal Experts Forum)

Truth or Consequences. What’s wrong with using bool as a parameter? There are usually better ways to express what you mean. This month we turn to an expert who died before Stroustrup was born.

(October 2002 C/C++ Users Journal Experts Forum)

Contracts, Promises, and Mere Semantics. What is a function saying when it takes a parameter by pointer, by reference, or by value? When interface idioms lie, sometimes there's no graceful way to avoid the surprises.

(September 2002 C/C++ Users Journal Experts Forum)

Baseless Exceptions. Implicit conversion sequences can be quite useful. But there are... well... exceptions to when they are applied.

(August 2002 C/C++ Users Journal Experts Forum)

A Midsummer Night's Madness. What do you get when you add a pointer to a typedef and mix in const? The Guru puts in her thoughts on the matter.

(July 2002 C/C++ Users Journal Experts Forum)

Getting to the Point. While the standard auto_ptr provides a safer alternative to raw pointers, it has its limitations, and some surprising behavior. The Guru helps out by giving the narrator a boost – library, that is. The Boost library has five smart pointers that provide a rich array of useful behavior.

(June 2002 C/C++ Users Journal Experts Forum)

The Good, the Bad, and the Deprecated. What can go wrong when your code gives you a bit too much... er... static.

(May 2002 C/C++ Users Journal Experts Forum)

Making a Real Hash of Things. Speed often does matter. But what kind of "speed" is important when it comes to associative containers?

(April 2002 C/C++ Users Journal Experts Forum)

To Sleep, Perchance. Just how many threading and streaming mistakes can arise in one poor little dozen-line function? Quite a few, and that's not even counting the magic...

(March 2002 C/C++ Users Journal Experts Forum)

Template Specializations, Default Parameters, and Other Fun Stuff. Many people know how to partially specialize a template. But what happens when the base template has a template parameter with a default value? The answer may not be quite what Bob expected...

(February 2002 C/C++ Users Journal Experts Forum)

New Bases, Part 2. Basic reading and writing from a standard stream sounds simple, but can harbor its share of little complexities. Here is a simple example, with notes about the kinds of complexity that can usually be deferred.

(January 2002 C/C++ Users Journal Experts Forum)

New Bases, Part 1. Converting a text-represented number from one base to another is pretty simple. But how extensible and reusable can the solution be to solve more than one problem, when there are also additional requirements?

(December 2001 C/C++ Users Journal Experts Forum)

I'd Hold Anything for You. There are occasions when you have a variable whose type you don't know until run time. Thanks to the Boost library, there is a safe alternative to fragile union- or void*-based solutions.

(November 2001 C/C++ Users Journal Experts Forum)
Hungarian wartHogs. What's in a name? Plenty, if you use Hungarian notation. Too much, if you use Hungarian notation.
(October 2001 C/C++ Users Journal Experts Forum)
Al-Go-Rithms. The Standard C Library contains some functions that are still useful in C++. Sometimes, though, you need to find your own 'rithm – algorithm, that is.
(September 2001 C/C++ Users Journal Experts Forum)
Back To Base-ics. When you are adding a new class to a project, and that class is very similar to an existing class, you will frequently have three options: publicly derive one class from the other; create a common base class from which both the new and existing classes will be derived; and implement one class in terms of the other class. What is the best way to choose among the three options?
(August 2001 C/C++ Users Journal Experts Forum)
The Bind That Ties. The Standard Library provides adaptors that extend the flexibility and power of the standard functions. While some of them may seem scary at first glance, they really are quite simple to use.
(July 2001 C/C++ Users Journal Experts Forum)
How to Persist an Object. In this article, our narrator learns that object persistence can be easily implemented, especially when it's hooked up to the factory method template -- see the June 2001 "Conversations".
(June 2001 C/C++ Users Journal Experts Forum)
Abstract Factory, Template Style. Using templates to generalize a class factory.
(May 2001 C/C++ Users Journal Experts Forum)
Roots. Why can't a Derived** be assigned to a Base**? A peek beneath the covers of the C++ object model.
(April 2001 C/C++ Users Journal Experts Forum)
Manipulations. How to write a simple IOStream manipulator to quote and unquote strings.
(March 2001 C/C++ Users Journal Experts Forum)
Redirections. How to go about redirecting output to cout/cerr using streambufs.
(February 2001 C/C++ Users Journal Experts Forum)
Access Restrictions. Stirring the debate about public data vs. accessor methods: the latter are safer, just as fast when inlined, and can have nicer syntax if operator overloading is appropriate.
(January 2001 C/C++ Users Journal Experts Forum)
Obelisk. Perils of writing "monolithic" code.
(December 2000 C/C++ Users Journal Experts Forum)
Virtually Yours. An application of the Template Method pattern, and a discussion of when to use public vs. protected vs. private virtual functions.
(November 2000 C/C++ Users Journal Experts Forum)
By Any Other Name. Applying the Visitor pattern: How to add a virtual function to a hierarchy without changing the hierarchy.
(September 2000 C/C++ Users Journal Experts Forum)
So Who's the Portable Coder? Writing portable code. Case in point: Scope of variables declared in a for-init-statement.
(July/August 2000 C++ Report)
Genesis. How we got here from there: A colorfully rendered history of the C family of languages.
(June 2000 C++ Report)
Null References. Can references be null? Case in point: A factory that returns a pointer to the newly created object.
(April 2000 C++ Report)
Re-membering auto_ptr. A class with an auto_ptr member: How can copying go wrong? Let us count the ways...

Copyright © 2009 Herb Sutter