Home > Computing > C++11

C++11

A few days ago I attended the Going Native 2012 conference. I captured my thoughts as they were fresh while sitting on a plane going back home a few hours after the conference, later I added a summary of the current state of C++ and where it is possibly going.

The Conference

The Going Native 2012 conference was devoted to the new C++ standard, C++11. The conference was organized by Microsoft at their main campus in Redmond. The name implies a switch from languages which rely on virtual machines, like Java or .NET, back to native languages which compile into binary code natively executed by target architectures.

It was a big fun and pleasure to attend the conference. A number of distinguished speakers who are directly involved with the creation and standarization of C++ were present, the talks were very interesting and of a great value and it was all well organized. I enjoyed a lot the ability to talk to the speakers in person inbetween the talks as well as the ability to have photos taken with them.

Everything was transmitted live over the internet and also it is all available for replay, for free, which adds additional value to the conference, because everybody interested in the new standard can benefit from it.

Attendance fee was very low, so I was surprised I was able to sign up after a month and a half since Going Native 2012 was announced. I found out that many people signed up a few weeks before it took place. That was surprising, considering the low fee and the high quality content which could have been expected from the speakers.

Some speculate that Microsoft threw in this conference with this generosity to advertise that they are not abandoning C++ as many have thought based on the fact that Microsoft’s compiler in its current state is very much behind in support for the new standard. To fix this, they announced they are working hard on improving the support for the new standard in the upcoming version of their compiler. They are also planning more frequent releases to bring new features to the programmers sooner. Also their implementation of the standard library is going to be complete in the upcoming release.

Other good things about the conference – good food (nothing really to complain from my side), excellent and energizing atmosphere and the ability to meet various people and talk to them about their experiences with the language. I also came back from it with some splendid trophies.

The talks spanned over two days. On the evening of day one there was a dinner in a billiard club in downtown Bellevue.

The Speakers and the talks

Me with Bjarne Stroustrup

The most of all I enjoyed the opening keynote by Bjarne Stroustrup, the creator of the C++ language. To me his talk wonderfully explained the gist of programming in C++ – the emphasis on style. It was very down to earth and is applicable to all C++ code, esp. industrial. I have the privilege and pleasure of working with great engineers and what Bjarne touted, I see every day in our code reviews. One of the most important things when writing C++ code is to make it clean and understandable to others and to your future self. The less time you have to spend to understand the code the better the code is. This actually applies to every language, not only C++. C++11 gives the programmers new, outstanding tools which will improve the code immensely. When used correctly of course, that’s where the style comes into play.

Hans Boehm provided insight to the threading capabilities of the new standard library, which he authored. It’s great threads finally made it into the standard library. Hans gave a good introduction into the most important aspects of that new feature.

Next Stephen T. Lavavej, a.k.a. STL, gave a good speech about standard library optimizations and a few new features which are very useful in conjunction with the standard library. STL is a very interesting personality, he is notable for talking very fast and he is relatively young compared to other speakers. Smells like a genius?

Me with Andrei Alexandrescu

Andrei Alexandrescu, known for bold and ingenious use of templates, talked about variadic templates, which provide a great simplification to certain template use cases and make it easier to write functions which accept variable number of arguments. In his second talk on the second day he talked about a proposal for a future version of C++ – static if, a version of “if” which is resolved at compile time and its branches are compiled on an as-needed basis much like specialized templates. It improves the use of templates even more. Andrei also has an interesting personality, he is a great joker and showman. His talks are really fun to watch.

On the second day, Herb Sutter, the chair of the C++ standard comittee, talked about Microsoft’s Visual C++ compiler, it’s current state and future. He also pointed out a number of new C++11 features which will be immensely useful in common, every day code. In one of his short speaches he also mentioned C++ AMP, which is Microsoft’s proposed extension to C++, which allows portion of a C++ program to run on the GPUs and also leverage other kinds of parallel hardware. The extension is simple, open for other compilers to adpot and integrates well with the C++11 language, likely something like this will be added to the standard itself in the future.

