Reconstructing a function of a function

xiaoxiao2021-03-06  151

Reconstructing a function of a function

Reconstruction is more than just a kind of thought, but also a technology. The "technology" mentioned here emphasizes that the reconstructed operability is very operability. After practical, I found that it can be reconstructed not only according to the understanding of the code, or it can be refactored according to some code. This is I originally ignored, I just used to feel the function according to the function of the code, and reconstruct it according to the function of the code. This has certain limitations. If you get your hand is a unfamiliar code, you can't do this. So I re-read the book and discovered the reconstruction rule on the serious understanding of the book. Step by step by step is the safest and most accurate method. So I said that refactoring is more than just a kind of thought, but also a technology, it is necessary to practice, cooked to master it, not like me, it can be mastered. This is my new understanding of the reconstruction.

Some ideas summary (multi-shared form talks about the function, mostly for reference only) First, see if this function needs to be refactored to determine the basis 1) The function is relatively long, more than ten lines. I would like to refact it. 2) A function is good, I personally think that it is simple to speak from the form, the smaller the completion, the better. It is also said that its function is better than "simple". This way I feel that it is logically easier to understand, and readability is best. One way to judge this is to see how many variables have changed in this function function. I feel that this function introduces how many parameters, in addition to the function he calls, it only changes or affects a variable as the best. That is to say, his task is single to only one variable, this variable or partial variable (finally calling it Return to the method of calling the function), or a member variable of the class (the function of the function, changing the class member variable, Using a method that requires it as a parameter). This way, I will take a function, he changed a few variables, and if more than one, I have to recover it (of course, this is not absolute, but also strictly considers).

2. It is important that a functional partition function reconstruction is important to optimize the code, making it easier to read. This time, according to the semantic function, the function is first to be considered, I think. Because of its understanding of your own understanding, the code is easy to understand for reconstructed, and readability is best. If the recipient has a deep skill, its division is relatively close to everyone's understanding, then the code to be reconstructed in this idea must be readily readily readily read. There is a way here to operate, I usually follow the annotation of the original code, one of the following sections below is divided into one. Use # region [to try to reconstruct the function name] and #ndregion enclose. This is suitable for overall movement. When you enclose the entire function, the idea of ​​code is very clear. You can then shrink other blocks, only to expand the part of the currently reconstructed, concentrate on refactoring it.

Third, the code reconstruction of a pair of # argion 1) You can repeat the second method to function further divide the code in #REGION. Until you use the two principles to judge this code to look good. 2) Reconstruction of Code in #REGION using the reconstruction method.

Fourth, the reconstruction of a function code that is difficult to understand When you think about the function of the function to be reconstructed, that is, when you can't start to divide the #Region block, you will be more from the code. The form is considering reconstruction. 1) Determine whether to replace it in accordance with the principle of the determination function as the judgment function mentioned in my one - a good function should be only modified or affecting a variable. We should first look at the role of local variables. Usually I first find the declaration of each partial variable, then shield it, and then look at the mistakes you have produced. To see the scope of the variable. If it has not been changed from the first assignment, we will put it Replace Temp with Query. If it is changed, then use #Region to enclose the first time from his statement to his changes. Take this part as a reconstructed research object. Remove the FLAG flag variable 1 in the loop, Flag must be removed 2, if the FLAG is again assigned again in the loop, it can be replaced by Return [value] again. 3. Otherwise, Break can be used.

The basic steps of the inter-object mutation feature: 1, package - the characteristic package to be moved (if the function is deemed to the Field, the function name is a package of the function) 2, move - the characteristics that will be packaged Includes a function body) Move to another object (if it is a function to set the function declaration in the Target object). 3, delegation - will move to another object to delegate 4 in the package function, remove the entrusted note: Each step is running, after running the next step

Movement order: First mover the Field removal method. In the way of movement, you encounter other Field, which is moved, first move it to move the function package.

Specific steps: For a field, after executing to 3, use the Find Tag Tool to find all functions that call the package function. It is found in the function to try to move it - repeated 1234.

When the current program is not achieved, you want to reconstruct it with other methods. You should first move the function to a different class to simplify the current interface. Then try to replace the implementation.

----

转载请注明原文地址:https://www.9cbs.com/read-127971.html

New Post(0)