Black box: between theory and reality

zhaozj2021-02-11  241

Black box: between theory and reality

The programming field has an old and evergreen law, that is, "divided into and cured." According to this rule, a realistic task, no matter how complicated, it will eventually be able to break down into multiple separation and independent small tasks; a task only completed a specific function, it is agreed between it and other tasks "Interface" communicates with each other without having to care about how the interior is implemented.

In the early days of programming, there is no concept of subroutines, all instructions are executed in a main program - there is no clear distinction between the sequence, branches, and loop structures - when the code exceeds hundreds of lines, Whether it can be seen, it has become a problem. The programmer at the time had a clever way, that is, when the program is divided into multiple pieces, when performing a certain function, you can use the GOTO to jump to the office, you can return it after the execution is completed. Although they (them) did not realize that this is actually a rule that uses the "divided into rules", the program is logically divided. And it is undeniable that although it is now regarded as something that is not worth advocating and should be abandoned, the GOTO statement does not have an irreplaceable role in the original period, otherwise the size of the program cannot be further expanded.

But this way of dividing programs will soon incur a criticism. Of course, this criticism is also quite fair because although the program is logically divided, the variables in the program can be accessed anywhere, which is very easy to cause the variable that should not be rewritten, and this error is also very It is difficult to find and eliminate; (I also saw a Basic program, 100 lines of code, no subroutine, no subroutine, there were more than 30 of us, and all our students were wounded - the teacher actually Take such a program as an example to learn.) Goto's question is that the program execution process can only be jumped, and it is impossible to hide the hidden thing, and the data hidden principle is a natural attraction of the rules of division. Things have developed to this step, there should be a revolutionary progress, so there is a concept of subroutine.

Although not like "object-oriented", as thunder, the appearance of the subroutine is indeed known to a true great progress in the program history. Imagine look, if your program can only have a master, can you write this program how long? The rule of "Separates" also has played its power here. It is because it guides us to avoid the entangled GOTO and bloated main procedures, starting a new stage of division of labor, coordination and cooperation - its meaning and human The first social division of society in history is comparable.

Since the 1980s, several trends have appeared in the world, and the result is that "object-oriented" programming models are deeply rooted. Needless to say more, as long as you think, you will understand, although the performance is different, the thoughts behind the revolution are a consistent, that is, the rule of "divided into and hidden" is higher. . The subroutine is provided just the functionality that is not related to each other, and the "object" or "component" is reflected in the complete functional entity. For an alteration, if the subroutine is part, then "object" or "component" is a complete machine, and these machines can be combined to form a complete pipeline. I have been born in Schi, the amount of the amount of the company is, because we have the programming tools and the programming ideas of the mastery, it is already the product of the machine's era; but only two or ten years ago, our seniors still in the knife The original era. According to the idea of ​​"Separate", we have programmed the machine produced in this large factory - whether it is called object, the components should be a "black box", except for the producer Other people just know how to use it. People advocating component-programming even have such a dream, thinking that one day in the future, we almost don't have to encode, as long as you put a variety of components, you can complete an actual application.

If things are really like this, it is very good. Our programmers will be divided into two categories, a component that is only responsible for the production of specific functions, do not care about calling it; another part of people are responsible for assembly - probably like the installed personnel in the computer city, sound It is high-tech, gaining people, in fact, as long as it will insert the card, the screwing screw is almost, and there is no high quality.

"Black Box" is really the terminator of all our programming puzzles? Mr. Houjie had such a pass in his "deep-in-depth MFC", which made me impressed:

Many friends have explored me with me: What extent should I dig excavate to MFC this type of Application Framework? Exploring the original code, don't you violate the original intention of "black box"? However, there is no way, they also agree, don't know those wonderful monsters, can only produce toys.

Very strange, when we dream of living in a beautiful programming life, Mr. Hou wants us to come down to hell, go to the "black box" to experience a painful reincarnation. What is the problem?

Most of the software engineering uses the construction project as a comparison and imitation: they even compare the components in the program as the bricks in the construction project, think that they can create a skyscraper on these bricks.

But and slow. A slightly more common sense should know that in modern buildings, the building materials for bricks and tiles have become increasingly subtle; the real useful building materials are cement and steel. Cement and steel bars are not a material: cement needs on-site pouring, there is no prefabrication and can meet a variety of architectural shapes; the situation of steel bars is similar, how much is used, how is the length, how to bind, how to The setting is required to be completed. In the programmed world, whether it is object, the components are all, in the current situation, it is more difficult to achieve similar "existing raw materials can be utilized, and the flexibility of the field customization". If the object of the object is to be modified, no matter how the source code level; and the component (such as the component concept in COM), in order to achieve binary compatibility, the interface is defined to die, there is no change, I am afraid it is not good. select.