Chandler Carruth, who is working on tools based on Clang, gave an introduction to the Clang compiler, which is a relatively new implementation of C++ compiler based on the LLVM backend. It is open source and rivals GCC. Among its advantages are real openness – it’s available for commercial use – and its modularity. Modularity is especially important, because you can take parts of the compiler and reuse for various purposes. Some tools being developed, based on Clang, include a tool to automatically insert minimal set of #includes or refactor C++ code, even if it is partially hidden behind macros. Another awesome feature of Clang are its diagnostic messages, which not only cleanly point out where a problem lies, even for complicated template code, but also suggest possible solutions.

I was not familiar with Clang or C++ AMP, these are two really interesting technologies which will likely affect the way we program in C++ in the near future, in a positive way.

Last but not least, Bjarne together with Andrew Sutton talked about history and current state of concepts, a feature which was not accepted into C++11 and many people miss it. Concepts are about specifying intent or template argument constraints when writing templates. The work on concepts is still not finished, Bjarne and Andrew are still working on them, but are soon going to propose them for addition to a future version of the C++ standard.

C++11 introduces a lot of useful features. The preferred ways of writing C++ programs changed. It is advantageous to use the new features to produce better code. Therefore the new standard made a lot of books obsolete in a way, books which teach C++ should focus on different features than before. It will probably take 3-5 years to release new books which will catch up with the standard. Herb promised that the commitee will attempt to not repeat this with the next version of the standard, they will mostly focus on fixes and useful additions, but without as enourmous improvements as this time.

The standards commitee also wants to address the problem of scarcity of good, portable C++ libraries or standard library features, which would integrate well with current the standard library. Their current approach is to make it easier for other contributors to submit proposals for standard library extensions and relax the strictness of reviews.

The state of C++11

My takeaway from the conference is that the C++ standard caught up with modern language features (such as lambdas, closures, threads, etc.). A lot of features which were missing for a very long time are now available. Among them are tools which significantly improve programming style by automating some tasks in the compiler instead of requiring the programmer to explicitly do them, such as the auto keyword.

The current compilers implement a subset of C++11 features. In the coming versions of Microsoft Visual C++ and GCC this will be a major subset. Less and less features are missing. It will probably take about two more years before all major compilers come with full support for C++11.

Probably even more years will pass before many projects upgrade their compilers to the latest version and will be able to leverage C++11 features. I’m hoping this will be sooner than later, because C++11 really is a better language than C++98 and code written with C++11 will statistically be better.

The future of C++

It is easy to notice the current trends in computing and where C++ is going. Future revisions of the C++ standards will provide even more expressiveness to the programmer and more opportunities for writing better and cleaner code.

The tools are also evolving and we will see faster compilers which optimize the code better than today, which issue better diagnostic messages. We will also see more tools which leverage compilers which will give us more way to modify, transform and refactor our code, which will also provide better instrumentation and other ways of detecting bugs.

We can expect more libraries for C++, either standardized or as part of the standard library, which will provide useful functionaltiy readily available for use in our programs without the need for digging the Internet or writing our own libraries. Many languages such as C#, Python, etc. come with lots and lots of libraries and allow the programmer to better leverage these languages in many fields out of the box. C++ will also gain similar capabilties.

C++ will likely be able to better leverage the architectures of today and tomorrow. The language and the standard library will include functionality similar to C++ AMP or Thrust. The programmer will be able to leverage vector instructions, multiple CPU cores and heterogenous architectures (e.g. CPU+GPU) right in the C++ code without the need of using external tools and the code will just work.

Categories: Computing
  1. JG
    7.02.2012 at 19:53

    It looks wonderful but still C++ evolution is hardly too slow. Bjarne should optimize own “native” behavior first. However slow or fast they did great job.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: