Reader Q&A: Book recommendations

Vigen Isayan emailed me today to ask:

What book(s) you would recommend for learning

1. design patterns, and

2. concurrency programming.

Off the top of my head:

1. For Design Patterns, the greatest is still the original “Gang of Four” Design Patterns book. The design patterns are mostly universal, and the implementations happen to focus on OO techniques (dynamic run-time virtual dispatch etc.) but you can also express many of the patterns using generic programming (static compile-time templates etc.) – for example Observer becomes really simple. The book is almost two decades old, has inspired huge numbers of follow-on patterns books, and there’s still none better of its kind that I know of.

2. For concurrency (and parallelism), check out my 33 articles on Effective Concurrency. I hope to assemble them into a book in the near future. In the meantime they’re all out there online freely available.

If you have additional recommendations, please post them in the comments. Thanks.

On a personal note

Speaking of the Gang of Four, here’s a personal story I don’t know if I’ve shared on the blog before:

At the time it first came out, I was working in downtown Toronto. We had a really excellent local bookstore that specialized in programming books and magazines (alas, it’s long gone now). On lunch breaks, I would go there to browse and get new books to absorb. Note that this was before I was a published author myself, and I had no idea about major new books coming out, so I had no warning of what was about to happen.

On one day that at first seemed like any other, at lunchtime I was browsing the shelves as usual, and I saw copies of a white and blue hardcover book I’d never seen before. Curious, I picked up a copy. It had an unusual title, Design Patterns. I had never heard of the book or its authors before, knew nothing about it at all, and so was quite unsuspecting when I opened it and something happened that I had never experienced before and haven’t experienced since (so far):

I opened that book for the first time, stood there paging through it for less than five minutes, and knew immediately and profoundly that I was holding a classic in my hands. The realization was so unexpected and surprising, it hit me almost physically. At first sight, it was as easy to recognize this book as an important leap forward as the first you see an airplane flying in the sky. Scales fell from my eyes: Cataloguing OO design problems and their known solutions! Imagine!

I had already learned a few of the patterns on my own here and there, some through hard work and experience, others by combining ideas from various articles, many by working with experienced colleagues. But suddenly I found myself standing there in the bookstore aisle just absorbing one problem and solution after another after another, and feeling my understanding begin expanding. Even the patterns I sort of knew about were explained with concise clarity: Motivation, the problem and the specific constraints on the solution which are so important because they affect the design. Known solutions. Variations with tradeoffs.

Bliss! No, more than bliss — treasure.

This must be what explorers and hunters feel like when one day unexpectedly they discover an unopened and unransacked tomb of a young Egyptian Pharaoh, a sunken treasure galleon filled with precious cargo and artifacts, or a cave near the West Bank containing well-preserved two-thousand-year-old scrolls of important literature.

And Design Patterns was language-agnostic, to boot.

Nineteen years later, it’s still at the top of my list of design books to recommend.

Disclaimer: Something this profound inspires a whole new subculture. Later “pattern” wannabe books often went way, way, way overboard, some of them almost to the border of quasi-mysticism. Ignore most (not all, but most) of the follow-on pattern books. Only a few are worth your time; read the reviews carefully first.

Visual C++ Compiler November 2013 CTP

We just shipped Visual C++2013 last month, but I announced at GoingNative in September that there would be more soon: another CTP (compiler preview) containing another batch of C++11/14 features, sometime in the fourth quarter.

I’m happy to report that today we shipped the promised CTP. Compared to the “high probability in CTP” feature set I mentioned in my GoingNative talk, one of those features I mentioned didn’t quite make it (C++14 generalized lambda capture, a.k.a. move capture and more), but to compensate, both medium-probability features made it (C++14 generic lambdas and C++11 inheriting constructors) plus, as a bonus, also alignof and alignas which we didn’t think would make it for the CTP but did. Here’s the full set of new features, pasting from the announcement:

  • Implicit move special member function generation (thus also completing =default)
  • Reference qualifiers on member functions (a.k.a. “& and && for *this“)
  • Thread-safe function local static initialization (a.k.a. “magic statics”)
  • Inheriting constructors
  • alignof/alignas
  • __func__
  • Extended sizeof
  • constexpr (except for member functions)
  • noexcept (unconditional)
  • C++14 decltype(auto)
  • C++14 auto function return type deduction
  • C++14 generic lambdas (with explicit lambda capture list)
  • (Proposed for C++17) Resumable functions and await

