Using the Devil Numbers in your code (numbers, strings, etc. that don't have a detailed meaning) will cause your code to be difficult to understand and you should define a number as a constant with a meaningful name.
The last goal of defining a number as a constant is to make the code easier to understand, so it's not just the Devil's number to define a number as a constant. Assuming that the name of a constant is meaningless and does not help to understand the code, the same is a demon number.
In some cases, defining a number as a constant will cause the code to be more difficult to understand, and it should not be forced to define a number as a constant.
Case
Devil number, can't understand. 3 What is the status of the product in detail?
if (Product.getproduct (). Getproductstatus ()! = 3)
{
throw new Pmsexception (PMSErrorCode.Product.ADD_ERROR);
}
is still the devil number, unable to understand what the status of Num_three in detail represents the product
if (Product.getproduct (). Getproductstatus ()! = Num_three)
{
throw new Pmsexception (PMSErrorCode.Product.ADD_ERROR);
}
In the example, the code is not easy to understand, although the number is defined as a constant
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;
Using numbers directly, the code is 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;
Demon numbers in the program