Introduction interpretative variable

xiaoxiao2021-03-06  110

Introduce Explainning Variable (introduced to interpretive variable)

Summary:

The result of the complex expression (or part) is placed in a temporary variable to explain the expression use in this variable name.

TIPS:

In the conditional logic, INTRODUCE EXPLAINING VARIABLE can be used to extract each condition clause, with a good named temporary variable to explain the meaning of the corresponding condition clause.

Comments by Allen Lee:

Inline Temp and Introduce Explaining Variable:

Both are opposite to some extent (appearance behavior). The former inserts the expression of the temporary variable into the caller to remove the temporary variable, but the latter refines the related expression in replacement with a temporary variable. The expression represented by the former to remove the temporary variable is relatively simple, generally used to store the return value obtained directly to a function or a member function of an object, such as Order.getResult (); (function style) Or Order.Result; (C # Property style); the latter to refine the expression is indeed complicated, at least a eye can see its meaning, such as TextBox1.Text.touppercase (). Contains ("@") ;. The former is generally for implementing other refactoring principles, such as Extract Method, paving roads; while the latter generally increases code, especially unacceptable complex expressions, readability. When optimized later, sometimes some expressions are relatively simple, such as Order.getResult ();, but because their internal algorithms are complex and only assignible once, if it uses Inline Temp to directly embed the callback side, then each time you need it. At the time, it will pay a lot of calculations. At this time, we may first take a look at whether the function can make Extract method, and then see if you can Substitute Algorithm, try to split the function, there is really no way, we can only retrieve the temporary variable to store the results once use.

Introducture Explaining Variable and Replace Temp with Query:

These two can be used in combination. When we find that some expressions returned, we can open them outside, then we can use Introduce Explaining Variable to introduce temporary variables, then use Replace Temp with Query to extract this temporary variable to a separate Query. These two combinations are sometimes equivalent to directly using Extract Method. So, if you sometimes find that the function to refine is not clear because the temporary variables are not clear, you may wish to remove the process method process into these two, often receive unexpected effects.

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

New Post(0)