r/cpp • u/crashcompiler • Mar 14 '26
Discussion of Code Structure and Code Complexity Implications of Basic C++ Language Features
After 10 years of programming professionally in C++, I came to realize that I generally prefer a simpler subset of the language for my day-to-day work, which mainly involves desktop application development.
Working in a 30 year old code base for so long, you get to see which design decisions panned out and which didn't. This lead me to think about the technical reasons for why certain C++ language features exist, and what long-term impact they have in terms of code complexity and code structure. The result is a somewhat lengthy and very subjective article that I would like to share.
You can find the article here:
https://slashbinbash.de/cppbas.html
The premise of this article is: if you use simple language tools you can concentrate on solving the real problems at hand, rather than solving language problems. This is very much inspired by listening to interviews with Casey Muratori, Jonathan Blow, Bill "gingerBill" Hall, and others.
I discuss several aspects of the C++ language like functions, structures, statements, enumerations, unions, arrays, slices, namespaces, classes, and templates. But I also go into topics like error handling, and ownership and lifetime. I finish the article with a chapter about code structure and the trade-offs between different approaches.
The goal of this article is to give the reader a sense of what code complexity and code structure means. The reader should be able to base their decisions on the technical aspects of the language, rather than the conceptual or philosophical reasons for why certain language features exist.
I'd be thankful for any feedback, corrections, and ideas that you have!
Note: I still need to clean up the article a little bit, and add a few paragraphs here and there.
View all comments
Show parent comment
2
u/crashcompiler Mar 14 '26
First of all, thank you very much for your feedback!
Before I reply to your points, I want to say that I will rework the whole introduction to better reflect that this article is not for beginners who want to learn modern C++.
> you always start with the oldest feature first.
My intention was to show step by step how the language arrived at these solutions, thereby bridging the gap between C, legacy C++, and modern C++. I'm not sure if there is another way to do it.
I think you are right that I'm putting a lot of focus on the old patterns, while only briefly addressing the modern solutions. I think I can work on that!
> you mainly are talking about language features.
I feel like that's the whole idea of the article.
The idea of having a function that returns either a value or nothing, is universal in all programming languages. Modern C++ chooses std::optional to express this in code, and one can always read the C++ standard for details of how to use it.
That's at least what I want readers to take away from this article.
> I'm missing the syntactic sugar arguments.
I can definitely improve pointing out the technical benefits of the modern C++ solutions over the old ones. But I don't really want to give opinions on syntactic sugar. I don't think I'm good at that.
> missing print/format, compile time, ranges, deleted functions
Maybe I can write a few things regarding certain aspects of these points. Like going from defining constants with `#define` to `constexpr`. I could discuss going from printf to std::cout to std::format. I need to think about it some more.
> missing compiler warnings.
I don't see how I can include compiler warnings in the existing text. There are books that cover this topic better than I could, for C as well as C++, across different compilers. And the article is about language features, abstract concepts, and code complexity. I don't know ...
> missing static analysis.
I know there are static analysis tools that try to compute a metric for code complexity, be it lines of code, cyclomatic complexity, ingoing and outgoing dependencies, etc. But the observations that I make in the article are not based on these metrics, which is why I don't know how I would tie it back together. But it's an interesting idea!