C 's dunk and love
Author: Hou Jie
1998.09.28 published
Every year's 09/28 in me is a special day - not just because Teacher's Day. This year is very special, there is no Putian celebration, then I will write an article I will celebrate it.
I published a lot of reverberation in July this year. These works are not written for the full beginners of C , but from the first-order to high-level as a large number of C guy, they enthusiastically express their joy of these topics.
In many letters, I see some interesting phenomena and feel some ideas worth finishing. Therefore, according to my personal learning, my teaching experience, and the experience of friends around, write this article, or after the bacteria.
●
First, let me have a preamble of "multiple and virtual> one book:
In general, C is a difficult language.
C is difficult to learn, which is initially lied, and the compiler has made too much hands on our program code, so that we are ubiquitous. And long, facing new thinking patterns, so that we must reverse the usual thinking habits.
The easy-to-use of C is its huge elasticity, which can process unknown, future, etc. Data type.
Of course, it must be used first. If you use it bad or you can't use, "Write C program" finally became "using C compiler", which is a joke that everyone is tuned to each other.
In the context of "difficult", "easy use" is the driving force for us to follow. The more and more university information department puts C in a big course, which although it means that C is important, it can also suffer from the information recruits.
In fact, the maximum crux of "difficult learning" is that it is very difficult to have a book, and it is possible to see the importance of multi-model and virtuality. After we have a crude grammatical basis, we guide us to the most important idea, and In the process of establishing this idea, provide a sufficient essential basis.
● One of the difficulties
"C is a difficult language", this sentence believes that many people have a heart. C learning difficulty, one lies in the language itself too much "scene", in "paradigm shift" (thinking of the mode).
Traditional steps such as C, Pascal, Basic, Fortran ..., in addition to the look, it is slightly different, basically all the functions Call came to Call, and it is easy to master. You want to do the action, you can see a clear in Code. If you can't see, the big man is just the compiler to add a small piece of code to handle the stack (Prologue and Epilogue). This small code basically does Housekeeping work, you Didn't see it, there is no relationship (better), does not affect your approach to program logic.
C is not the same, C has too many and program logic's related action is the compiler to join us. In other words, the C compiler is our "plus code". If you don't know this section, learn C has a fog, fog is not fog, flower is not flowers. What code does the compiler have added to our C program? a lot of! When the object was born, the CTOR will be evokeed, and the Dtor will be evoke when the object is killed, which is the result of the addition. Set VTPR and VTBL in the CTOR, which is also the result of the encoded. When the NEW single item generates Memory Block cookies, an internal structure is generated when an internal structure records Object Size and Class CTOR ..., which is also the work behind the curtain. It can be said that there is no action in the program code, but all the operations related to program logic, all the results after the C compiler is encoded.
When "inherits" occurs, the entire situation has become slightly complicated. "Multiple inheritance" is more complex, "virtual inheritance" is more complex.
The subject behind these brazles, is crised as a so-called C Object Model (object model). If you don't know these underlying mechanisms, you can only bring the rules of "Make Destructors Virtual In Bases" (
● Two difficulties
The second learning difficulty of C is "Paradigm Shift" (the movement of the thinking mode). Don't say yourself design Classes, light uses others' classes, it is a way of thinking patterns and behavioral modes. MFC (or OWL or VCL) Programmer will inevitably appreciate and experience what I mean.
Using the so-called Application Framework (a large, cohesive, there is a Class Library, which is the use of the object to the public base construction, what is the relationship between your code and FRAMEWORK? What is the meaning and value of a large heap of Framework offering a rewritten virtual function? Why is the beautiful nature of the Framework design and a wide variety of algorithms that can be implemented on the Class Types we designed? When Framework is designed, don't know our existence!
This is the power of polymorphism in the object-oriented.
Earlier C object model, the low-level surface of the offset design; the thinking mode is transferred here, it is the high-level surface of the program. Ability to play the power of new thinking patterns to the most exhausted Polymorphism (Multi-type) and Generalization (generic). If you don't use these two features, it is equivalent to C Tao Mountain to return.
● Anti-refining, cycle shock
Imagine C is a knife used to resolve the program, if it is strong, if it is sharp, you must pass multiple temperings, refining between high heat and quenching. After the beginner C syntax (SYNTAX), you should try to experience Polymorphism as soon as possible (which is the use of virtual functions). Waiting until the spirit of OOP has a biggest control, but many small details for C are not very clear, it is the time to return to C object model.
Growth, it is a high-order (Object Model) to vibrate to a higher level, not a flat water that is flat-intensive in the mid-order (C syntax).
● Do not indulge in C Syntax
100 people told me that he understood C / OOP, only 10% couldn't let me think he didn't blow the atmosphere. Too many people don't get Polymorphism, and I will not get the Object Model. In this way, it will not be able to at the C grammar level. I learned C , I graduated from the big four, and even the Virtual Functions was about the time, I didn't say a truth.
Sometimes I think that the students are too cars, because the students are in a state of ignorance, neither know how C / OOP should learn, and I don't know which books can teach them. Therefore, if you are guilty, you are better to blame your teacher.
As we all know, the University professor Thai is the moving port. The general mentality is "the first, the promotion is to be; the program language? Hey, the last flow!". The "last flow" course is usually taken by the professors. Whoever is going to teach; then, there is often a "next semester to teach C language, this semester cold (summer) is going to make a book to come to evil." Biaser language, this thing, only the mouth does not care, must do it, and always do it. The teacher did not touch the spirit of C / OOP, what can students learn?
Some school information systems do not teach specific programming languages. The attitude of teachers is "language is something that they have learned, getting the college hall, hey, do not enter the stream"! So I should take the actual basis for the students, but I will drive my fog from the sky, talk about the abstract ideas. Teachers who are full of readers may be ignored, a student who has no technical foundation, is not a shape, but the shape of the device.
Can we enjoy the pictorial painting first, or can we enjoy abstract painting? We are not all the first to paint the painting of Bicaso, until your art is rich enough, life is more full, and you can have a three-signs, you can contact the class bypass, Can you enjoy an abstract mood that you can enjoy and even enter Picasso?
The teachers have a specialty, and the teachers have to teach the big class lessons of the country, the basic class, I think it seems to be too difficult. Then, the teacher is not as blaming the school authorities. If the school authorities can hire experienced and teaching enthusiasm to teach such practical disciplines, isn't the tripartite? Don't say what system is rigid, it is difficult to break through, university is a high degree of autonomous region, and a few parties and teachers are hired. Is it within the scope of rights?
When students don't learn what he wants in the course, you have to be self-study. However, sequential language has the possibility of self-study, the object-oriented language, in the extent of college students, I think self-decoration is really difficult, will only repair a four unlike, half a bottle of water. Can't get a school! Can't ask professors! In the case of Du Fu, I hope to see this article, know how C / OOP should learn.
● Don't add C Semantics and C Object Model
For friends who have a strong interest in the underlying knowledge, explore the Object Model field, which will be very happy to play between Object Size, Object Layout, VPTR / VTBL, and many of the technologies after many curtains. Understand these things, of course, it is good, but because a look is to have its mysterious pleasure and accomplishment, some friends have "play" in this level, and the small place is very fine, it's not easy. , Play the ultimate goal of C / OOP.
The ultimate goal is Polymorphism!
I want to say, don't play too much in C Syntax and relatively low-order C semantics. It's okay, it will hurt. Some exercises attached to the C classic books, I have a little bit of flavor. As for what is the selection of babies, the question bank is boring, in addition to the basic skills of practice, all are full of interesting things.
Programming should be a combination of Tiamao empty imagination and creativity; if you can think about the topic, such as a Class system that is actually running, or a livelihood classification (interior of the interface) system, not very Is it interesting? In the process of preparing the information, check the encyclopedia, and then I also found the geometric information of the nine planets in the sun, the orbit cycle of Harley, or the "Interview of the Interview", this is the name of the English name, this Isn't it interesting to be more interesting than Dr. i or ---- I or * & * & P? (I have seen a lot of such a funny question, no one, I have to write a few arithosome. You should know the mind of the mind I said)
Although, in the field of science and engineering, there is no technology, but don't make yourself too rigid, too much. The rigidity is the largest settlement of our education system. At the high level, the defeat is revealed.
● Recommended
If you don't introduce a few good books, I am doing definitely.
Let me have another two brush test questions: multiple and virtual>:
1. C Primer (3 / e), lippman / a.w. / 1998 (I heard that 1999 will have Chinese translation)
2. The C Programming Language (3 / E), Bjarne / A.W. / 1997 (I heard that 1999 will have Chinese translation)
The above two books are C classic encyclopedia. In terms of content, I think the same is prosperous. The general impression is that the first is more acceptable, and the second is slightly. Second book author bjarne is a c language creator, so there is its authority. I know a multipart C / OOP master, all two books.
3. INSIDE THE C Object Model, Lippman / A.W. / 1996 (Medium translation
The whole book explains C Object Model, and the pool is falling into Huangquan. The content is very good, the level is also high, but unfortunately, the original instrument is large and small, and it is necessary to be careful when reading.
4. Effective C , Meyers / A.W. / 1992 (I like Chinese translation, the name forgot, who can add?)
5. More Effective C , Meyers / A.W. / 1996 (Is there a translation? I don't know, who can add?)
The two books of the same author, specializing in C Programming, making your program more robust and more efficient. Many of the concepts involve C Object Model, mixed with (3), such as fish.
6. POLYMORPHISM IN C
On the basis of grammar, the readers directly guide the most important idea and provide a sufficient necessary basis in the process of establishing this idea. I only list a Chinese book, because I have few Chinese books in this area, and the English book is much more. "Deinariary of the rodents of the pearles", "Eight-Party Degree", or say it. Note that these are just books that have been used in this solid yuan, and it is readily viewed in large-scale experience, as well as Large Scale C Software Design (John Lakos / A.W. / 1996).
OO's world, more than OOP, and OOA / OOD, that is also a piece of learning and a book of a cylinder.
--- End