GP and OOP, my thoughts

zhaozj2021-02-08  418

To sna_daniel et al: Is it IS-IMPLEMENTED-IN-TERMS-OF? Hope is not. Because this is just the opposite of the Implements keyword in Java. The former is to achieve inheritance (combination), the latter is inherited. You also know that Java's interface is equivalent to the pure virtual abstraction class in C , in order to avoid introducing multiple inherits, Java uses this concept to express IS-A relationships. Of course, Extends is also an IS-A relationship, but it has the meaning of inheritance. Only public inheritence in Java, so IS-IMPLEMENTED-IN-TERMS-OF JAVA can only be completed in Java. If you want to get more, there is an article is IS-A, C View third phase has an article very clear, Can go see. I summarize the views in this post, oppose the netizens who regard GP as independent thinking, basically there are two arguments: 1. All functions in STL can be "easily" in a typical OO language. So, GP It can only be considered to be C to overcome the side branch developed by the insufficient dynamic capacity. It cannot be counted as the mainstream of the OOP parallel. 2. GP only provides efficiency advantages, and the efficiency is relatively good, it is a small problem. Therefore, I can't count independent thinking. I want to draw a little time, talk about my understanding of this issue.

First of all, although everyone can realize STL in dynamic language, it is very clear that it is just the simulation of STL, it seems to be different. Even if we ignore this, there is actually no dynamic language simulated STL can be counted as comparison Success. But some language fans seek psychological comfort, or the theoretical show in scholars laboratories, such as Jal. There have been a Java class library called JGL, it is a relatively successful. I used it to write actual procedures I really have studied JGL, but I will live and return to it. In fact, all the features of a STL are definitely unlike everyone thinking is so simple, the huge deficiencies on abstract ability must rely on cumbersome, unsafe. Dynamic type identification mechanism, in huge single inherited trees, extremely laboriously simulated. And some things, such as Functor AdapTor, you have no way to use STL as concise performance methods. So, if It can also be called "easily, natural", then I can claim that c is an object-oriented language. If someone does not believe, you can try to do a small STL yourself, see if there is no template means something In contrast, even if you can draw the STL simulation, you can explain what problems. Don't forget that STL is the product of C Template thought, you are just an imitator, this is the gap in this It seems that the gap between the emulation of the truth in the show. If you think STL is only the natural extension of OO thought, then OOP has been popular for 20 years, and there is no status of STL, and Template is in C Zhongan family For about 5 years, STL is amazing? If you think that there is a complete support, you can do not need STL, then how do you explain Java / C #, do not have to join the generic capabilities, how to explain it? Multilingual advocates simulate a STL's effort? The answer is only one, STL and the GP it appears, and there is no thing that appears in the past. We will return to ask a question, what is the idea to reach? The degree, can be called a thought? Our Chinese is probably being too deep, and everything likes to go up, abstract abstraction, the level is getting higher and higher, the top floor, oh, It turned out that GP is alright, did not escape from OO concept! Probably my philosophical level is not high, then Kant's Not read, so I have no ability to go to World Trade Building with everyone The top level (oh, sorry, I forgot, the World Trade Center has not : - <) Discussing that Xuan Xuan. I am a programmer, I have to do the work is not an abstract philosophical discussion, but the actual software, write code that can be efficient, reliable. If you ask me GP What is the feeling of a normal programmer, I will tell you: a whole new world! Really, my current target platform is Wince that is limited in memory and processor, and the classic Win32 is not big. I have also touched these things, but now, it is because I think the problem, the evaluation design is even written in the way each line of code has changed. Take a look at today's C community, how innovative ability, many things have never thought about it, now dare to think, and give a wonderful solution, let people feel unbelievable, after understanding, I can't help but call! I Sometimes I feel that GP's most attractive place is this.

Tell me you read the following code feeling: template struct WinStyleTraits {static DWORD GetWinStyle (DWORD dwWinStyle) {return dwWinStyle == 0 t_dwWinStyle:? DwWinStyle;}}; typedef WinStyleTraits <> CUserWinTraits; typedef WinStyleTraits COverlappedWinTraits; typedef WinStyleTraits CChildWinTraits; WTL simplified version of this code is a little thing, to provide conventional Windows-style user, is transmitted to the CreateWindowEx (function). Experience, see how smart it, think about why an OOP programmer can't actively invenment this. (Incidentally, this class name is similar to Traits, but it traits is not very strong, at least I think so), look at here: Template Class Auto_Ptr {Private: T * Pointer_; ... public : Template auto_ptr (u * p): Pointer_ (P) {} ...} This is a typical GP usual method, Template Contructor, this mystery and fun, it is happy, and C Looking for it. It is also possible to mention countless examples, but the conclusion is that the use of GP, your design idea has changed, the angle of the analysis problem changes, the method of writing code has changed, the scale of the evaluation process changes, for the entire program structure and software construction The view has also changed, if you still tell me, in fact, I didn't change, my "thought" is the same as the previous OO, or my current thought is just the vassal of OO, then you are crazy, It is what I am crazy. Object-oriented as a great software thought, not light is in full swing, and will definitely leave glorious footprints in history. I am hard to imagine that there is no Object this concept in the future software construct. However, a large complex derived level, the number of clumsy design has a lot of complicated objects (Remember the words of Grandy Booch say? "If you find that the class is not enough, please consider the number of objects"), it is difficult to Empirical software development process, unbearable resource waste (don't tell me how fast your computer, you are clear that the money to buy more "fast" is for what is for me), I have made me feel that this road is impossible for a long time. Walk down, one day in the morning, everyone will change the sum. Finally, I want to show that I have a basic expectation for future GP programming ideas: 1. Object remains the basic unit of the constructor. But at the same time, there is an abstract operation as another basic unit of the program. In the historical law of screw rising, we returned to the idea of ​​"program = data structure algorithm", but this is much higher. 2. Only very limited and very clear derived levels, the objects are not over-complex relationships, except for simple derived relationships and combined relationships, other relationships are completed with the static polymorphism of compilation period.

转载请注明原文地址:https://www.9cbs.com/read-312.html

New Post(0)