Talk review: Empirically Measuring, & Reducing, C++’s Accidental Complexity

Empirically Measuring, & Reducing, C++’s Accidental Complexity – Herb Sutter – CppCon 2020

Empirically Measuring, & Reducing, C++’s Accidental Complexity – Herb Sutter – CppCon 2020


For some time now Herb Sutter is devoted to making C++ simpler and more natural to use. I admire his work very much and I can’t wait until first of his ideas get accepted to the International Standard (IS). At CppCon 2020 Herb picked another fight in this important battle – this time in the parameter passing battlefield. Yes, passing arguments to the functions. But why this particular area? It sounds like a topic where everything is simple and hardly anything can be done. I was surprised too.

Herb Sutter approached the problem in the most professional and effective way. First, he gathered and analyzed many existing C++ guidelines and rules (like C++ Core Guidelines) and grouped them into categories. The biggest group is related to, you guessed it, parameter passing. Then he analyzed what are the typical scenarios in which we call functions with arguments. It turns out, that there are quite a few. Especially if we consider object lifetime, cost of copying and ownership. This usually involves move-semantics and even perfect-forwarding in some cases. Also, there is a problem of output parameters, which should not require to be initialized before the call (note that some static analyzers flag that as an issue). You always have to consider how will look the call site and how would client want to pass the arguments. This has an immediate impact on the function prototype, which can quickly get complicated.

In this talk Herb proposes new language keywords, that will solve all the above problems. Functions will behave exactly as you expect and even static analyzers will be able to take advantage of them to verify your code more precisely with no false positives. If you are interested, then this talk is for you. Just remember, that at the time of publishing this review all described features are only the proposals and there is no concrete timeline when they will be available.

In this talk you will learn

  • What is the new proposal for parameter passing?
  • How to empirically analyze and prioritize problems in programming?

Selected keynote slides

  • 2:02 – Why thinking about complexity matters.
  • 3:15 – Basic definitions:
    • essential complexity – inherited in the problem,
    • accidental complexity – an artifact of a specific design.
  • 4:53 – Looking for special “signs” in the code will help us locate programming complexity.
  • 5:23 – There are lots of guidelines and rules for C++. Most are related to language usage.
  • 7:00 – Classification of the 638 rules (533 of which are strictly language-related).
  • 9:33 – 90% of the rules are about accidental complexity:
    • “This is a chance for improvement and language evolution.”
  • 10:37 – Rules breakdown into categories.
  • 12:58 – ~23% of the rules are related to parameter passing and object initialization.
  • 13:41 – How to pass an object as of today.
  • 14:36 – Switch to thinking about what we want to do with the passed object.
  • 17:50 – Definition of an input parameter.
  • 21:15 – Definition of an input/output parameter.
  • 23:25 – Definition of an output parameter.
  • 24:58 – Definition of a move parameter.
  • 26:57 – Definition of a forward parameter.
  • 29:37 – Demos:
    • Herb is showing a dramatic code reduction and increased simplicity by applying his proposal (compared to the current state).
  • 48:40 – Today’s guidelines for initialization:
    • Exception for arrays: do not initialize if array in an output parameter.
  • 52:45 – How output parameter can solve the problem of redundant object initialization when this object will be initialized inside a function.
  • 54:35 – Proposal of the “uninitialized” semantics.
  • 57:05“Meta classes + new parameter passing will reduce C++ guideline rules by 30%”.
  • 59:20 – History of the “Simplify C++” talks.
  • 1:03:50 – Final thoughts:
    • “Efficient, abstraction – in that order!”,
    • We should create language abstraction from efficient rules that we already do.
  • 1:05:15 – Q&A.

Subscribe to get notified about new content

Thanks for taking your time to read it. If you like it or have other opinions, please share it in the comments. You can also subscribe to my newsletter to get latest news about my content. Happy coding and let’s stay connected!