The most-requested feature of C++14, and the one I’ve personally been anticipating the most, is generic lambdas — it is sweet to see it working right within Visual Studio 2013, as the CTP installs as a selectable toolset you can use within the shipping product to edit and build (no Intellisense or red squiggles though). Note that for this CTP, your lambda can be either generic (have an auto parameter type) or have a default capture list (e.g., [=] or [&]), but not both — of course we’ll support both together in the future as the feature makes a future release.

As far as I know, this Visual C++ CTP is the first shipping (albeit CTP quality) C++ compiler to offer generic lambdas, though I expect Clang and gcc to also make them available soon — joy for C++ developers everywhere!

Once again, thank you very much again to the great Visual C++ team for producing this CTP; even as we speak, they’re hard at work on more. Thanks again also to the other members of the ISO C++ committee for producing a great and high-quality C++11 and soon-to-be-not-draft C++14.

I hope you enjoy trying out this CTP.

(V)C++ recorded talks at VS 2013 Launch

As part of today’s VS 2013 launch, in addition to the live talks and Q&A we also have some recently recorded talks that are now also live. My talk is a quick 20-minute tour of the new ISO C++ conformance features in VC++ 2013 — nothing I haven’t said before, so if you’ve seen my last two Build talks you’ve seen this material, only here I’ve condensed it to a distilled two-minute overview of each feature using examples.

Here they are, each between 4 and 20 minutes long. Note that these are just the (V)C++-specific topics — be sure to look at the Related Videos of each to see other new features that light up for C++ as well as for other languages.

ISO C++ Additions in Visual C++ 2013 (Herb Sutter)

ISO C++ received a major upgrade with the latest standard, adding many features that make the language both simpler and more powerful. Visual C++ 2010 and 2012 have already implemented a number of these features, from auto to range-for to lambdas.  In this video, Herb Sutter reviews the additional ISO C++ standards conformance improvements in Visual C++ 2013, and how each of them contributes to making modern C++ code clean, safe, and faster than ever.

​What’s New for C++ Developers in Visual Studio 2013 IDE​ (Jennifer Leaf)

Visual Studio 2013 includes several compelling new features for C++ developers.  In this video, you’ll learn about IntelliSense improvements, the new code formatting feature, and other changes that help you navigate through and write your code.

New Compiler Optimizations for C++ Applications (Jim Hogg & Ankit Asthana)

C++ developers will find many improvements in Visual Studio 2013 — including new versions of the compiler, linker and tools — that make code run faster.  In this video we’ll cover C++ performance improvements, including better vectorization; permutation in the order of loop nests; better Profile-Guided Optimization (that now applies to Windows Store apps); a new vector calling convention; and more support for C++ Accelerated Massive Parallelism (AMP).

Debugging Improvements for C++ Developers (Brad Sullivan)

Visual Studio 2013 includes numerous improvements for debugging C++ applications.  In this video we’ll demo two of these features: Just My Code and JavaScript/Native Interop Debugging.

Introducing Visual Studio 2013 for Windows Developers Building C++ Apps (Raman Sharma)

Visual C++ in Visual Studio 2013 includes improvements for Windows App developers in the core language and libraries, as well in tooling, debugging and designers.  This video will provide an overview of these new features in Visual Studio 2013 for C++ developers building Windows Store apps.

Live Visual C++ Q&A today

As part of the VS 2013 launch today, in a few hours I will be joining Tarek Madkour and Ale Contenti on camera for about half an hour to answer questions about VC++2013. Tarek and Ale are two of the three-manager triad who run our VC++ team.

Visual C++ in 2013 and Beyond

with Charles Torre, Ale Contenti, Tarek Madkour, and Herb Sutter

Date: November 13, 2013
Time: 12:45pm PST (approx.)

I believe the session will be recorded and available on demand in a couple of days.

Reminder: VC++2013 upgrade SKU available until end of January

