bjarne stroustrup video lecture c++0x iso standard c++09 iconWhile browsing my favorite programming news site programming.reddit.com, I stumbled across this link to a video lecture on C++'s upcoming standard C++0x by Bjarne Stroustrup.

You can start watching it right away or you can download it in DivX or MPEG and watch it later.

I have a great interest in the C and C++ family of programming languages and their history, and I have read two of Bjarne's books - C++ Programming Language and The Design and Evolution of C++. I enjoyed every page of these books and they made me not only a decent C++ programmer but also made me understand how the language was formed, what its goals were, where it was headed, and how the language got various constructs it has now. If you ever consider becoming a great C++ programmer, these books are a definite read.

The most fundamental things these books taught me was to think think of various levels of abstraction and approaching a given programming problem from various programming paradigms.

When I found the link I put aside all the things I was working on and started watching the video lecture. I love C++ that much!

A note aside for people wanting to learn C++. I see people argue on programming.reddit.com and other sites that C++ is not worth learning, that it's a dead language and X is better than C++, etc. Don't listen to this crap! If you ever watched Guy Kawasaki's presentation The Art of the Start, the 11th point of success is "Don't let the bozos grind you down." That's what all these bozos on Reddit are trying to do. Don't listen to them; just start learning C++ and you will succeed.

Now, back to the lecture. Here, I cite what the lecturer has to say about his lecture:

A good programming language is far more than a simple collection of features. My ideal is to provide a set of facilities that smoothly work together to support design and programming styles of a generality beyond my imagination. Here, I briefly outline rules of thumb (guidelines, principles) that are being applied in the design of C++0x. Then, I present the state of the standards process (we are aiming for C++09) and give examples of a few of the proposals such as concepts, generalized initialization, being considered in the ISO C++ standards committee. Since there are far more proposals than could be presented in an hour, I'll take questions.

Just like I did while learning JavaScript from video lectures, I am going to timestamp blog about most interesting things that caught my attention.

