Abstract In C ++
Author: Li Jianzhong
In the past two days, the translation of Bjarne stroustrup, translated by Mr. Deng jifeng (soloist), is the article titled action and the C ++ Machine Model written by embedded software and systems. 2005. Based on my experience in C ++ training for a period of time, I have learned more about the abstract of C ++. Here I will give a brief summary to share with my friends.
To clarify the problem, Wikipedia will first talk about the word abstract action:
Your action is the process of processing the information content of a concept, typically in order to retain only information which is relevant for a particle purpose.
To put it simply, it is "getting rough", or "getting irrelevant, getting relevant ".
What is the purpose of "one-to-one fetch? Wikipedia also gave a good explanation:
Complexity ction
Invalid action typically results in complexity limit ction leading to a simpler conceptualization of a domain in order to facilitate processing or understanding of specified specific scenarios in a generic way
In general, the two paragraphs from Wikipedia briefly illustrate the key role of "abstraction" in our understanding of things-the understanding of the world by people, it is actually a process of continuous "abstraction. The power of "abstraction" is widespread in various disciplines and fields. Of course, there are still some specific differences between different disciplines and fields.
Well, let's talk about the abstraction in C ++ or the abstraction of programming languages. For the most fundamental purpose, computer is an abstraction of human beings. Of course, the beautiful aspiration of Turing is achieved by programmers. The role of programming language in this process is to abstract "something easy to understand computers" into "something easy to understand ". In combination with the current mainstream programming languages (C ++, C #, Java, VB. NET, etc.), let's give some examples to illustrate the abstraction, that is, let programmers:
Basic Programming Abstraction
* Forget the data address (regardless of the object, pointer, or reference) in the memory and focus on the concept of the type instance expressed by the data.
Process-oriented Abstraction
* Forget the details of function call pressure stack/output stack, and focus on the call relationship between functions.
Abstract Based on Object Programming
* Forget the memory layout of the data member (field) in the object, and focus on the expression of the data member to the object state.
* Forget the binding mechanism and this pointer of function members (methods) in the object, and focus on the expression of object behavior by function members.
Object-Oriented Programming Abstraction
* Forget the memory layout of the data member in the subclass object under the class inheritance, and focus on the subclass concept brought about by the inheritance.
* Forget the virtual table vtable structure related to virtual functions and focus on the concept of dynamic polymorphism brought about by virtual functions.
Abstract of generic programming
* Forget the various compilation and binding mechanisms of the template, and focus on using a set of abstract concepts to express a set of requirements.
Abstract for Component Programming
* Forget the metadata and other mechanisms behind the component platform, and focus on the Black Box Concept expressed by the componentization module.
These "Forget... And focus on... To C #, Java, and VB. in other languages such as net, many programmers can easily do this-in other words, they can ignore the "underlying machine Models mapped to various abstractions" and only care about the "abstraction" of language expressions ", and develop qualified or even excellent programs. In this way, programmers in these languages can basically follow the following learning path to become a qualified programmer:
Grasp the structure of language syntax-> master the design idea (that is, abstraction)-> Develop an application or library
However, in C ++, a programmer cannot "forget... And focus on... Otherwise, it is difficult to write a program that runs correctly. A qualified C ++ programmer must follow the following learning path:
Master the language syntax structure-> master the underlying machine Models mapped by various abstractions-> master the design idea (that is, abstraction)-> Develop applications or libraries
This is the "abstract" issue in C ++! C ++ programmers cannot get rid of the "underlying machine Models mapped by various abstractions" and concentrate on "abstraction" alone-in other words, the abstraction of C ++ and its underlying nature are the two sides of C ++, which cannot be separated as easily as other languages.
So what has led to the unique "incomplete abstraction" of C ++? What are the advantages and disadvantages of this "incomplete abstraction?
Bjarne stroustrup repeats his philosophy when designing C ++ in the article "procedure action and the C ++ Machine Model:
* Program work at the highest feasible level of each action at the highest abstraction level.
The so-called "practical" means no loss of efficiency, flexibility, management ...... Simply put, C ++ wants to achieve "abstraction" without compromising any efficiency. C ++ has indeed achieved this goal. This is exactly why C ++ is "not thoroughly abstract.
This "not thorough abstraction" certainly won great success for C ++, making C ++ the preferred language for system-level software, which is beyond the expectations of any other language, see the heavyweight software http://public.research.att.com /~ BS/applications.html.
However, this makes C ++ always recognized as difficult to learn and use in the programmer circle. In the C ++ open source library comment (excerpt), Meng Yan talked about the fact that it is very difficult to Write Excellent libraries with C ++. Unfortunately, I only talked about the "difficult" conclusion and did not discuss the reasons for "difficult. In fact, C ++ is not only difficult to write a library, but it is also not easy to write an application in C ++-compared with other languages, it's just that the "abstraction and underlying" Thinking of C ++ writing libraries should be considered at the same time. All the root causes are the incomplete abstraction of C ++ ".
I don't know how much the close combination of the abstraction of C ++ and the bottom layer will impair the enthusiasm of C ++ programmers for learning, this affects the popularity of C ++ applications and the quality and progress of software projects.But at least for those who want to become C ++ programmers, they must recognize the fact that "the abstraction and underlying nature of C ++ must be mastered at the same time, in order to thoroughly master C ++,This is what I often emphasize when teaching C ++ training courses for enterprises and individual students.
Of course, the C ++ community is aware of this problem. c ++ 0x also establishes a principle of "providing support for both experts and beginners, see Bjarne stroustrup's c ++ 0x Overview Speech at last year's c ++ Software Technology Conference. However, at present, the implementation of this principle is not satisfactory. For example, if a C ++ programmer does not understand the underlying machine Models mapped to pointers, objects, templates, and concept (new things in C ++ 0x, you can easily write the draw_all () that Bjarne demonstrated in the C ++ 0x overview () example-although Bjarne stroustrup expects all c ++ programmers to think it is "so simple!"
Maybe we should not have expected too much for C ++, but want to make it have the ultimate efficiency to construct system software, I also want to make it purely abstract to meet the changing general software development-There seems to be no perfect thing in the world, of course, there is no perfect language :)