Saturday, March 26, 2011

Effective C++ in the C++0x (C++11) Age

Yesterday, Herb Sutter posted the truly exciting news that the new version of C++ has reached FDIS status.  Practically (though not officially) speaking, this means that the new standard for C++ is finished, and we can stop using the code name "C++0x" and start using "C++11" in its place.

I was recently informed that the German translation of Effective C++ will be reissued with a new cover as part of their "classics" series.  They asked me to write a little something about it, and I came up with a new preface that considers the relevance of the information in the book in the age of C++0x/C++11.  Given the adoption of the FDIS, plus the fact that the preface will be published only in translation, it seems appropriate to post it here:
2011 is an exciting year for C++ developers. It marks the official debut of the new standard for C++, informally known as “C++0x”. Over a dozen years in the making, C++0x makes C++ more powerful and flexible than ever. In addition to introducing major new features, such as support for concurrency, lambda expressions, move semantics, and type deduction for variables (auto variables), C++0x provides an assortment of secondary capabilities that also increase expressiveness, improve efficiency, and eliminate programming drudgework. Examples include range-based for loops, static assertions, inheriting and delegating constructors, reference-counting smart pointers, hash tables, regular expressions, variadic templates, and more. All told, the C++0x feature set is about twice that of “old” C++. Furthermore, the feature set is increasingly real: the number of C++0x features supported by modern compilers is large and growing quickly. 2011 isn't just the year when C++0x receives official ratification as a new standard, it's also the year in which it starts to see serious mainstream use.

Which may lead you to wonder whether the information and advice in this pre-C++0x edition of Effective C++ remains relevant. I'm pleased to report that it does. Surprisingly so, in fact. Having spent nearly two years steeped in the details of C++0x, I expected to groan a bit as I reviewed this book's table of contents with C++0x in mind. Surely some Items would be inappropriate. But the advice I found proved sound. Should C++0x developers prefer consts, enums, and inlines to #defines (Item 2)? They should. Should they prevent exceptions from leaving destructors (Item 8)? Certainly. Should they use objects to manage resources? Declare data members private? Consider alternatives to virtual functions? Factor parameter-independent code out of templates? (Items 13, 22, 35, and 44.) Yes, yes, yes, yes! My goal has always been for Effective C++'s table of contents to summarize the advice in the book, and that summary remains just as applicable to C++0x development as to “traditional” C++ development. C++0x is a bigger language, and in some ways it's a different one, but the core techniques for making effective use of “old” C++ are core for the effective use of C++0x, too.

This doesn't mean that this Effective C++ is a perfect match for C++0x. The book doesn't discuss features new to C++0x, so Items about making effective use of those features are missing. A C++0xified Effective C++ would certainly have Items devoted to move operations, to uniform initialization, and to lambda expressions, and it'd probably have an entire chapter on making effective use of the concurrency API. Such a book would also contain different examples, e.g., ones making use of auto variables, range-based for loops, in-class default initializers, as well as the occasional variadic template. To the extent that this book falls short in its support for C++0x, the errors are those of omission, not commission.

But Effective C++ has never claimed to be a comprehensive book. My intent has never been for it to address every aspect of the language. Rather, it has been to examine the most important aspects of C++ that affect practicing programmers on a day-to-day basis. C++0x introduces new aspects of the language that warrant discussion, but that doesn't diminish the importance of the issues I treat in this book. In fact, it may accentuate them, because effectiveness with C++0x requires mastery of the language it extends, i.e, “old” C++. As the shiny new parts of C++0x garner more and more attention, discussion of the “old” parts will recede, but those parts will still be important.

Whether you're programming in “traditional” C++, “new” C++, or some combination of the two, then, the information and advice in this book should serve you well, both now and in the future.

Friday, March 25, 2011

C++ and Beyond 2010 Presentation Materials Now Available

The official presentation materials from last year's C++ and Beyond event that I did with Herb Sutter and Andrei Alexandrescu are now available for purchase.  For the full story, please consult my post at the C++ and Beyond web site.

Scott

Monday, March 21, 2011

Neuer Schulungskurs: Effektives C++ im eingebetteten Bereich

Seit 1999 habe ich mit der Firma QA Systems daran gearbeitet, technische Seminare in Mitteleuropa (hauptsächlich in Deutschland, normalerweise im Herbst) zu halten. Wir haben versucht, fast jedes Jahr etwas Neues anzubieten. Bis zu diesem Jahr hat „etwas Neues“ immer neue Themen bedeutet, und in den letzten Jahren ist es fast voraussehbar geworden, dass die Weltpremieren meiner neuen Seminare in Deutschland stattfinden. So war es mit meinem Seminar über C++0x in 2009 und mit dem über Fastware in 2010. Für 2011 wollen wir auch etwas Neues haben, aber dieses Jahr ist es kein neues Thema. Stattdessen ist es ein bewährtes Thema – die effektive Anwendung von C++ im eingebetteten Bereich – in einer neuen Sprache: Deutsch.

