Issue # | Title and Description |
#60 (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...” |
#59 (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. |
#58 (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? |
#57 (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. |
#56 (February 2005 C/C++ Users Journal) | Order, Order. Getting the order right for a standard associative container can take a bit of thought. |
#55 (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. |
#54 (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… |
#53 (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? |
#52 (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.! |
#51 (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! |
#50 (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. |
#49 (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… |
#48 (June 2004 C/C++ Users Journal) | Getting Abstractions. Are getter and setter functions inherently evil, or are they just a little misunderstood? |
#47 (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… |
#46 (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. |
#45 (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. |
#44 (February 2004 C/C++ Users Journal) | Virtually Misbehavin'. C++ implicit overriding at work. |
#43 (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.” |
#42 (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?” |
#41 (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. |
#40 (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. |
#39 (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. |
#38 (August 2003 C/C++ Users Journal) | Factory Redux, Part 2. Continuing to revisit the Template Method factory, with a generic<twist> to it. |
#37 (July 2003 C/C++ Users Journal) | Factory Redux, Part 1. Revisiting the Template Method factory, with a generic<twist> to it. |
#36 (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... |
#35 (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. |
#34 (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. |
#33 (March 2003 C/C++ Users Journal) | Once Is Not Enough. Some reasons why the ubiquitous Singleton Pattern is, perhaps, a little too ubiquitous. |
#32 (February 2003 C/C++ Users Journal) | Points of Order. Of shoes, socks, arguments, and locks: Why order is important in programming as in life. |
#31 (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. |
#30 (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. |
#29 (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. |
#28 (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. |
#27 (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. |
#26 (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. |
#25 (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. |
#24 (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. |
#23 (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? |
#22 (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... |
#21 (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... |
#20 (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. |
#19 (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? |
#18 (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. |
#17 (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. |
#16 (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. |
#15 (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? |
#14 (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. |
#13 (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". |
#12 (June 2001 C/C++ Users Journal Experts Forum) | Abstract Factory, Template Style. Using templates to generalize a class factory. |
#11 (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. |
#10 (April 2001 C/C++ Users Journal Experts Forum) | Manipulations. How to write a simple IOStream manipulator to quote and unquote strings. |
#9 (March 2001 C/C++ Users Journal Experts Forum) | Redirections. How to go about redirecting output to cout/cerr using streambufs. |
#8 (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. |
#7 (January 2001 C/C++ Users Journal Experts Forum) | Obelisk. Perils of writing "monolithic" code. |
#6 (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. |
#5 (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. |
#4 (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. |
#3 (July/August 2000 C++ Report) | Genesis. How we got here from there: A colorfully rendered history of the C family of languages. |
#2 (June 2000 C++ Report) | Null References. Can references be null? Case in point: A factory that returns a pointer to the newly created object. |
#1 (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... |