Here are the things that caught my attention in Bjarne's C++ video presentation. Time in the brackets is when it appeared on the video. '+' before the brackets indicate that I knew it already, '-' that I didn't (just for personal notes). I will write down some obvious facts about the language even though I know them, so you got an idea what the lecture was about.

  • +(03:25) C++ is used on both Mars rovers, Spirit and Opportunity. Design life of the rowers was 6 months.
  • +(05:30) C++ is a better C in a way that it can roughly do the same as C but also has many new features
  • +/-(06:55) Highest level goals of C++ are to make it a better language for systems programming and library building and make it easier to teach and learn.
  • (08:46) Joke: The next Intels will execute infinite loop in five minutes and that's why you don't need performance.
  • +/-(10:00) The main problem for a new revision of the standard is the popularity of C++. Existing and new users want countless improvements. Adding a new feature needs to keep the existing code absolutely stable. Each new feature makes the language harder to learn.
  • +(15:46) The current C++ ISO standard is from 1998, with a revision in 2003.
  • (15:50) Joke: If you can tell the difference between C++ 1998 and C++ 03, then you have just been reading too many manuals.
  • (16:36) Joke: Some of C++ language developers working on C++0x are very, very keen to get that x to be a decimal number.
  • +(17:20) Voting on C++ standard features is done nation-wide. Each nation casts one vote.
  • +/-(19:14) Standardization matters because it directly affects millions of peoples, new techniques need to get into mainstream use, it's a defense against vendor lock-in
  • +/-(22:10) Rules of thumb for the standard:
    • Maintain stability and compatibility,
    • Prefer libraries to language extensions,
    • Prefer generality to specialization,
    • Support both experts and novices,
    • Increase type safety,
    • Improve performance and ability to work directly with hardware,
    • Fit into the real world,
    • Make only changes that changes the way people think.
  • -(30:28) There are around 100 new proposals for language features.
  • -(33:22) There are much less library proposals. Just 11 new proposals for Library TR1!
  • -(35:47) Areas of language change are machine model and concurrency, modules and DLLs, support for generic programming.
  • +(38:01) Vector initialization problem example.
  • (40:50) Even Bjarne made an error when using the verbose syntax for initializing a vector with a list of values from an array:
    bjarne vector initialization mistake int double
    "If you have tedious, verbose and indirect code, you make mistakes!"
  • -(41:09) Indirect vector initialization from arrays violates Stroustrup's language design principle (from The Design and Evolution of C++) - "Support user-defined and built-in types equally well."
  • -(41:56) C++0x solution to initialization problem are initialized lists, std::initializer_list<type>.
  • -(43:43) There are too many ways to initialize things in C++ and they work in various contexts, C++0x introduces uniform initialization syntax which can be used in any initialization.
  • -(46:50) Fundamental cause of lots of problems in C++ with generic programming is that the compiler doesn't know what template argument types are supposed to do.
  • +/-(49:30) C++ 98 got templates right in a way that parametrization didn't require hierarchies, parametrization could be done with non-types, the code generated had uncompromising efficiency and that it turned out that template instantiation was Turing complete!
  • -(54:42) Concept aims of C++0x are direct expression of intent (lecture got cut here (they ran out of type or something) :( and the next moment was somewhere in the future), no performance degradation compared to current code, relatively easy implementation within current compilers and that current template code must remain valid.
  • -(55:33) Lecture continues here from where it was cut. It's something about type system how it makes sure correct data types using just declarations, and about compile time type contracts through templates.
  • -(1:06:14) Quick summary: template aliases, initializer lists, overloading based on concepts, type deduction from initializers, a new for loop for ranges.

After the lecture the following questions were asked:

  • (01:09:40) What's your opinion about the Microsoft implementation of C++?
  • A: Microsoft's implementation is the the best out there, they conform to the standards pretty well and the code generated is also good. GNU gcc is also good. Though, they want you to use their "Managed C++" called C++/CLI which is totally unportable. Apple does the same with their version of C++ which is Objective C/C++ and and so does GNU. They all play this game of trying to get users just to use their product and not switch to their competitor products.
  • (01:11:56) Do you think you'll ever design a new language from scratch?
  • A: Certainly not from scratch. You have to answer the question, why are you designing a language? You design a language to solve a certain problem. If I ever designs a new language it will be because I feel that some problem needs a solution.
  • (01:13:39) You mentioned threads, are there other things like transactions and cache mangement?
  • A: Concurrency is becoming very important. The question is how do you do it? My solution is to provide language primitives out of which you build libraries that use these primitives and provide various models of concurrency. Doing it directly with language primitives is too hard.
  • (01:16:25) How long after the standard is out do you expect to see a production compiler?
  • A: After the C++0x standard is approved and released the vendors will start releasing compilers right away. Some of them have already built in some of the upcoming features.
  • (01:17:55) Is auto like a type inference?
  • A: auto is kinda type inference but it's very simple. You simply look at the type of initializer and you use it.
  • (01:18:47) Would it be useful to have a switch in every compiler for deprecating features?
  • A: Yes, that would be useful because the compilers have to support old features which we would like to get rid of ever. I have not been able to convince compiler makes to do it.
  • (01:19:16) Is it possible to do garbage collection (GC) cleanly and efficiently in C++?
  • A: Yes, it is possible to do GC in C++. An implementation already exists and I will have a discussion tomorrow on whether to put it in standard. There are two problems, though. One is that people would start writing poor code never caring to free the used memory which would lead to poor performance. The other is that GC can be a performance virus.
  • (01:24:39) A lot of academic institutions have dropped teaching C++. As a result there are a lot of poor coding practices and poor coding solutions coming in from people. Are there any plans to have some documentation on how it would be more teachable?
  • A: I have become an academic for the last couple of years and someone talked me into teaching undergrads. I am more used to serious Ph.D's from good universities with 10 years of experience and it's not quite the same! I tried out ideas and I wrote a text book which will get out some time next year.
  • (01:26:24) How soon after you created C++ did you see it start to take over the industry?
  • A: The first commercial release was in 1985. I had access to data how many C++ users there were and kept track of it during 80s. From 1979 till 1991 the doubling rate was 7.5 months. And now we are at 3 million users.
  • (01:28:25) A lot of template classes at the moment use template hoisting to make them more efficient in terms of code size at compilation time. Is there anything being done to address the issues that make it necessary?
  • A: There is a trick of avoiding a lot of separate template instantiations based on void pointer. I don't see any changes to that. That's a portable way of doing it.
  • (01:29:50) What's your opinion on generic programming at runtime level?
  • A: It would be a good idea, but what's mostly called generic programming at runtime level has either so many indirections that it runs at 1/10ths of the speed of non-generic code or it's not too generic and you can't do any of the interesting stuff.
  • (01:31:33) You talked about having user defined types act the same way as built in types. Pointers are used for various optimizations like function overloading and smart pointers. Do you see a problem here? Is it being solved?
  • A: First of all, I think smart pointers are overused. Secondly, we can emulate inheritance with smart pointers. You can basically build a perfect smart pointer now. I worry about smart pointers because if you use a smart pointer and I give you one and we have no agreement on how mine works, we got a race condition. We have no lock on this code and we got two pieces of code which poke in the same area. You have to be very careful of the semantics of this smart pointer.
  • (01:33:38) There are interesting parallels between templates and duck typing used in dynamic languages. Will templates overtake classes for writing code and filing contracts?
  • A: Yes, templates has roughly the same as duck typing in scripting languages done dynamically. I think interfaces will be much better specified with concepts and there is still a large components of duck typing. Templates are becoming more important. Please remember that templates by themselves are nothing! They help you to abstract you over something.
  • (01:37:14) Have you ever gotten any death threads because of the changes in the language?
  • A: I have never gotten any death threads for any reason. And lets keep it that way!
  • (01:37:28) Is there any particular naming convention you subscribe to?
  • A: Yes, I like underscores. I do not like the camel stuff, it's less readable.
  • (01:37:57) The new language features you come up with. There are so many languages upcoming right now? Do you try to reuse any of the things they have done?
  • A: I try to learn from new languages, particularly, the users of new language. But grafting from one language to another is much harder than most people think. When you see something work in one language, then you see what problem are they solving, can we solve as elegantly in C++? If the answer is no, then we see how it can be solved and see the way it was done in other language. But simple grafting is a very hard exercise.
  • (01:38:52) When you initially designed the language, did you start from rigorous specifications or how did it start?
  • A: I am trying to be rigorous, but it's still informal in a sense that it is written in English. I started out with C specification written by Dennis Ritchie. Some things have improved, some have become more obscure because of the more words people use. We have tried several times to see if we can make it also formal. It would be nice to have formal sematics either for all of it or parts of it. It has not been that successful over the years. But I am very happy to report that a group from IBM this year managed to prove that C++ inheritance system was formally sound. It's proven. So 20 years later they proved that I didn't screw up.
  • (01:40:18) With Sun releasing some hardware which runs Java bytecode, are you afraid that it could take away C++'s embedded position?
  • A: Java would kill C++ totally in 2 years, Sun said in 1996. They sort of been repeating this story over and over again. There is a lot of Java, and there is a lot of C++ and it's a big world.
  • (01:41:05) How do you balance things at compile time and runtime, for example exceptions?
  • A: If you need to have balance, something at runtime, then you have to have it at runtime. For example, most of the good uses of virtual functions can't be done at runtime because you don't have the information. Talking about exceptions, there are compilers which add no overhead if no exceptions are thrown. There are trade offs and some things you just need to do at runtime.

You can watch the lecture right here as an embedded flash video, or you can download the this lecture.

Download Bjarne Stroustrup's Lecture on C++0x

See you next time!