Embedded efficient programming (II)-clear

Source: Internet
Author: User

4. efficient programming: Clear

Clear: the code is easy to read and easy to understand and maintain.

    • Simple logic
    • Brief code line
    • Function briefs
    • Comments (or self-comments)
    • Clear hierarchy

4.1 heavy code Header

Example: Multi-Level struct Variable Search

 
<Span style = "font-size: 14px;"> A1 = A-> B-> C. d. a1; b1 = A-> B-> C. d. b1; C1 = A-> B-> C. d. c1; D1 = A-> B-> C. d. d1; </span>

Assume that A, B, C, and D are long strings, such as A1, B1, C1, and D1. If there are many variables, the code looks very heavy. It is inconvenient to start writing and read.

Code modification:

 
D = A-> B-> c.d; a1 = D. A1; b1 = D. B1; C1 = D. C1;
4.2 function briefs

    • The number of function lines is recommended to be less than 200.
    • Complex functions are written into several independent subfunctions to ensure that the logic of the trunk is clear.
4.3 Module clear diagram (1) Unclear hierarchy
Figure (2) Clear layers.







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.