Recently, the
GoingNative'2012 conference, organized by Microsoft, was completed. It took place on February 2 and 3 in Redmond, and the main theme was C ++ 11. It seemed to me that this wonderful event was not fully sanctified, and wanted to correct the situation.
"C ++ 11 feels like a new language" Bjarne Stroustrup
"We're all learning C ++ 11" Herb Sutter
"We broke every single book on the planet" Herb Sutter
The coat of arms of Sutter in his opening address devoted the conference to Dennis Ritchie, the creator of the C language, and the key developer of the UNIX operating system.
This is a very important event for the C ++ community, where people who have become legends in the C ++ world, who largely determine its development, spoke and answered questions. The reports are very interesting, and I learned a lot of new things. Then there is a review of all reports and question and answer sessions.
List of speakers:
- Bjarne Stroustrup (creator of C ++)
- Herb Sutter (C ++ Standards Committee Chair, software architect at Microsoft)
- Andrei Alexandrescu (C ++ template and compute master from Facebook, one of the authors of D programming language)
- Chandler Carruth (LLVM / Clang developer from Google)
- Stephan T. Lavavej (STL master from Visual C ++ Libraries team)
- Hans Boehm (distributed to HP Labs)
- Andrew Sutton (C ++, A & M University)
I recommend to those interested in the modern state of the language these 3 speeches:
- Herb Sutter: C ++ 11, VC ++ 11 and Beyond ( link )
- Bjarne Stroustrup: C ++ 11 Style ( link )
- Stephan T. Lavavej: STL11 - Magic && Secrets ( link )
The remaining reports are also worthy of attention, but they are devoted to narrower topics (parallel programming, Clang compiler, templates, concepts). The event was decorated with two question and answer sessions. All videos and slides from the conference are available for download and viewing online on
channel 9 .
Day 1 - C ++ 11 Today - February 2, 2012
Bjarne Stroustrup: C ++ 11 Style
Bjarne talks about the strengths of C ++, a good programming style, gives many examples. An interesting comparison of the performance of the vector and the list: the result seems unexpected, and gives food for thought.
')
Hans Boehm: Threads and Shared Variables in C ++ 11
Finally, in C ++, multithreading has fallen into the standard language. The design of threads largely follows the design of the well-known library boost.thread. Casual async / future support for asynchronous calls is mentioned. There are examples of using mutexes / locks.
The main part of the speech is dedicated to Data Races. An exact definition is given of what it is in a C ++ program, and what to expect in the event of a Data Race. Much is said about the atomic types that have appeared, a comparison is made with volatile from Java, C #.
Stephan T. Lavavej: STL11 - Magic && Secrets
STL talks about the numerous innovations in the standard C ++ library:
- Index with reference counter. The “type erasure” technique. Why it is better to use make_shared to create shared_ptr
auto sp1 = make_shared<T>( args )
- Emplacement: constructing an object directly in a container
v.emplace_back("Carmichael", 3 * 11 * 17); // more efficient, easier to type v.push_back( make_pair("Carmichael", 3 * 11 * 17) );
- As a new standard, I almost broke the std :: pair, or why you should use nullptr instead of NULL
pair<X*, double> p1(NULL, 3.14);
- Futures / async, and also why it is sometimes better to transfer heavy objects by value rather than by reference
- Range-based for will appear VC11, and will be already in VC11 Beta. How it is implemented, and why it is better to use in conjunction with auto
- auto: not only easier to write, but sometimes you get more efficient code
map<string, int> m; // ? for (const auto& p1 : m) { … } for (const pair<string, int>& p2 : m) { … }
Andrei Alexandrescu: Variadic Templates are Funadic
"... After all, He-Who-Must-Not-Be-Named did great things — terrible, yes, but great."
In the presentation of the template-based metaprogramming guru, we are talking about Variadic Templates: a new feature of the C ++ 11 standard that allows you to create template classes / functions parametrized by a variable number of parameters. For example, you can now write a type-safe analogue of the printf / scanf function from C. Most likely, most C ++ programmers will never need to write something themselves using Variadic Templates, but this option is very important for library creators. The presentation will be interesting to those who want to look at the syntax used, and understand how Variadic Templates can be used.
The presentation contains 3 parts:
- It describes what Variadic Templates is, why they are needed, describes the snaxis, and shows an example of a function that determines whether the first passed argument is equal to one of the subsequent ones.
isOneOf(1, 1); // => true isOneOf(1, 2, 6); // => false isOneOf(1, 3.5, 4, 1, 2); // => true
- A simple add-on for the printf function from C is implemented, which checks the correspondence of the transferred types to the format string.
safe_printf( “%d %f”, 12.1, 1.1 ); // => throws invalid format exception safe_printf( “%d”, 1, 2, 3, 4, 5 ); // => throws too few format specifiers exception safe_printf( “%d %f”, 11, 12.1 ); // => ok, redirects to printf(…)
- A possible implementation of the class std :: tuple (from the C ++ 11 standard) is shown.
tuple<int, string, double> t; get<0>(t) = 42; assert(get<0>(t) == 42); get<0>(t) = “this will not compile”; // => compilation error get<1>(t) = "forty-two"; get<2>(t) = 0.42;
Panel: The Importance of Being Native (Bjarne, Andrei, Herb, Hans, Stephan)
Answer Questions Session:
- If C ++ is answer, what is the question?
- Does anyone do a targeted promotion of the C ++ language?
- Will there be support for modules in C ++ in the near future?
- Who will write code using Variadic Templates and then support it?
- What are the prospects for the inclusion in the standard of tools that support task-based concurrency (like PPL), computations using GPGPU, or korutin?
- What are the prospects for the emergence of the Garbage Collection in C ++?
- Will binary compatibility appear in C ++?
- How applicable is C ++ to hard real-time systems programming, kernel development
- ...
A couple of interesting quotes:
“But I think it’s a problem. We just don't generate that much garbage "Bjarne Stroustrup
"... I’m a little bit different, but I’m not sure where to go." ... Herb Sutter
Day 2 - C ++ 11 Today and Tomorrow - February 3, 2012
Herb Sutter: C ++ 11, VC ++ 11 and Beyond
Sutter promises full support for the standard C ++ 11 library in the next version of the VC11 studio, and (pleasant surprise), in the beta version, due out this month, support for range-for and final / override will appear. It is planned to release several “Out-of-band” releases (not linked to Visual Studio releases) soon after the release of VC11 with a consistently improving support for the standard: initializer lists, template aliases, variadic templates, constexpr, noexcept, = default / delete, ... Yes the opportunity to participate in the survey, which features of the new standard are most important, and I would like to see as soon as possible:
bit.ly/mscpp11 .
The second part is devoted to the new style, idioms and recommended methods of programming in C ++. Sutter argues that all books on C ++ are outdated with the release of the standard, that every example from the book can and should be rewritten in a new style: We broke every single book on the planet. At least one C ++ 11 book already exists:
bit.ly/meyers11 . Expected time to update other well-known books on C ++:
- C ++ Primer (Moo) - Aug 2012
- The C ++ Programming Language (Stroustrup) - Late 2012
- Programming: Principles & Practice Using C ++ (Stroustrup) - Late 2013
- Effective C ++ (Meyers) - 2013-2014
- C ++ Coding Standards (Sutter, Alexandrescu) - 2015
The third part talks about possible plans for the development of the C ++ standard. In his opinion, such a radical change in style, and idioms as in C ++ 11, is undesirable in the near future. At the end of the speech, the Coat of Arms effectively described the weakest side of C ++, and told what was planned to be done to correct the situation.
Chandler Carruth: Clang - Defending C ++ from Murphy's Million Monkeys
The Clang developer talks about why it was necessary to write another C ++ compiler with live gcc:
- Bad error messages
- Low compilation speed
- Technical features of gcc, making it unsuitable for building code analysis tools
- The political limitations of gcc making it unsuitable for building code analysis tools
The latest version fully supports the standard C ++ 98, and partly C ++ 11. Works on Linux, Mac. There is no Windows support, as there are not enough Windows developers among the developers.
There are many examples of problematic code in C ++, and what are the error messages and warnings that the compiler produces. It looks like an interesting static code analyzer has turned out, but there are also possibilities for analyzing behavior at run-time. Based on the compiler, very interesting means of refactoring and analyzing C ++ code are developed. For example, a
tool to remove unnecessary include .
Andrei Alexandrescu: Static If I Had a Hammer
This is a proposal to add a static_if construct to the standard language, which has worked well in the D language. It would seriously simplify some generic code that you cannot look at right now without a shudder. Here is what its use might look like:
// It – forward iterator template <class It> It rotate(It b, It m, It e) if (is_forward_iterator<It>::value) {...} // WithParent enum class WithParent { no, yes }; template <class T, WithParent wp> class Tree { class Node { ... }; static if (wp == WithParent::yes) { Node * parent_; } Node * left_, * right_; T payload_; }; Tree<string, WithParent::yes> dictionary;
Bjarne Stroustrup and Andrew Sutton: A Concept Design for C ++
The concepts are a long-suffering feature that was not included in the standard of the C ++ 11 language, and seriously delayed its adoption. Stroustrup tells how he understands concepts in language, and Sutton dwells on technical details. As I understand it, there is a desire to add concepts to the language, and the proposal will be submitted to the standardization committee. The proposal is seriously revised downwards compared to the original. This is how code using concepts might look like:
template<InputIterator I> DistanceType<I> distance(I first, I last); // template<RandomAccessIterator I> DistanceType<I> distance(I first, I last); // , random-access template<Sortable Iter> void sort(Iter first, Iter last);
Panel: Ask Us Anything! (all speakers)
Session of questions and answers. A lot of topics were touched:
- adoption to C ++
- constexpr
- shared_ptr
- reflection
- plans for C ++ next standard
- modules
- polymorphic lambdas
- writing portable code
- compiler vendors
- template exports
- concepts
- concurrency
- build time
- C ++ syntax
- refactoring tools
From the constexpr discussion:
Chandler Carruth : ... But we are not done yet. It that hard. It is a harder then variadic templates, I believe it is actually a harder then lambdas. It is one of the most challenging ways to implement correctly.
It is interesting to note that it has been more complicated than the previous bodies during the standardization.
Many thanks to the organizers and participants of the conference !!!