Interestingly, "Exploring the insider of black box", no matter how much MFC, VCL is good, there is no shortage of researchers, or even now, Java's source code is also started to study. And in fact, I have to admit that sometimes in order to achieve a certain function, some undocuMented things must be used. If you don't know what the "black box" is, just look at the ocean. There is even a small number of people began to doubt, and the application framework is really good. It should be learned, but it is more appropriate to learn the pure API. Some people have begun to question C , think "C may be a scam ..." (everyone saw the joke "C inventor interview". History is always developing forward, this is unquestionable. The new things we face, object-oriented, the components are good, Application Framework is better, which is more advanced than the past and cannot be more backward. Of course they are not perfect, and it is impossible to solve all the problems we have encountered. (Computer vendors always tend to declare us with the trendy advertising words, as long as they use their products, they can solve all the problems we have encountered - this has also been, but some computer books are in order to improve sales, and put the opening place. It turned into these untrusted stores, it is really evil. Don't believe this set, programming will never be a very easy task.) And can solve the old problem while it is possible Bring new problems; but we can't deny its role, just like the industrial revolution brings economic prosperity, it also brings environmental pollution and a variety of social problems, but we can't never return to small farmers. Go it?

We should understand that "black box" is very good, very useful, but it is the ideal world product. Another strong law in the real world is that ideals and reality have always have gaps. Despite the construction of a black box strive to hide its internal mechanism, there is always some cases in reality that the designer did not have or impossible. A good example is the runtime in the C language. It is quite perfect. It has always been working very well from the invention so far, but since the concept of "thread", the original perfect structure immediately faces unprecedented crisis - operation Many functions in the library cannot do Thread Safe at all. We certainly impossible to accuse the inventors of the running library, how can they expect what happened in this kind of thinking? Another good example is the emergence of Unicode, so whether it is the running library function of the operation string, the API function is still there, and now there are two different versions of ANSI and Unicode. This shows that regardless of how the designer of "black box" is carefully planned, it is impossible to always meet all needs in reality, or it is still effective over time.

One point of view:

1. The so-called "as long as there is a suitable component, it can be easily established an idea," in the modern large program, can only be an empty idea. (Volume change): You can set up a standard dog nest with several prefabricated boards, but in dozens of or even hundreds of buildings, it is very rare to use the prefabricated materials.) I think that the key is not Is there a good component, but there is no reasonable and complete production, modification, and maintenance of components. My ideal components should have the nature similar to cement: very plasticity, can be planted into any shape, but from the production of cement, there is a set of mature stability. Our current component model, still can't meet the needs in the elasticity, and there is no set of standard machining technology. To use it to build integrity, it is far away. 2. "Black Box" is a good concept, as long as it may, we should try to enjoy the benefits of it. However, the correct attitude uses it rather than relying on it. As long as it may, we should try to understand its underlying mechanism, so that you can not do it if you have a special problem. As long as you don't have a rhurner, you don't just see the trees, this understanding is good. (As an architect, it is impossible to be a person who will only draw a drawing and calculate the material; he must go to the site to practice, you can see how the reinforcement is tied, how to block mold, high How to determine; if there is no such actual experience, he will never be a good architect. Although he doesn't have to take a steel bar in practice.) As a programmer, we should also complain to learn 3 Delphi, still only put Component on the Form, can't find the functions, just waiting for a better component, but also Delphi misunderstood him. Such a person said that the programming tool misunderstood him. It is better to say that he uses the programming tool, only staying at this level, do not want to make brains at this level, do you want to make brains at all, and what else do you have in the computer city?

3. We are all discussing the reuse of the code and the reuse of components. I think we can also improve a level, how can we achieve the reuse and ideas of the method. The foreign master has been "Thinking In C " "Thinking in Java", although the programming language used to express is different, but the idea and spirit of the reflection are connected, it is fully able to span different programming languages, even different platforms and different The barrier in the field. In modern software, the location and role of encoding is increasing, and how software reflects the designer's thoughts and intentions are the first. Discuss differences or exceptions between different languages ​​or different compilers, in fact, there are not much sense: whether it is a programming language, as long as there is a good program habit, it can clearly express the intentions of the designer. Interestingly, even if Zhao Yuan is yet, Qian Zhongshu's language masters, will never discuss "Chinese and English" as a problem; but some programmers, even ginseng soon, but also very passionate What is it more than the master?

Postscript: After writing, I found a bit run, anyway, it was essay, everyone was a game text.

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

New Post(0)