Wir finden, dass es ständig Interesse an diesem Thema in Deutschland gibt, und wir glauben, dass einige Ingenieure die Informationen lieber in ihrer Muttersprache erfahren würden, auch wenn der Referent (ich) mit einem komischen Akzent spricht. Der Inhalt des Kurses ist gleich wie die ursprüngliche englische Version („Effective C++ in an Embedded Environment“), aber alles ist auf Deutsch: der Vortrag, die Folien, die Unterlagen, die Fragen und Antworten – alles.

Ich kann nicht behaupten, dass ich Deutsch so gut spreche wie  Englisch (schön wär's!), aber QA Systems und ich denken, dass wir dieses Jahr eine gute Gelegenheit anbieten, nützliche, verlässliche Informationen über die Anwendung von C++ im eingebetteten Bereich auf Deutsch zu bekommen. Wenn Sie sich für dieses Thema interessieren, empfehle ich Ihnen, dass Sie die Beschreibung des Kurses auf der QA Systems Website anschauen.  (Dort wird der alternative Titel "Effective C++ in einer Embedded Umgebung" verwendet.)

Ich hoffe, Sie bei diesem Seminar im Oktober in Stuttgart kennenzulernen.

Scott

Talks in Stuttgart in October

For the dozenth year in a row, I'll be collaborating with QA Systems on a series of one- and two-day technical seminars in Germany in the fall.  (Okay, the first year the seminars were in Switzerland, and, yes, I am aware that Switzerland is not part of Germany.)  This year's talks are:
If the title of the second seminar looks a little funny, that's probably because you're expecting it to be in English.  It's not.  Like the entire seminar, it's in German.  I'll post details about that in a separate posting that will follow this one, although I'll note here that I didn't choose the rather Denglish title above.  The title I use is "Effektives C++ im eingebetteten Bereich."

The seminars with QA Systems are always a lot of fun, with very sharp attendees asking really interesting questions.  I hope to see you at one or more of the talks I'll be giving in Stuttgart in October.

Scott

Monday, March 14, 2011

Registration for C++ and Beyond 2011 is now open!

Herb Sutter, Andrei Alexandrescu, and I will be doing an all-new C++ and Beyond in August in Banff, and registration has just opened.  If you're intrigued by the notion of getting together with some of the most interesting and experienced C++ developers on the planet, discussing how to take advantage of new C++0x language features, and exploring how to attack challenging performance problems, C++ and Beyond is an event I think you'll find worthy of your attention.  I encourage you to check out the C++ and Beyond web site for everything there is to know about the event.

Most of my posts related to C++ and Beyond go to the C&B blog, so if you'd like to follow developments related to C&B, I suggest you subscribe to its feed.

I hope to see you at C&B 2011 in Banff in August!

Scott

Wednesday, March 9, 2011

Appearing and Disappearing Articles at DDJ

The article I mentioned in my last post ("Appearing and Disappearing consts in C++") is no longer available at the URLs I provided.  In fact, it's not available at the Dr. Dobb's web site at all.  However, the PDF I submitted to DDJ is available through this link, where it will remain. The rest of this post explains why the article briefly flickered to life at DDJ and then vanished. Unless your interest in C++ extends to the process of getting something about it published, you can skip the information that follows.

I can't speak for other authors, but the way I've always worked with publishers on articles can be summarized this way:
  1. I send the prospective publisher an idea for an article, a rough draft of an article, or an essentially complete article, and I ask if they are interested in publishing it. If so, we move to step 2.
  2. We negotiate a contract for the article.  Generally speaking, I grant them certain publication rights, and they agree to pay me something for them.
  3. I deliver a final version of the article, which they then convert into whatever format will be published.
  4. They ask me to review the converted article to ensure that no errors were introduced during conversion.
  5. The article is published.
In this case, DDJ went directly from step 1 to step 5 after agreeing to publish the article, something they were able to do, because I'd submitted an essentially final manuscript, thus eliminating the need to wait for me to deliver the final copy in step 3. I found out about the publication from a friend of mine some hours after the bits went live.

I contacted DDJ and expressed my concern that they had published without our agreeing on a contract or my being given a chance to review the article for errors.  They sent a proposed contract, and I requested changes.  We went back and forth a couple of times.  They eventually decided that we would be unable to come to agreement, so they removed the article from their site.  I found out about this when somebody posted a comment to that effect to my blog, although DDJ sent official notice some time later.

As an aside, the contract negotiations didn't get hung up on money.  It was more about the kinds of rights DDJ would acquire and who'd have control over the content of the article.

 I'm sorry about the confusion about the article's location, but at least we can enjoy the irony of an article about appearing and disappearing consts itself appearing, disappearing, and now reappearing.  I still  hope you find the article interesting and useful.

Scott

Tuesday, March 8, 2011

New Article: "Appearing and Disappearing consts in C++"

It's been a couple of years since I got the itch to write a technical article, but I recently found myself thinking about types in C++ and how the language sometimes adds or removes const without your explicitly asking it to do so.  This is especially the case when it comes to new features in C++0x such as decltype and lambda expressions.  The result is "Appearing and Disappearing consts in C++" at Dr. Dobbs.  The normal online version of the article is available here, but I think the formatting they use makes it difficult to read, so I suggest you view the printer-formatted version of the article instead. 

I hope you find the article interesting and the information in it useful.

Scott