Joseph Sibony
reading time:
I’m about to give a talk at CppCon 2021 next week on C++ Complexity.
The question whether C++ is a complex language is, of course, subjective, but there would not be many that would argue against that claim.
The question of what makes C++ complex for you is of course also subjective, but it is an interesting question with potential implications. We may deduce that:
- There are features that we need to teach better
- There are domains that may need improvements via the ISO process
- There are areas that may benefit from better tools
C++ complexity has been a point of discussion for a while now. A great talk on that was given by Kate Gregory at Meeting C++17, titled: “It’s Complicated”. Some argue that the complexity is a feature of the language, others view it in terms of culture (the original blog link is not available anymore, but the discussion that it ignited is fascinating).
A nice snippet from the reddit discussion above:
So, as I said, I’m going to talk about C++ Complexity at CppCon 2021. In a similar talk that I gave at CoreCpp about two months ago, I asked the audience what makes C++ complex for them?
The question had a list of subjects prepared ahead of time, after consulting with C++ community members, trying to cover all potential complexities. Here is the list that was presented – respondents could check any number of items:
- Nothing – everything in C++ is a breeze for me
- Pointers and references
- Memory and lifetime management
- const correctness
- Rvalue and move semantics
- Constructors / Destructor
- Operators overloading
- Implicit conversions
- Multiple Inheritance
- virtual inheritance
- Polymorphism
- Covariant return type
- Exceptions handling
- Lambda expressions
- Template specialization
- SFINAE
- Templates in general
- Smart pointers
- Multithreading and Concurrency
- Lockless algorithms and memory fences
- Performance
- Testing
- Working with external libraries
- Following the new C++ standards
- Coroutines
- Compiling and/or linking
- Handling long build time
- Working with dynamic libraries
- Packaging and deployment
- Debugging memory leaks
- Debugging and troubleshooting crashes
- Debugging in general
- Specific GPU programming issues
- Specific Real-Time programming issues
In addition to the above options, there was also an option for “other”, asking the respondents to elaborate.
The questionnaire also asked for the respondents’ years of C++ experience, with the options: 0-1 years, 2-4 years, 5-8 years, 9-12 years and more than 12 years.
The results are interesting.
Let’s start with the audience: years of experience in C++
Though the list of complexities presented in the questionnaire was quite exhaustive, a few people added their own, with items such as: understanding compiler errors, managing big projects and lack of standard tools (e.g., lack of a standard build tool).
One of the options in the list was that there isn’t anything complex: “Everything in C++ is a breeze for me”.
The total percentage marking this option was 9%, but naturally, this percentage is higher for veterans (still, only 15%) compared to beginners (5%), as can be seen in the graph:
Here are the results for the entire sample, consisting of 101 people:
The top five selections were:
- Debugging memory leaks
- Rvalue and move semantics
- Handling long build times
- Following the new C++ standards
- Lockless algorithms and memory fences
But when analyzing it based on seniority, veterans and novices suffer from different things.
For veterans the top five were:
- Lockless algorithms and memory fences
- Debugging memory leaks
- Following the new C++ standards
- Handling long build times
- Packaging and deployment
Top complexities – veterans:
For novices the top five were:
- Rvalue and move semantics
- Memory and lifetime management
- Handling long build time
- Implicit conversions
- Debugging memory leaks
Top complexities – novices:
It is interesting to note that “Handling long build times” is in the top 5 for both veterans and beginners. This shows that this is an issue that bothers the C++ industry. Of course, we at Incredibuild are happy to solve this issue for you, with distributed build acceleration, already used by many companies in the industry.
It is also interesting to see that debugging memory leaks is still high in the list (35% picked that, in the entire sample!). And that’s long after smart pointers have become widely accepted in the industry. It is not clear if people do not use smart pointers, or otherwise misuse them. This should be further investigated.
Another interesting result is having Rvalue and move semantics at the top 5 for novices, but not much lower for veterans (#7). Seems that we do have some work cut out for us in teaching this subject better, making it easier to follow and understand.
Packaging and deployment is #5 for veterans, and as it seems we are still on the lookout for the silver bullet in that domain for C++, with several good solutions around.
Summary
C++ has its complexities, for both novices and experts. But the feeling you get when talking with C++ practitioners is that these complexities are just kind of a challenge, not an end-all or reason to look for other possibilities around (Rust, anyone? well not for C++ enthusiasts).
With the evolution of the language, though new complexities come in, many are being solved. Still, understanding the complexities that the community perceives is important if we want to look for solutions in terms of best practices, tools and further evolution of the language.
Table of Contents
Shorten your builds
Incredibuild empowers your teams to be productive and focus on innovating.