Translation Tipatterns - Preface & Ready (Introduction)

zhaozj2021-02-16  98

Preface The content of this book is from me (most of the time and Bill Venners). Bill and I have a lot of lectures, and in the past few years, with our own knowledge about the model and how to do well, the content of this course has also changed significantly. In this process, we have accumulated enough information that we have their own work, but we don't want to do this, because we are trying to be too interesting. We held a lecture in the United States, and we were still in Prague (we tried to hold a small meeting in spring and other lectures). We have also set it out of-site lectures. I would like to express my heartfelt thanks to those who participate in these lectures in these years, they help me clarify and extract a lot of ideas. I hope to continue to summarize and develop similar ideas through this book and the lecture in the next many years. This book will not hit this. After some careful consideration, I plan to write Thinking in Python's Python version of the book, not to introduce the Python language. (There are already a lot of good textbooks to introduce this outstanding language). I think this is more exciting than the labor and writing a language manual (I want to write Thinking In Python, I'm going to write Thinking In Python.)

introduction

This book is about design, I have been working in this work over the years. Basically, from my first tried to read "Design Mode" (Gamma, Helm, Johnson & Vlissides, Addison-Wesley, 1995, often referred to as "Tour Guide" or GOF).

One chapter in Thinking In C is specially designed in design, and then I put this chapter in the Volume II of Thinking In C Second Edition. And in the first version of Thinking in Java, you can find a chapter is about mode (I took it in the second edition, because this book is too long, the reason is that I intend to write now This book). This book is not an introductory book. I assume that you read Thinking In Java or other textbooks before reading this book. In addition, I also assume that you have a certain degree of understanding of Java's syntax. You should have a deep understanding of "object" and its connotation, including polymorphism. In addition, these things have explained in Thinking in Java. On the other hand, you can learn more about object-oriented programming in the process of reading this book. If you only have some initial awareness of "objects", these awareness will continue to deepen in the process of understanding these design methods mentioned in this book.

Y2K syndrome The subtitle of this book is "technology to solve problems", so there is a need to mention a large trap in the field of programming: premature optimization. Every time I put this opinion, everyone is actually agreed. At the same time, everyone seems to keep their own Special Case in their hearts. "Just I happened this."

Computers are mysterious to many people. So when someone claims that the stupid programmers have forgot to use a sufficient number of numbers to save the date after 1999, everyone has become a computer expert - "These things are not difficult, if I pay attention to it. To this shallow problem. "Take me, my background is initially computer engineering, I first embedded system programming. Therefore, I know that many embedded systems have no concept or time, even if they are, they will not be used for any important arithmetic occasion. I am clearly informally informing all embedded systems to be in January 1 January 2000. But as far as I know, only those who predict that the disaster will return the bigborship of the guys that will be coming. It seems that they have never said those words. I mean, we are very easy to fall into a thinking style, that is, some algorithms or code sections that we part or fully understand will become the bottleneck of the entire system, and this judgment is just because we pass this Some of the imagination of some known code segments determine that it is definitely less efficient than those we don't know. But unless you do actual testing, usually PROFILER? Otherwise, you can't really know the actual operation. Even if you already know that a code segment is very efficient, don't forget that 90% of the 90% of the programs is just a code that is less than 10% of the entire program. So unless you think that this part of the code is 10%, it is not necessary to optimize them. "97%, we don't need to consider subtle operational efficiency," premature optimization "is all troublesome roots" -Donald Kruth

Context and combined context and composition You will see that the most typical term in the design mode literature is "context". In fact, "design mode" is a common definition is "Solution for a context-specific problem." These patterns of GOF will often contain a "context object", and the programmer using these modes is derived directly with this context object. I once thought that these objects seem to live in the dominant position in many models, so I thought that they used to dry. "Context object" often serves as "Facade" role to cover the complexity of other parts of the mode. In addition, it often controls the controller that controls the entire mode. Initially, I thought that these things were not very important for achieving, using and understanding the model, but I remember that there was a word in the GOF book to be very impressed: "PREFER Composition To Inheritance." Context object Allows you to use patterns in a Composition. Perhaps this is its biggest benefit.

About "Checked Exceptions 1" CHECKED Exceptions 1) Abnormal value lies in its unified error reporting mechanism: This is a standard error reporting mechanism, rather than those non-strong big miscellaneous error reporting methods like C. (And C just add an exception to the mixed error reporting mechanism, without making an abnormality a unique error report method) Java has a huge advantage that the relative to C is that the exception is the only way to report the error. 2) The word "non-mandatory" on the previous paragraph is another problem. In theory, if the compiler enforces the programmer or transfer exception according to the specification, then the programmer will always be taken to the place where it may be wrong, and these errors are handled in an appropriate approach. I think the problem is that this is just a hypothesis that has not been verified, and we are doing this assumption with the designer of language as a supervisor. My theory is that when someone wants to do something, but you keep urging him with a messy means, he will use the way to cover up the bored things, and you will not look back in the future. Re-take off those things. I found that I was doing this in the first edition of Thinking in Java. ...} catch (somekindofexception e) {} (I wrote above those code, then more less forgotten it until you rewrite it. How many people will think that this is a good example and follows it? Martin Fowler also noticed this problem, he found that people never do this after shielding these exceptions. The negative issues of Checked Exceptions have made it deviate from the original intention of designing it. When you test, you will find these problems. (Now I believe that checked exception is a testistic thing, some people think it is a good idea, until shortly I believe it is really a good idea). When I started using Python, all anomalies will appear, no one will suddenly disappear. You can rush your concern, but you will not be enforced to write a big code just to make an exception can pass. They (abnormal) will appear in their place you want to rush. If you encounter the worst case, you forgot to hurry, they will temporarily hide (you will prompt you later) and will not completely disappear. Now I believe that Checked Exceptions encourage people to make an exception disappear. And it makes the code readability worse. Finally, I think we must realize that the exception itself is experimental thing. We must examine it before assume that all Java exception mechanisms are correct. I believe that only one unified error handling mechanism is very good, I also believe that it is also good to pass an exception by using an isolated channel (an abnormal processing mechanism). I remember an advocate of an exception handling mechanism of C , that is, it allows the programmer to distinguish the work code and the error handling code. However, I think checked exception doesn't seem to do this; it is the opposite, it always wants to reach something in your work code, this can't be said to be a reverse. I use Python's experience to make this view, unless I change to this problem, otherwise I tend to use more Runtime Exceptions in my Java code.

table of Contents

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

New Post(0)