Recap: Back in June, Microsoft:

  • announced that were were moving to a faster cadence and shipped VS 2013 one year after VS 2012;
  • announced that new ISO C++ conformance features from the November 2012 CTP (and more) would be available in VS 2013, but not in VS 2012 Updates; and
  • didn’t announce pricing for VS 2013, so people who had just paid for VS 2012 Professional (only that specific SKU) were concerned that they might be charged full price again for VS 2013 Professional. (This applies to Professional only, because all other SKUs get free upgrades anyway — Express is always free, and Premium and Ultimate are subscription-based with free upgrades included in the subscription.)

I just want to remind anyone who bought VS 2012 Professional that when the actual pricing was announced last month, it was announced that to ease the transition there would be a limited time promotional upgrade from VS 2012 Professional to VS 2013 Professional for $99, available from early November (now) until the end of January. You can wait until after the holidays to decide whether you want it, but I thought I’d just give another heads-up about the time limit if this upgrade matters to you.

I hope this is a good value, as VS 2013 has lots of new features for C++ users beyond just the additional ISO C++ conformance: lots of editor improvements from simple things like brace completion and parameter-sensitive Intellisense to the (IMO cool) enhanced scrollbar and peek definition; C++ AMP improvements; optimization improvements including a smarter auto-vectorizer; and much more. See this blog post for an overview of what’s new in VC++ 2013 — the team did a lot in just one year, and thank you again to everyone who helped to make this happen!

What’s next for Visual C++:

  • At Build and GoingNative, we announced that a preview CTP of the next batch of C++11/14 language features will be available this quarter. We’re still on track for that. Watch vcblog and this space for the announcement.
  • Tomorrow is the VS 2013 virtual launch. Given that we already shipped the product itself a month ago so that you already have it in your hands, is there any reason to watch the launch? Short answer: Yes, I think you’ll find it interesting and worth your while.

Reader Q&A: Acquire/release and sequential consistency

Reader Ernie Cohen emailed me this morning to ask a question about one slide in my atomic<> Weapons talk from last year’s C++ and Beyond:

In your atomic weapons talk (part 1) (updated 2/15/2013) ,page 18, titled “Sc > Acq/Rel Alone: Some examples”, the first example listed “transitivity/causality”:

T0: g = 1; x = 1;

T1: if (x == 1) y = 1;

T2: if (y == 1) assert(g == 1);

I understood you to mean that the assertion might fail if the loads were simple C++11 acquires and the stores were simple C++ releases. But this works just fine with the weaker memory order; the operations in each thread are related by sequenced-before, the communications between the threads create happens-before, and without consumes happens-before is transitive, so there is a happens-before edge from g = 1 to the assertion. Am I missing something?

[Note: g is an ordinary variable, x and y are std::atomic, and all initially zero as usual.] The motivation behind this example, and the other example on the same slide, was to show that when we specified the C++ memory model and atomics, we had to consider more than individual acquire-release pairs in isolation, but also provide additional guarantees to ensure that the whole program was sequentially consistent (SC).

In the above example, yes, we guarantee that the assertion cannot fail with C++ acquire and release semantics, and making sure the memory model required this transitivity is exactly one of the two key points of this example. As you point out, it requires getting the “right” answer when combining sequenced-before and happens-before.

The second point illustrated here is that it was essential to support cases where the programmer could depend on reasoning based on tests of whether a particular write was read and then making SC assumptions based on the outcome of the test, otherwise the whole program wouldn’t be SC.

For completeness, the other example on the slide showed an additional case where individual pairwise acquire/release alone was insufficient to guarantee SC outcomes unless we added requirements. Here is the example, with x and y std::atomic and initially zero:

T1: x = 1;

T2: y = 1;

T3: if( x == 1 && y == 0 ) print( “x first” );

T4: if( y == 1 && x == 0 ) print( “y first” );

This illustrates the total store order requirement: It must be impossible to print both messages, else the result wouldn’t be SC.

Note that in most cases using (non-SC) memory_order_acquire and memory_order_release explicitly happens to give you SC results, except when they don’t (e.g., Dekker’s fails, and I think the second example above fails as well). And of course other relaxed atomics can allow non-SC results at the drop of a hat.

Bjarne and I are speaking in Chicago on Tuesday night

