The author of this article, Elliotte, is a famous IT author who has written more than 20 programming books, many of which are published in China, such as restructuring HTML: improving Web application design, he is currently working on XML processors XOM, jaxenXPath engine and Amateur media player .... "> <LINKhref =" http://www.php100.com/
The author of this article, Elliotte, is a famous IT author who has written more than 20 programming books, many of which are published in China, such as restructuring HTML: improving Web application design, he is currently working on XML processor XOM, jaxen XPath engine and Amateur media player.
The text is as follows:
Last week, I was deeply inspired by a colleague's point of view, which was so obvious that when he said it, I was surprised why I didn't realize it before:If you design for reuse, you will be wrong.
The only purpose of the code you want to write is to serve the tasks you need to solve at hand. Do not design for reuse. Do not consider reuse. Do not waste one second for code reuse.
In fact, any code you need that can be reused already exists. Do you want to connect to an HTTP Server and fully support security authentication and cookies? It sounds like many projects can be used. so you want to encapsulate it into an easy-to-use HTTP class or shared package. isn't it a good idea? Error. You should use Apache HttpClient.
Do you need to solve the initial value problem of your parabolic method? Don't go over your numerical analysis textbook. what you need to do is download Flanagan's Java scientific computing library or buy a NAG license. Do you want to make a calendar component for your colleagues? Directly tell them to use JCalendar. Although it is not exactly the same in appearance and usage as you think, it is enough. If you plan to make your own components or find an existing modification, you will find that the different performance effects you have developed are not suitable for other people's applications, do not waste time developing reusable code.
These examples are for Java, but they are applicable to other mainstream languages, such as Perl, Python, Ruby, C ++, C #, and Scala. In fact, if a language cannot provide reusable code to solve your problem, you are choosing the wrong language to solve your problem.
Is there any exception? I can only come up with two (so far I don't feel like there is a third case ).
The first exception is that you are developing a new thing,The class library you need does not exist. you are the first person to enter this field.You need to write reusable code. For example, when I first developed the XIncluder class library, the XInclude specification is still being formulated. you cannot find the second available class library in Java. The class library I wrote proves the implementation of the specification and promotes the development of the specification to a more complete state. It was wise to develop my own XInclude class library ten years ago, and today it will never be done again.
The second exception isFor expert, I'm not even sure if this is an exception. If you are a real expert in a certain field and have reusable code to solve problems in your field, you have carefully studied the existing solutions, you think they are not perfect. you are looking for a better solution. in this case, you can only consider writing reusable code. This is why I want to develop XOM. After I write hundreds of pages of books and carefully collect various APIs for processing XML in Java, I understand their advantages and disadvantages, I think we should sit down and design an API to change it into them. Although I think that the api I designed is the best API, I am still not sure whether it is worthwhile to spend time on it. XOM, in my opinion, is better than any previous API, but it is not as good as it can replace other class libraries in a large number of other projects. The demand for this new API is not really great.
Are there any other exceptions? In another case, do you need to write reusable code? I cannot think of it. So many programmers have spent so much time exploring problems in our lives and sharing their achievements on websites such as Sourceforge and Github for free. Of course, new problems will continue to emerge, but you will not be able to get much benefit from some old problems if you study them again. Next time, if you find that you are designing for reuse, stop and ask if you can reuse others' code.
[Original English: Don't Design for Reuse]