The way to write graceful code, two habits: one step in place vs iterative optimization

Source: Internet
Author: User
Recently put this Android app all the transactional methods have been written, with the following experience, novice experience, the old bird patted want to write graceful code of people generally have this idea: must write every code, write each method, constructs each class, must remember the optimization : decoupling to reuse , splitting methods to reuse, using loops to reduce redundancy, limiting the number of cycles to reduce invalid operations, and so on. There must be nothing wrong with this idea, but many times it is often the case:
  1. When functionality is complex, for example you have broken down several methods, such as you have used several layers of loops (a bit too much ...). ), such as in multi-threading
  2. You often can't one step to do so much optimization
  3. This often causes you to write a code that will think for a long time
Of course, this is not bad, want to write can reduce a lot of useless, even if you think for a long time but always spend less, is a lot of experts advocate the way but for an ordinary person, you often need to realize that because of your ability to think, many optimization methods will be easier to find after writing the whole method, So the two ways to write code in time will have such a balance point : One step write the perfect code time = = First quickly write the function, and then modify the time required to optimize the optimization so you need to write in the normal process of the code to understand where your balance, and then according to the actual situation, Choose one of the ways to write and when you have to choose the latter, such a specific step is recommended: just try to ensure that the bug is not rigorous, while noting the place to optimize, and then write out the function, then if there is a chance, then back to optimize the above said is Time (efficiency) dimension , in this dimension two ways there is a balance point there is another dimension, is the ability to exercise the dimension , in this dimension one step is definitely over iterative optimization of the word here, and finally how to put me your balance point, is your own thing!

The way to write graceful code, two habits: one step in place vs iterative optimization

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.