Bjarne Stroustrup and I are giving back-to-back talks on Tuesday night in Chicago, while we’re both in town for the standards meeting next week. Admission is free. Register by email here (and ignore the “it’s full / sold out” note on the page — see below.)

Note that my talk will be 80% new material followed by the last 5-10 min of my GoingNative 2013 keynote, so even if you’ve seen that talk most of the material will be new. Here are the coordinates:

A joint Chicago Chapter ACM and Chicago C/C++ Users Group meeting

Broad-spectrum C++/C++14 (Bjarne Stroustrup)

One C++ (Herb Sutter)

Tuesday, September 24, 2013
Doors open approximately 6:30 pm
Presentations run 7:00 pm – 9:30 pm

Renaissance Chicago Downtown Hotel
1 West Wacker Drive, Chicago, IL 60601
Room A/B [or a nearby larger room, just follow the crowd when you arrive]

Note: The page says the event is at capacity and the primary registration link balks, but there is space because they keep expanding the room — it has already expanded from the original 100 seats to 200 and currently 300 seats, and they’re looking into moving to a still larger room as we speak. So do add yourself to the waiting list via this email link as it looks likely you will still be able to get in.

Reader Q&A: “Will C++ remain indispensable…?”

A reader wrote me today to ask the following. Since this is a FAQ, I thought I’d post the answer here.

With the advent of C++11 and upcoming C++14 and C++1y, the language has strapped much of the digital electronics industry under its belt. High performance software, Libraries, Embedded, Research, Web backends, our everyday software, and trivial systems; Everything directly or indirectly depends on C/C++.

My question is -: Will C++ remain indispensable for creating above mentioned class of production software for very long foreseeable future ?

Short answer: Yes, but don’t stop there because that’s not all of what C++ is about!

Expanding on “Yes”: Yes, I think so. The main reason is that several long-term industry trends now in progress favor C++’s core strength of “efficiency per Watt/cycle/transistor + full flexibility and control” in a portable language. For example, for mobile (notebook, tablet, phone) and cloud datacenter (Facebook, Google, etc.) app environments, both of which are clearly large and will continue to experience long-term growth, the critical measure has already switched to “performance per Watt”… if that’s your primary constraint and cost, you’ll usually end up at either C or C++, and the latter gives you stronger abstraction. And performance per Watt is just one example; besides that one, as other trends like the power wall and the eventual end of Moore’s Law continue to grind out, the value proposition of “performance per Watt/cycle/transistor + full flexibility (to express what you need) and control (over hardware and things like memory layout)” will remain valuable in the long term.

Expanding on “but don’t stop there because that’s not all of what C++ is about!”: Old C++ used to be harder, but today modern C++ is far from limited to those categories. As I pointed out my “One C++” talk last week (start around the 42:00 mark), C++ is already a de facto standard language to teach artists (not professional programmers) in the world’s top design schools such as Parson’s, notably using C++ plus the openFrameworks library, and C++ is also a widely used library outside schools for creative interactive applications (again often by people who are not programmers by training), notably using C++ plus the Cinder library.

Other languages are important and useful too, and often are built on top of C++, and that’s great – there is no such thing as “one language fits all,” and everyone realizes that like any language C++ is not for everyone or every use. Nevertheless, C++ is very horizontal, meaning usable in many domains, and the cases where C++ is applicable and actively used is growing, not shrinking; one effect is that we have to relearn what a “C++ programmer” is because that group is getting increasingly diverse. As we continue to make C++ more accessible, I expect we will continue to hear about its being used more and more even by people we didn’t expect, like artists and financial gurus who are not programmers by training and whom we never used to think of as C++ programmers… it’s happening already.

My “One C++” talk from GoingNative is now posted

I see the recording went live this morning. Thanks again to all the speakers and in-room and worldwide attendees for coming and watching!

Day 2 Keynote: One C++

Herb Sutter

My favorite part was seeing the response to the challenge to write a cool graphical interactive C++ program from scratch in 24 hours using a library most had never seen before – Cinder or openFrameworks. In two other GN segments we showed the results. Here’s they are:

Herb’s UI Challenge Results

My Favorite C++ 10-Liner, plus UI Challenge Results Part 2 / Closing comments

Thank you all for coming! It was a blast.