Talking about code optimization

Optimized code is divided into two areas:

A reduced volume of code. Second, improve the efficiency of the code.

======================================================================================

A reduced volume of the code

1. If you try to change the code to modify a focus, for example, to modify the value of certain properties, can write a unified approach to modify properties.

2. If there is a function to be used more than twice, you can consider it encapsulates a static method of writing in public in the Utils.

3. If there are more than two sub-categories do similar but different operating within a function, consider this function in the parent class abstract.

 

Second, improve the efficiency of the code

1. The time complexity as possible smaller (fewer nested loop, the higher the efficiency of the code). Multi-way filter may be employed to extract the target data when writing code, try not to use round-robin fashion extraction.

2. Do not write code interdependent, decoupled as far as possible (e.g. A Service-Service calls a method in the B, B empathy also called A, this is not possible).

3. Reduce the dynamic operation of the statement, would rather waste a little memory to process the data, and do not let it waste of dynamic operation CPU.

Guess you like

Origin www.cnblogs.com/ALittleMoreLove/p/11091086.html