Today is really happy, successfully put a 140, more than 4, more than 4, more functions, more than 50 functions (if the addition of the auxiliary function is calculated, and there is more than 80 lines) And with new, better methods instead of the original (this is why the reason for reconstruction).
The original function can work, but it is extremely long and logic is difficult to understand. I first put each sentence in detail, and then run twice, merged some redundant logic, and clarified the idea. Then you write the same new function as the interface instead of it.
Here I use a little skill, which is to define a new function with the same interface, and the old function does not delete, but passed the call to the new function at the top of the old function. This allows if there is a problem, you can simply comment and use the old function.
The process of reconstruction is more troublesome, I want to modify the original code, but its logic is a bit chaotic, and too long. So just write the logical framework in the form of a logical framework on the basis of your understanding. Then fill in the blank, each comment does not exceed two lines of code. Many code will be smashed out. When I finally finished writing, I have found that there are two places in my new logic. I am exactly the same from the code, so I am very happy to reconstruct the logic, more clarity.
In the current code, only one page of the logical part is fully clearly described. Although there is still room for continuing to refactors until the function does not exceed 1 page, I think this is enough. Whether it is my own or others to maintain this code, I will understand the program logic and it is easy to change it.
If you don't reconstitution, if you are logical, I may be able to still be trapped in more than 100 lines of code.