GotW

GotW logo: Thinker with birdGuru of the Week (GotW) is a series of C++ programming problems created and written by Herb Sutter.

Starting in May 2013, GotW articles are currently being revised to match the upcoming C++14 ISO Standard. The intent is to (eventually) update all of the original 88 GotWs articles, keeping the original numbers, and to write new ones starting at #89 to continue the sequence consecutively.

This page lists the GotW issues that have been revised and added so far.

GotW Archive

#94: AAA Style (Almost Always Auto). Toward correct-by-default, efficient-by-default, and pitfall-free-by-default variable declarations, using “AAA style”… where “triple-A” is both a mnemonic and an evaluation of its value.

#93: Auto Variables, Part 2. Why prefer declaring variables using auto? Let us count some of the reasons why…

#92: Auto Variables, Part 1. What does auto do on variable declarations, exactly? And how should we think about auto? In this GotW, we’ll start taking a look at C++’s oldest new feature.

#91: Smart Pointer Parameters. How should you prefer to pass smart pointers, and why?

#90: Factories. What should factory functions return, and why?

#89: Smart Pointers. There’s a lot to love about standard smart pointers in general, and unique_ptr in particular.

[… GotW issues in this range are being revised for C++14 and will appear here as they are ready…]

#7c: Minimizing Compile-Time Dependencies, Part 3. Now the unnecessary headers have been removed, and avoidable dependencies on the internals of the class have been eliminated. Is there any further decoupling that can be done? The answer takes us back to basic principles of solid class design.

#7b: Minimizing Compile-Time Dependencies, Part 2. Now that the unnecessary headers have been removed, it’s time for Phase 2: How can you limit dependencies on the internals of a class?

#7a: Minimizing Compile-Time Dependencies, Part 1. When we talk about dependencies, we usually think of run-time dependencies like class interactions. In this Item, we will focus instead on how to analyze and manage compile-time dependencies. As a first step, try to identify (and root out) unnecessary headers.

#6b: Const-Correctness, Part 2. const and mutable are powerful tools for writing safer code. Use them consistently.

#6a: Const-Correctness, Part 1. const and mutable have been in C++ for many years. How well do you know what they mean today?

#5: Overriding Virtual Functions. Virtual functions are a pretty basic feature, but they occasionally harbor subtleties that trap the unwary. If you can answer questions like this one, then you know virtual functions cold, and you’re less likely to waste a lot of time debugging problems like the ones illustrated below.

#4: Class Mechanics. How good are you at the details of writing classes? This item focuses not only on blatant errors, but even more so on professional style. Understanding these principles will help you to design classes that are easier to use and easier to maintain.

#3: Using the Standard Library (or, Temporaries Revisited). Effective reuse is an important part of good software engineering. To demonstrate how much better off you can be by using standard library algorithms instead of handcrafting your own, let’s reconsider the previous question to demonstrate how many of the problems could have been avoided by simply reusing what’s already available in the standard library.

#2: Temporary Objects. Unnecessary and/or temporary objects are frequent culprits that can throw all your hard work—and your program’s performance—right out the window. How can you spot them and avoid them?

#1: Variable Initialization – or Is It? This first problem highlights the importance of understanding what you write. Here we have a few simple lines of code—most of which mean something different from all the others, even though the syntax varies only slightly.

Temporary GotWs

The following temporary GotWs were posted in late 2011 and early 2012. As they are folded into the main sequence above, their pages will be replaced with redirect links to the permanent locations.