The author of this article, Elliotte, is a famous it writer who writes more than 20 books on programming, many of which are published domestically, such as refactoring HTML: Improving Web Application design, and he is currently studying XML processor XOM, Jaxen XPath engine and amateur media player.
The following is the text:
I was inspired by a colleague's idea last week that was so obvious that when he said it I was amazed at why I didn't realize it before: If you design for reuse, you're wrong.
The only purpose of the code you are writing now is to serve the tasks you currently have on hand to solve. Do not design for reuse. Don't think about reusing. Don't waste a second of your code reusing.
In fact, any code you need to reuse is already there. Want to connect to an HTTP Server and fully support security authentication and cookies? This thing sounds like a lot of projects that you can use, so you want to encapsulate this thing into an Easy-to-use HTTP class or shared package, good idea? Wrong. You should use Apache httpclient.
Need to solve the initial value problem of your parabola method? Instead of looking through your numerical analysis textbook, you need to download Flanagan's Java Science Computing library or buy a nag license. Want to make a calendar selection component for your co-workers? Just tell them to use the Jcalendar. It's not exactly what you think it looks and how it's used, but it's enough. If you're going to make your own components, or find an existing one, you'll find that the different effects you're making are not suitable for other people's applications, so don't waste time developing your own reusable code.
These examples are for Java, but for other mainstream languages, such as Perl,python,ruby,c++,c#,scala, are applicable. In fact, if a language doesn't provide reusable code to solve your problem, you're choosing the wrong language to solve your problem.
Is there an exception? I can only think of two kinds (so far I don't feel like a third situation).
The first exception is that you are developing a new kind of thing, you need the class library 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 was still in place, and you couldn't find a second class library available in Java. I wrote this class library into a normative and achievable proof that promotes the specification to a more complete state development. It would be wise to develop my own Xinclude class library ten years ago, and it will never be done again today.
The second exception is for experts , and I am not even sure if this is the exception. If you are a real expert in a field, there are reusable code to solve your domain problems, and you've been seriously studying existing solutions, you think they're imperfect, you're looking for a better solution, and only then can you consider writing your own reusable code. That's why I want to develop XOM. Just after I wrote hundreds of pages of the manuscript, the detailed collection of the current Java processing XML in the various APIs, know their advantages and disadvantages, I think should sit down to design an API to improve them. Although I think the API I designed is the best API, I'm still not sure if it's worth the time spent on it. XOM, in my opinion, is better than any previous API, but it's not good enough to be able to replace other class libraries in a number of other projects. The need for this new API is not really big.
Is there another exception? In another case, do you need to write reusable code? I can't think of a. So many programmers spend so much time exploring the problems in our lives and putting their results on sites like Sourceforge and Github for free. Of course, the new problems will continue to appear, but for some old problems, if you go over them again, you can not get much benefit from it. Next time, if you find yourself designing for reuse, please stop and ask yourself if you can reuse someone else's code.
[English Original: Don ' t design for reuse]