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:
- 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
- You often can't one step to do so much optimization
- 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