When designing programming, we often implement it according to specific problems, but lack the motivation to extract commonalities.
Why is this? I think it is a complicated mental work to extract commonalities. Do people have the energy to do this complicated and heavy mental work after they finish their work on time?
Therefore, I believe that it is meaningless to blame people for not refining and reusing them. To improve this problem, we can cultivate a code habit that can improve reusability. Once this habit is developed, we can easily write some code with relatively high reusability.
1. Interface-based programming. Develop a good interface specification (based on the caller's needs) and complete the internal code. This isolation can avoid excessive speculation about the implementation and reduce the caller's dependence on the specific implementation.
2. Function specialization. Each interface should only contain a closely related set of function call specifications.
3. The main process calling solution is a configuration factory, which is responsible for the caller and implementation of the configuration factory.
4. Reduce ambiguous and fuzzy definitions. For example, a magic number or an identifier with unsatisfactory words.
5. testable. Code that cannot be measured is useless to projects. Test immutability. A set of consistent states and outputs are generated under the same input and state.
6. Increase the problem handling scale. There may be little difference in coding between solving a small-scale problem and solving a large-scale problem. Therefore, we must be good at analyzing the problem from a relatively large scale and solving the problem.
To be continued