The design principle of C ++ is: to learn C ++, we can think that it is an independent language. It is not dependent on C language. We can skip C language at all, directly learning C ++ requires a good foundation of code and a good knowledge of English.
This is in opposition to the three requirements: "complete type security", "full universality", and "Perfect abstraction beauty. The design principle of C ++ draws on the user-defined type class, § 4. 1) and class hierarchy mechanism from Simula. However, in Simula and many similar languages, their support for user-defined types is fundamentally different from the support for internal models. For example, Simula cannot be customized for users in the stack.
On the contrary, built-in objects are only allocated space in the stack. They cannot be allocated in the dynamic storage area and cannot be pointed to by pointers. This difference between the treatment of built-in types and the treatment of user-defined types implies a strict consideration of efficiency issues.
For example, when it is treated as a reference to an object allocated in the dynamic storage area, if the object belongs to a custom type such as complex, § 4. 1), it will bring load to the runtime and space, and these loads are considered unacceptable in some applications. These are the problems that C ++'s design principles intend to solve. At the same time, the difference in usage also determines that it is impossible to uniformly treat those types with similar semantics in the model programming.
When maintaining a large program, a programmer may inevitably make some modifications to the program based on some incomplete knowledge, focusing only on a small part of all program code. Based on this, C ++ provides class § 4), namespace § 5. 2), and access control § 4. 1), which makes it possible to make design decisions different from locality.
Dependencies in certain sequence are unavoidable in one-pass compilation language. For example, in the design principles of C ++, a variable or function cannot be used before it is declared. However, in C ++, the class member name rules and the overload resolution reload resolution rules are formulated independently of the declared order principle, to minimize the possibility of confusion and errors.
◆ Use traditional clumsy) connector linker );
◆ There is no unreasonable incompatibility with the C language;
◆ Do not leave room for lower-level languages under C ++ except for assembly languages );
◆ You will not pay zero-load rules for the parts you do not use );
◆ In case of any doubt, we can provide a means of completely autonomous control.
In the C ++ design, as long as it does not seriously affect its support for strong type check strong type checking, and try to be compatible with C's "source-link" method. In addition to some minor details, C ++ includes C [Kernighan, 1978] [Kernighan, 1988] as a subset.
The compatibility between C ++ and C allows C ++ programmers to immediately have a complete set of languages and tools available. There are also two important points. First, a large number of high-quality teaching materials for C already exist, second, C ++ programmers can directly and effectively use a large number of ready-made libraries using the compatibility between C ++ and C.
- In-depth exploration of C ++ static Constructor
- What is standard input in C ++?
- How does the C ++ compiler handle exceptions?
- A summary of C ++ Language Learning
- Analysis of C ++ constructor in C ++
When C was decided to use C as the basis of C ++, C was not as outstanding and hot as it was later. Therefore, when considering this issue, compared with the adaptability and efficiency provided by C language, the popularity of C language is only a secondary consideration.
However, the compatibility with C also makes C ++'s design principles retain some flaws in C syntax and semantics. For example, the declaration Syntax of C language is far from beautiful, And the built-in implicit conversion rules are also chaotic and undisciplined. Another major problem is that many programmers who have switched from C to C ++ have not realized that the significant improvement in code quality can only be achieved through significant changes in the programming style.