1, big break small
The code function is divided into small functions, each function had better have a single responsibility, each function entry control in 3 or less, or can continue to be divided into smaller functions. The function needs high cohesion and low coupling. The same reason to do the demand is also to be small
if(a){ xxxxxxx xxxxxxx }else if(b){ yyyyyyy yyyyyyy }else if(b){ yyyyyyy yyyyyyy }...... Instead, one method checks the value of the input parameter and then calls the corresponding processing methodsCopy the code
2. Code efficiency
Reduce time complexity and space complexity
Loop less, don’t loop more than once, try to put all operations in one loop, for example, the process of the primitives in the flowchart rendering into the primitives rendering logic
Do not nest loop, you can turn some data into map structure data, through the map to find
3. Open and close principle
Open for extension, closed for modification If a situation requires adding an input parameter to function A, it is best not to modify function A at this time, because there is no need for an additional parameter elsewhere. Better to rewrite a function and call function A
4. Fail fast
if(! xxx) returnCopy the code