How to understand the design principles of C++
Today, I would like to talk to you about how to understand the design principles of C++, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
The design principle of C++ is: as far as learning C++ is concerned, we can think that C++ is an independent language, he does not rely on C language, we can not learn C language, but we must have a good code foundation and English skills.
It is opposed to the requirements of "complete type security", "complete versatility" and "perfect abstract beauty". C++ 's design principles draw on user-defined types (class, §4.1) and class hierarchy mechanisms from Simula. However, in Simula and many similar languages, its support for user-defined types is fundamentally different from its support for built-in types. For example, customization for users in the stack is not allowed in Simula.
In contrast, built-in objects are allocated space only in the stack, not in dynamic storage, and cannot be pointed to it using pointers. This difference in the treatment of built-in types and user-defined types implies a strict consideration of efficiency issues.
For example, when used as a reference to an object allocated in a dynamic store, if the object is of a custom type (such as complex, §4.1), it puts a load on the runtime and space; these loads are considered unacceptable in some applications. These are the problems that the design principles of C++ are intended to solve. At the same time, the difference in usage also determines that it is impossible to treat those semantically similar types in paradigm programming.
When maintaining a large program, a programmer will inevitably make some changes to the program based on some incomplete knowledge and only pay attention to a small part of the whole program code. Based on this, C++ provides class (§4), namespace (§5.2) and access control (§4.1), which makes the locality of design decisions possible.
In languages based on one-pass compilation, some sequential dependencies are inevitable. For example, in C++ 's design principles, a variable or function cannot be used until it is declared. However, the name rules and overload resolution (overload resolution) rules for class members in C++ are developed independently of the order of declarations in order to reduce the possibility of confusion and errors to *.
◆ uses traditional (clumsy) connectors (linker)
There is no unexplained incompatibility between ◆ and C language.
◆ does not leave room for lower-level languages below C++ (except assembly language)
◆ you won't pay for the parts you don't use (zero load rule)
When in doubt, ◆ can provide a way of complete self-control.
C++ is designed to be compatible with C's "source-link" approach as long as its support for strong type checking (strong type checking) is not seriously affected. Except for some minor details, C++ includes C [Kernighan,1978] [Kernighan,1988] as a subset.
C++ 's compatibility with C allows C++ programmers to have a complete set of languages and tools available immediately. There are also two important points, one is that a large number of high-quality teaching materials about C already exist, and the other is that C++ programmers can take advantage of C++ 's compatibility with C to directly and effectively use a large number of off-the-shelf libraries.
When deciding to use C as the basis of C++, C was not as outstanding and hot as it was later, so when considering this question, compared with the adaptability and efficiency provided by C, the popularity of C is only a secondary consideration.
However, the compatibility with C also makes the design principles of C++ retain some defects of C in some syntax and semantics. For example, the declarative syntax of C language is far from elegant, and the implicit conversion rules of its built-in types are also chaotic. Another big problem is that many programmers who switch from C to C++ do not realize that a significant improvement in code quality can only be achieved through a significant change in programming style.
After reading the above, do you have any further understanding of how to understand the design principles of C++? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.