Some Suggestions on coding specifications and code Reconstruction

Source: Internet
Author: User

First, we recommend two tools: resharper and dotcover.

    1. The Code should be able to be read by others with less comments, rather than simply understanding the machine.
    2. If you think your code is ugly, You Need To refactor it.
    3. Avoid repeated code as much as possible
    4. When necessary, you can use static variables to save the queried data. We recommend that you set static variables to read-only and private, and access them through the read-only attribute.
    5. Treating static variables and static attributes differently
    6. Directly calling methods in static attributes does not improve performance, but static variables can
    7. Exercise caution when using readable, non-Private Static variables or attributes
    8. Code exposure is as low as possible (internal is not used to protected)
    9. The data type of the parameter should be as strict as possible (for example, use int instead of string)
    10. The definition of a local variable is as close as possible to its use, which facilitates code refactoring.
    11. If local variables are involved in the Code logic before they are used, they should be reconstructed as methods
    12. If a nested loop or condition judgment occurs in the code, this code should be restructured.
    13. We recommend that you use using to introduce the namespace, instead of writing the namespace to the Declaration when declaring the object.
    14. Remove unused using
    15. Remove unnecessary comments and deregistered code During refactoring
    16. Unless otherwise specified, it is recommended that a method not exceed 30.
    17. If necessary, you can use LINQ to query links of Multiple lists.
    18. Use List <t> instead of datatable as much as possible, which makes it easier to use and avoids excessive packing and unpacking.
    19. If you think your code is ugly, refactor it.

If something is wrong, please make a brick and correct it. Thank you!

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.