Why do they say C + + is too complex? Abstractionists are anti-human design!


To measure whether a language (in a broad sense, not only programming language) is complex, we can look at the number of words, part of speech changes and grammatical structure. eight

According to relevant data, up to the latest C + + 20, there are about 99 keywords in C + + and 6 names with special meaning in specific context.

For comparison, in C language, as of C11, there are 44 keywords

Obviously, C + + is more complex than C, and its keywords are more than twice as many as C.


But there are also views that C + + will feel complexity only when it is viewed in isolation.

Designing any language has a background.

C + + is aimed at specific users:

· dealing with various complex problems

¤   Write a solution that runs for a long time

¤   The solution should meet any performance requirements

¤   Work on different hardware and operating systems

¤   Coexist with many existing systems

Although people want a simple language, what people really need is a language that helps solve problems.

Since C + + is quite popular, we come to the conclusion that:

People are willing to give up the requirement of simplicity for the strong expressiveness and efficiency provided by language.

If so, why does the more complex the problem to be solved, the more complex the tool has to be? There are three reasons:


✿ the first is the class library and language semantics

Initialization and assignment in C + + are almost the same in many languages, such as C.

So why is it so important in C + +?

C + + allows variables to “own” certain resources. If the value changes, these resources must be abandoned.

Differences become important when we write classes that deal with data structures assigned elsewhere.



When the following code assigns a value to s, s actually already has a value (default constructor).

When assigning values, s must discard the memory occupied by the old values.


In principle, there is no need to draw a clear line between the two.

You can immediately follow a destructor operation after initialization, which will simplify many programs, but make the abstraction of some classes difficult to implement.

For example:

Some C + + libraries provide a class called slice. If an object includes a data structure, we can create a slice pointing to a part of the data structure. Assigning a value to the slice will affect the selected part of the original data structure.


However, if the assignment is always equivalent to the deconstruction operation immediately after initialization, this kind of abstraction is more difficult to implement.


✿ the second is a compromise

For example, interface design, many in C + + provide a simplified tool for class design to help them solve the problem of user interface.

Therefore, it will be more difficult to use C + + design analogy with other languages.

But at the same time, the solution is also broader.

This will give library designers the possibility to be more strategic and allow them to think more.

Through the well-designed C + + library, it will become very easy to use.


Everyone will find it very difficult to design an excellent variable length string and negative number class, but it will be even more difficult to add these things to the compiler.

The reason is that users rarely have the right and ability to modify their own compilers, let alone migrate this change to different compilers.

Based on this, C + + provides a compromise scheme.

It allows us to define the concrete behavior of abstract concepts in detail without changing the internal working mode of the compiler.


✿ the third reason is the conservation of complexity

The computer system is complex and phased. If we ignore this complexity, we can not only eliminate the complexity, but also pay a certain price.

For example, the problem of calculating the addition of three floating-point numbers:


This code does not provide accurate answers to all permutations of 1020, – 1020 and 1.

1020 + 1 and – 1020 will equal 1020, and 1 will eventually be completely lost.

In solving this problem, we can choose to deal with or ignore complexity.

If you decide to deal with it, you need to do this by ensuring the most accurate possible answers.

If you ignore complexity, it will move elsewhere.

Software dealing with complex problems must face complexity.


Some languages pretend that complexity does not exist and choose to ignore it, providing users with a clean and tidy interface.

If some parts of the world do not conform to the model they envision, they simply ignore it.

Other languages throw complexity directly to users( If users don’t care, they win the game, which is why so many imperfect software products are delivered before they are perfect).

Here, C + + is a compromise, which allows us to write programs that implement the lowest level of control over the operating environment, and also allows us to ignore most of the less important details.

In order to be more flexible, it pays a greater price.


Flexibility is very valuable to the designers of library classes, so they can provide users with functions in a wide range of application fields using different abstraction levels.

Therefore, in the long run, abstraction is still the most powerful tool in the world.

For small partners, do you think C + + is complex or simple? What are the reasons for the complexity? Welcome to discuss!


Finally, whether you are changing careers, beginners or advanced, if you want to learn programming~

——[noteworthy]myC / C + + programming learning exchange club!——

involve:C language, C + +, windows programming, network programming, QT graphical interface development, Linux programming, game programming, data structure and calculation, and database