Take a look at Refactoring

zhaozj2021-02-11  164

Initial refactoring

You can't find this word from the English-Chinese Dictionary or Jinshan Word: Refactoring. Because it is an uncommon computer-specific term. Let's take a look at its definition (given my translation level, I will list it first):

Refactoring Is a Program Transformations That Reorganize a Program WITHOUT CHANGING ITS Behavior. Translate is: Factor Recombination is a conversion process for the reorganization of the program (code) without changing the program behavior.

Refactoring's proposal is the Ralph E. Johnson of the University of Illinois University, Click to access his personal home page). He gave us a new idea to standardize software coding: improve the simplicity and ability to read software code without changing the program function.

First we will give two simple examples to explain Refactoring

EXAMPLE 1:

The original code:

Double PotentialeNergy (Double Mass, Double Height) {

Return mass * height * 9.81;

}

But what is this 9.81, no one told me, well, look at the modified code:

Static final double gravitational_constant = 9.81;

Double PotentialeNergy (Double Mass, Double Height) {

Return mass * gravitational_constant * height;

}

EXAMPLE 2:

IF (Date.before (Summer_Start) || DATE.AFTER (SUMMER_END))

Charge = quantity * _winterrate _winterServiceCharge;

Else Charge = quantity * _summerrate;

There are very difficult here in various expressions, so we use a simple and understand to replace it.

IF (NotSummer (Date))

Charge = Wintercharge (Quantity);

Else Charge = Summercharge (Quantity);

Squiring various complex expressions into individual functions, and expressed its function with a function name, such a program clearly understood.

From the above two examples we see that in fact, refactoring is substantially an optimization of the program code. Make the code more affinity and facilitate maintenance and code reuse. This idea promotes a good programming style, clear programming ideas, not only the readers of the program, but also contribute to the program of the program. Make the program a better structure.

on

Refactoring

Have a good book

Refactoring: Improving The Design of EXISTING CODE

",Yes

Martin Fowler

Written, you can visit

http://www.refactoring.com

To get more information.

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

New Post(0)