agentd.cn
C++ Big Picture: Issues of C++
Excerpt
**FAQ**: Sure - not perfect, but mature and well-supported, which is good for business. **FQA**: C++ is not “mature” in the sense that different compilers will interpret it differently, and C++ modules built by different vendors will not work with each other. C++ is not “well-supported” in the sense that development tools for C++ lack features and are unreliable compared to other languages. These things make one ask “Am I the first one trying to do this?” all the time. … C++ is different - it’s designed for perfection. Where other languages give you a feature, C++ gives you meta-features. Instead of built-in strings and vectors, it gives you templates. Instead of garbage collection, it gives you smart pointers. This way, you can (theoretically) implement your own “perfect” (most efficient and generic) strings. In practice, this turns into a nightmare since many different kinds of strings, smart pointers, etc., each perfect in its own way, will not work with each other. C++ sacrifices usability for perfection. However, despite the obsession with perfection, C++ is “practical” - from a language designer’s perspective rather than from a user’s point of view. The “practical” thing in C++ is that it’s based on C. This helped the language gain popularity. This is also the main reason for inconsistencies in the language - ambiguities in the grammar (declaration/definition, type name/object name…), duplications of functionality in the different features (pointers/references, constructors/aggregate initialization, macros/constants/templates, files/namespaces…). … Most kinds of built-in language support for object-oriented programming, including no such support, have big advantages over C++ classes. The single biggest problem with C++ classes is that private members are written in header files, so changing them requires recompiling the code using them - for important practical purposes, this makes private members a part of the interface. C++ is built such that recompilation is very slow (an order of magnitude slower than it is with virtually any other language), and classes are built to make recompilation a frequent event. From a business perspective, this means two things: your C++ developers spend a significant amount of their time in recompilation cycles, and C++ interfaces provided to your customers or by your vendors will cause you major headaches (when versions are upgraded, some of the code won’t be recompiled and software will fail in creative ways). Luckily, C++ interfaces are hard to provide (effectively all parties must use the same compiler with the same settings), so quite typically C++ modules have interfaces written in C. … **FQA**: “Generic programming” in the context of C++ refers to templates. Templates are hard to use (and not only define & implement) due to cryptic compiler error messages, extremely long compilation time and remarkable hostility to symbolic debugging - both code browsing and data inspection. The usability problems are not solved by using off-the-shelf components. … Makes it possible for old code to call new code **FQA**: Here are a few more: No practical implementation of C++ runs in managed environments, increasing both the defect rate and the potential damage of an undetected defect Providing C++ interfaces to a software component is impossible in practice due to lack of compile time and run time interoperability C++ is extremely inconsistent and complicated, increasing learning curves and the defect rate C++ compilers typically fail to comply to its intricate standard, reducing portability C++ compilation is both very slow and very frequent, increasing development time and defect rate (people write cryptic and dangerous code to avoid recompilation, for example, use global variables instead of adding arguments to functions, saving 1.5 hours per rebuild x 20 developers = 30 hours of downtime) C++ lacks standard types representing basic data structures like strings, arrays and lists (or has more than one standard and many non-standard ones, which is the same), making it harder to reuse code (each interface works with a different kind of strings) and reducing the speed due to run time type conversion All things mentioned in the FAQ are false for most practical purposes: … C++ doesn’t reduce safety-vs-anything trade-off since it’s extremely unsafe (it “supports” all the undefined behavior of C like buffer overflows, adds many new scenarios with undefined result like invisibility of template specializations at the point of usage, and its complexity reduces the chances that someone actually knows what a program does and can prove its correctness). Where’s the “trade-off”?
Source URL
https://agentd.cn/archives/big-pictureRelated Pain Points
Undefined behavior and safety issues in core language features
8C++ is extremely unsafe, supporting all undefined behaviors from C (buffer overflows, pointer misuse) plus new undefined behavior from templates (invisible specializations). Iterator invalidation creates dangerous undefined behavior, and complexity makes it difficult for developers to understand what code actually does or prove correctness, increasing defect rates.
C++ interfaces cannot be provided or versioned in practice
8Providing C++ interfaces to software components is impossible in practice due to lack of compile-time and runtime interoperability. When versions are upgraded, code becomes inconsistent and fails in unpredictable ways. This forces vendors to expose only C interfaces instead, limiting expressiveness.
Long Build Times
7Build time remains a significant pain point for C++ developers, with 43% reporting it as a major issue. Multiple systemic reasons contribute to slow builds, though there is a slight downward trend indicating some ecosystem improvement.
Cross-Platform Compatibility and Portability
732-52.6% of C++ developers encounter compatibility and portability issues across platforms, operating systems, and compilers. Code adjustments for different systems can be time-consuming, especially with legacy code, resulting in platform-specific bugs and increased maintenance costs.
Header file private members force unnecessary recompilation
7C++ requires private class members to be written in header files, making them effectively part of the public interface. Any change to private members forces recompilation of all code using the class, defeating encapsulation benefits and severely impacting development velocity.
Poor compiler error messages for templates
6C++ compiler messages are unhelpful when template code is incorrect, making debugging difficult. C++20 concepts help but require significant effort to understand.
Multiple incompatible standard implementations of basic data structures
5C++ lacks standard types for basic data structures like strings, arrays, and lists, or has multiple competing standards and non-standard implementations. Each interface works with different string/container variants, making code reuse difficult and forcing runtime type conversions, reducing performance and maintainability.