Improve reusability encoding habits

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.