The use of devil numbers (numbers without specific meanings, strings, etc.) in the Code will make the code difficult to understand, and the number should be defined as a meaningful constant of the name.
The ultimate goal of defining a number as a constant is to make the code easier to understand, so it is not a devil number to define a number as a constant. If the constant name is meaningless, it cannot help you understand the code. It is also a devil number.
In some cases, defining a number as a constant makes the code more difficult to understand. In this case, you should not forcibly define the number as a constant.
Case
// The Devil's number cannot be understood. 3. What is the status of the product?
If (product. getproduct (). getproductstatus ()! = 3)
{
Throw new pmsexception (pmserrorcode. Product. add_error );
}
// It is still the devil's number, and it cannot be understood what kind of status num_three represents.
If (product. getproduct (). getproductstatus ()! = Num_three)
{
Throw new pmsexception (pmserrorcode. Product. add_error );
}
// Although the number is defined as a constant in the example, the code is not easy to understand.
Point drawcenter = new point ();
Drawcenter. x = parentwindow. x + (parentwindow. Width-clientwindow. width)/half_size_div;
Drawcenter. Y = parentwindow. Y + (parentwindow. Height-clientwindow. Height)/half_size_div;
Return drawcenter;
// Directly use numbers to make the code easier to understand
Point drawcenter = new point ();
Drawcenter. x = parentwindow. x + (parentwindow. Width-clientwindow. width)/2;
Drawcenter. Y = parentwindow. Y + (parentwindow. Height-clientwindow. Height)/2;
Return drawcenter;
Source Free qcoin resources: http://blog.sina.com.cn/hksqbi