CppCon 2020

Way back in the old days I did a lot of C++, using first MFC and later also ATL. I clearly remember the intellectual challenges – going from C to C++,  learning all the stuff about templates, and trying to live without printf and its siblings. Sometimes it was extremely effective, but at other times it was just like “does it really have to be this complicated?”.

On one hand C++ really allows you to think about performance, and let as much happen at compile time as possible. On the other hand it silently does so many things in the background, that you really need to understand as an embedded developer.

I moved to networks, and managing hardware and embedded systems, and C++ became more distant. However, as stated in Embedded Trends, C++ remains an important language and I got curious to see where it’s going.

A good colleague told me that he found some neat presentations on YouTube, from the yearly C++ Conference – in short “CppCon”. CppCon 2020 took place September this year. Naturally Covid-19 has changed the whole thing. No more big meetings, coffee-breaks, discussions and dinners. Instead, presenters sit in their homes. You see the presenter via a webcam next to their slides in a bigger window. Thus, the recordings on YouTube are now very similar to “being at the conference”. I really recommend that you go on YouTube and search on “CppCon 2020”. As a side note I can tell you that with a Chromecast on the TV in my basement, I can now workout physically and mentally at the same time!

So what did I learn from watching a number of presentations this year?

The course of C++ is changing

When I moved from C to C++, it was also a move from functional to object-oriented (OO) programming. My coworkers and I spent countless hours discussing “diamond” inheritance, overloading and polymorphic concepts in general . Now, at CppCon 2020, Phil Nash did a presentation called “OO Considered Harmful”. This is not a change of religion, but nevertheless states that C++ is not all about OO. The tittle refers back to a “letter” written by Edward Dijkstra in 1968(!) called “Goto Statement considered harmful”. We all have learned to avoid Gotos, but I must admit that I did not know Dijkstra’s letter.

Now I have read it. In a fantastic precise language Dijkstra basically tells us that the code we write, should not differ too much from the way it’s run. As humans we better understand code that is run line-by-line – exactly as it is written, rather than code that is executed in tiny pieces here, there and everywhere. Dijkstra accepts procedures as a way of simplifying the code, but the Gotos makes it all a mess.

Naturally, concurrent or even parallel (there is a difference) programs are challenging, but even single-threaded event-driven programming can be a pain to follow and debug. If I break execution here, what is the state of my variables?

In many ways several of the newer things seems to be a step in keeping the code more easy to read – screen by screen – but not necessarily as Dijkstra requested; run in the order they were written.

It seems to me that many of the new things are about making C++ simpler and safer. However – being C++ it never really gets to be simple. C++ is highly backward compatible, and still supports a C-like coding-style. This means that there are so many ways to do things. The track called “Back To Basics”, is a great  way to understand where to break old habits. Here the whole history of a given subject is unfolded, leading to a deeper understanding of the changes in the language.

Specific improvements in C++20

  • With C++11 we got Lampda-Expressions. They do have a cryptical syntax, but they allow you to write small “functions with function-pointers” just where you need them. They are typically used as call-backs, so they do not appear where they are executed in the code, but they do however, appear where you need to deliver the pointer. This evolved in C++14, C++17 and again in C++20.
    Barbara Geller & Ansel Sermersheim has a “Back to Basics” on Lampda where they take us through all the versions.
  • With C++20 we finally see Coroutines. This could be a great step towards escaping “callback-hell”. It does however seem that the language-support is not fully there, and we are told that library versions should be preferred until C23.
    Marc Gregoire talks about this, as well as Ranges, Concepts and Modules and other stuff in his presentation “C++20: An (Almost) Complete Overview”.
  • “Ranges” seems to be one of the really neat new things. It is part of “Concepts” and allows you to use collections with sorts, filters and transforms that are all lazy evaluated in “pipes” similar to the command-line pipes. It seems that you can work on infinite sets of data.
  • “Modules” as known from many other languages as a more intelligent way to do what we currently do with header-files. Naturally in a backward-compatible manner.
  • Concurrency came into C++ with the 2011 version, but there are many improvements. Arthur O’Dwyer does a nice “Back To Basics” on Concurrency. It seems that there is a general enforcement of RAII – Resource Allocation Is Initialization. This basically only works on stack-allocated objects that have a well-defined lifetime, so a good part of the trick is to allocate as much as possible on the stack – in function scope.
  • Tons of updates like improved date-handling in std::chrono and a “Format” string call like we have seen in C#. Stephan Lavavej from Microsoft does a presentation called “C++20 STL Features: One year of development on GitHub”. He introduces many improvements and also explains how the old version might be unsafe. I was particular horrified when he talked about “remove” from collections.

Other observations

I realized that “std::” is now pronounced “stud” or “stid”. I am sure we used to say “standard”. Young people are in such a rush!

I also enjoyed Bob Steagall’s: “Back To Basics – the structure of a Program.” In all my rusty-ness I felt at home here, but still learned and got a better grip of the concepts. For instance I now know that there are 9 specific phases in a C++ compilation.

Finally I got sidetracked into older presentations by Kevlin Henney. He is most entertaining, and it is fun to see him attack things that programmers do because … well because others do. There are so many strange ideas of what you should and should not do, that often stem from ancient history – often in other languages. A nice quote from Alan Perlis: “Everything should be built top-down – except the first time”. You gotta love it.

So go to YouTube and search for “CppCon 2020” – and enjoy 🙂

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *