The smooth promotion of the C ++ language is obviously very grateful to the large user base of the C language, but the C language style is also deeply branded with the C language, that's why many people prefer the C ++ language.
The program code also has a style, which is nothing new. As early as 1980s, C language programmers had to choose between K & R and ANSI. But in all fairness. I have never seen a language like C ++ that is so subtle and elusive in terms of code style: no one can tell how many different styles C ++ code can derive.
However, I know that many C ++ beginners are familiar with C ++ codes of different styles, I often mistakenly think that I have seen several completely different programming languages-this alone is enough to remind us, it is imperative to study and clarify the evolution and development rules of C ++ language styles.
Similar to the style changes of previous dynasties, the study of C ++ language style has no shortcut. We can only follow the historical context and find the source of the Code style based on the research method of "ending with a table" [1] advocated by Liu Yu in Wenxin Diao Long, explores the internal cause of style evolution and clarifies the trend and laws of technological development.
1. C with classes-an attack on the C language style
Before Bjarne Stroustrup adopted Rick Mascitti's suggestion in December 1983 and named the new language it invented as "C ++", people used "CC with Classes) it is called a "dialect" that originated from the C language and has a data abstraction mechanism ". Although C with classes is essentially only a scalable language that can be converted into a traditional C language code by the pre-processing program Cpre, which is similar to the pre-processing process of Pro * C language we saw in Oracle, but it did lay the foundation for all later C ++ Code in terms of style.
- class stack {
- char s[SIZE];
- char* min;
- char* top;
- char* max;
- void new();
- public:
- void push(char);
- char pop();
- };
The Code "C with classes" is recorded in Stroustrup's "design and evolution of C ++ language". The new () in the Code is actually a stack-like constructor, which is very different from the later C ++ language. Obviously, Class C almost completely inherits the C language style. The statement in the code looks exactly the same as the C language, and the class structure is roughly the same as that in the C language.
These signs indicate that the C ++ language comes from C and is compatible with C as much as possible. This design idea not only facilitates the rapid popularization of C ++, but also facilitates the smooth development of C ++. promotion obviously benefited from the large user base of C language ).
In addition, the C language style has been deeply branded with the C language, so that after a few years, when the C ++ language has basically had an "independent personality, stroustrup also has to remind people to leave the C language thinking style as far as possible.
On the other hand, Stroustrup firmly rooted in Class C from the class, derivation, access control, and other object-oriented concepts borrowed by the Simula language. According to Stroustrup, the intention of introducing an object-oriented mechanism for C language is to find a "suitable tool" [2] to implement a distributed system or solve similar complex problems. However, stroustrup binds the efficiency of C with the elegance of Simula. In fact, it has laid the seeds of "Double Character" for the C ++ language-it is hard to say that this is not the C ++ language style. diverse direct incentives.
- Introduction to C ++
- Summary Notes on learning and exploring C ++ library functions
- Basic Conception and method of C ++ Class Library Design
- Does C ++ really have market value?
- Basic Conception and method of C ++ Class Library Design